最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Leaflet maps - can I find which layer a marker has been placed inon? - Stack Overflow

programmeradmin1浏览0评论

I add a bunch of layers to my map, using a set of geoJSON objects (actually UK post code areas) - these show up nicely.

After that, I add a set of markers at specified locations.

What I want to do now is iterate through these markers and find out which post code area they belong to - ie in which of the first set of layers they fall in.

I can loop through the markers thus:

 var ll;
 map.eachLayer(function (mrk) {
    if (mrk instanceof L.Marker) {
       // ll = mrk.getLatLng(); 
       // this is a LatLong object, for whatever use that is...
    }
 });

but can't figure out how (if) I can get what I want from here... is there aa way of finding a "parent" layer? Except this isn't a strict parent in the DOM sense, of course... I'm just wondering if there's a way of saying "Ah, marker X is sitting on top of layer Y" (Or, maybe, the other way round: loop through the base layers and find out which markers sit on each.)

Probably not. I suspect I may have to approach this whole problem differently, not using Leaflet at all...

发布评论

评论列表(0)

  1. 暂无评论