0

由于大多数时候我使用 addLayer() 和 removeLayer() OL 方法添加和删除图层,我如何处理类似使用 ol-mapbox-style 处理的矢量图层?以下角度代码不起作用,我在https://github.com/openlayers/ol-mapbox-style中看不到合适的方式。

changeToVectorTileMapTilerEmbebedJson() {
  apply(
    this.map,
    'https://api.maptiler.com/maps/b3265770-0173-4415-909d-264ef9934779/style.json?key=blablabla'
  )
  .then(() => this.map.removeLayer(this.stamenTerrain))
  .then(() => this.map.removeLayer(this.stamenWaterColor))
  .then(() => this.map.removeLayer(this.osm))
  .then(() => this.map.removeLayer(this.topMap))
  .then(() => this.map.removeLayer(this.vectorTileMapTilerHillShades))
  .then(() => this.map.removeLayer(this.vectorTileMapTilerSatMediumbres))
  .then(() => this.map.removeLayer(this.vectorTileArcGISpbf))

}

谢谢

4

1 回答 1

0

您可以识别由 ol-mapbox-style 创建的图层,因为它们具有 mapbox-source 和 mapbox-layers 属性。如果您在其中任何一个上过滤图层数组,您可以删除这些图层

this.map.getlayers().getArray().filter(
  layer => return layer.get('mapbox-source');
).forEach(
  layer => this.map.removeLayer(layer);
);
于 2020-08-26T14:53:57.617 回答