如何删除使用 apply 方法加载的 ol-mapbox 样式图层
how to remove a ol-mapbox-style layer loaded with apply method
由于大多数时候我使用 addLayer() 和 removeLayer() OL 方法来添加和删除图层,我如何处理类似地使用 ol-mapbox-style 处理的矢量图层?以下 angular 代码不起作用,我在 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))
}
谢谢
您可以识别由 ol-mapbox-style 创建的图层,因为它们具有 mapbox-source 和 mapbox-layers 属性。如果您在其中任何一个上过滤图层数组,您可以删除这些图层
this.map.getlayers().getArray().filter(
layer => return layer.get('mapbox-source');
).forEach(
layer => this.map.removeLayer(layer);
);
由于大多数时候我使用 addLayer() 和 removeLayer() OL 方法来添加和删除图层,我如何处理类似地使用 ol-mapbox-style 处理的矢量图层?以下 angular 代码不起作用,我在 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))
}
谢谢
您可以识别由 ol-mapbox-style 创建的图层,因为它们具有 mapbox-source 和 mapbox-layers 属性。如果您在其中任何一个上过滤图层数组,您可以删除这些图层
this.map.getlayers().getArray().filter(
layer => return layer.get('mapbox-source');
).forEach(
layer => this.map.removeLayer(layer);
);