【发布时间】:2020-05-14 06:24:29
【问题描述】:
我认为这个问题说明了一切。 我正在使用传单。我正在将三层加载到地图上。
但是,在单击地图后,我找不到知道单击了哪个图层的方法。 基本上是因为没有在图层上设置事件处理程序,只在地图上设置。
我还尝试将图层添加到功能组中,并向该功能组添加点击事件。然而,点击地图不会导致任何事件/响应。
这是我在 featureGroup 中所做的:
addWaterNameLayers: function() {
var knownWaters = L.tileLayer.wms(getGeoServer('wms', geoEnviroment), {
layers: this.wmsLayers.known.name,
format: 'image/png',
opacity: 0,
styles: 'cursor: pointer',
transparent: true,
attribution: ""
});//.addTo(this.mapInfo);
var unknownWaters = L.tileLayer.wms(getGeoServer('wms', geoEnviroment), {
layers: this.wmsLayers.unknown.name,
format: 'image/png',
opacity: 0.3,
styles: '',
transparent: true,
attribution: ""
});
L.FeatureGroup(knownWaters, unknownWaters).on('click', function(event) {
console.log('click');
this.handleClick(event);
},this);
//this part will work on mapclick, so on featuregroup it should work?
//when clicking on the map
/*
this.mapInfo.on('click', function(event) {
this.handleClick(event);
}, this);
*/
},
在上面的代码中,您还可以在地图上看到 click 事件……这很有效。 在功能组上它没有。
此外,当我将 featureGroup 的代码更改为这些代码时,它也不起作用:
var featGr = L.FeatureGroup(knownWaters, unknownWaters).on('click', function(event) {
this.handleClick(event);
},this);
var featGr = L.FeatureGroup(knownWaters, unknownWaters);
featGr.on('click', function(event) {
this.handleClick(event);
},this);
将featureGroup添加到图层也不会做任何事情......
【问题讨论】:
-
您找到解决方案了吗?我也有同样的问题...
-
需要迭代 WMS 层,但已经有一段时间了,所以不记得了。
标签: javascript leaflet