You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

OpenLayers中使用Protomaps样式文件为PMTiles矢量切片图层设置样式失败的问题求助

OpenLayers中使用Protomaps样式文件为PMTiles矢量切片图层设置样式失败的问题求助

我现在遇到一个样式配置的棘手问题,想请教各位开发者大佬:

我自己托管了一些.pmtiles文件,在Angular项目里借助ol-pmtilesPMTilesVectorSource创建了矢量切片图层,想要套用从Protomaps官网获取的style.json来给图层设置样式。当前使用的依赖版本是:ol@9.2.4ol-mapbox-style@11.0.3ol-pmtiles@2.0.2

我尝试用ol-mapbox-style提供的applyStyle方法来关联样式和图层,还特意修改了style.json里的url字段,把开头的pmtiles://去掉了(留着的话会触发错误)。现在请求样式文件能拿到200 OK的响应,但控制台一直提示无法获取源,图层也完全没有渲染出预期的样式效果。

下面是我的实现代码:

export class PMTilesManager {
  constructor(
    private http: HttpClient,
    private url: string = EnvironmentManager.get('pmtilesUrl'),
  ) {}

  public async getPMTilesLayer(): Promise<VectorTileLayer<any>> {
    const style = await firstValueFrom(this.http.get<any>('assets/pmtiles-style.json'));
    const source: PMTilesVectorSource = new PMTilesVectorSource({
      url: this.url,
      format: new MVT(),
    });

    const layer: VectorTileLayer<RenderFeature> = new VectorTileLayer<RenderFeature>({
      declutter: true,
      source: source,
    });

    applyStyle(layer, style, 'protomaps');
    return layer;
  }
}

有没有大佬能帮我排查下问题出在哪?或者有没有其他靠谱的方式,能给PMTiles图层正确应用Protomaps的样式文件?

内容来源于stack exchange

火山引擎 最新活动