繁体   English   中英

在Leaflet中悬停地图时获取图层信息

[英]Get Layer info when hover the map in Leaflet

我在Leaflet的基础地图中添加了Geojson图层。 我使用以下事件来获取地图数据和图层数据:

map.on('mousemove', function (e) {
    console.log(e);
});

它给了我以下日志:

在此处输入图片说明

当我将其悬停时,我找不到与Geojson图层有关的任何内容(该图层的目标中没有任何内容)。

有人对此有任何解决方案吗?

这是获取Geojson图层信息的代码:

$.ajax({
    dataType: "json",....

       onEachFeature: function (feature, layer) {
           layer.on('mousemove', function (event) {
                console.log(event);
           });
       }
});

您可以使用map变量获取有关图层等的信息。

实际上,当您创建图层时,似乎也将其存储在变量中,以便您可以访问它。

var map = L.map(...);
var geoLayer = L.geoJSON().addTo(map);
geoLayer.addData(geojsonFeature);

map.on('mousemove', function(event) {
  console.log(event, geoLayer, map);
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM