在Leaflet的矢量层上的弹出窗口中获取目标的FetaureId

时间:2019-03-30 00:40:03

标签: leaflet

以下代码可以正常工作,我在getFeatureId中得到了很多有趣的数据。 我如何在弹出窗口中解决这个问题?

var map = L.map('map').setView([53.505, -7.09], 7);

L.tileLayer('https://{s}.etc.etc/{z}/{x}/{y}.png', {
  attribution: 'osm..'
}).addTo(map);

var VectorTileOptions = {
  rendererFactory: L.canvas.tile,
  attribution: '',
  interactive: true,
  getFeatureId:function(feat){
    return feat.properties.routes
  }
};

var TilesPbfLayer = L.vectorGrid.protobuf(tileurl, VectorTileOptions).addTo(map);

var popup = L.popup();
map.on('popupopen', function(e) {
  popup.setContent("how do i get the feature Id ? ")
});
TilesPbfLayer.bindPopup(popup)

1 个答案:

答案 0 :(得分:0)

我可以在磁贴层上获得click事件,并且该层在其中包含我的东西

TilesPbfLayer.on('click', function(e) {
    if (e.layer)
        popup.setContent(e.layer.properties.routes)
})