如何解决如何删除使用apply方法加载的ol-mapbox样式图层
由于大多数时候我都是通过使用addLayer()和removeLayer()OL方法添加和删除图层的,所以我该如何类似地处理以ol-mapbox样式处理的矢量图层?以下角度代码不起作用,我在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样式创建的图层,因为它们具有mapbox-source和mapbox-layers属性。如果您在任一图层上过滤了图层数组,则可以删除这些图层
this.map.getlayers().getArray().filter(
layer => return layer.get('mapbox-source');
).forEach(
layer => this.map.removeLayer(layer);
);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。