![](/img/trans.png)
[英]Openlayers: Once a layer is removed, new layers won't be added to the map
[英]Openlayers: Is there a map event that fires when a new layer has been added?
我正在寻找一个事件,该事件在将新层添加到 openlayers map 时触发。
像map.on('layeradded')...
我发现了所有这些事件: https://gis.stackexchange.com/questions/252946/what-are-the-possible-listeners-and-event-types-for-an-openlayers-map-ol-map并搜索在文档中,但找不到合适的东西。
您可以使用 class 来扩展EventTarget
,因此无论何时添加层,您也可以调度自己的事件。
const myClass extends EventTarget { addLayer(layer) { this.map.addLayer(layer); this.dispatchEvent(new CustomEvent(`layer-added`, detail: {layer})); } }
您可以在分派的事件中添加您选择的数据,因此 eventListener,例如,知道添加了哪个层 - 或者无论用例是什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.