使用 geojson 功能的传单 .bindLabel

Gre*_*ske 5 leaflet

我是传单新手,我想向从 geojson 格式派生的点图特征添加标签。

我收到错误: TypeError:layer.bindLabel 不是此脚本中的函数https://jsfiddle.net/gfiske/ksx600sn/35/ (取消注释第 129 行)

任何人都可以建议解决方法或更好的方法吗?

谢谢。

geojsonLayer = L.geoJson(geojson, {


style: function(feature) {
    return {
      color: feature.properties.GPSUserColor
    };
  },
  pointToLayer: function(feature, latlng) {
    return new L.CircleMarker(latlng, {
      radius: 7,
      fillOpacity: 0.75
    });
  },
  onEachFeature: function(feature, layer) {
    layer.bindPopup(feature.properties.MAP_LABEL);
    layer.bindLabel(feature.properties.MAP_LABEL);
    }
});
Run Code Online (Sandbox Code Playgroud)

car*_*ant 6

从文档中Leaflet.label

注意:从 Leaflet 1.0 开始,L.Label 作为 L.Tooltip 添加到 Leaflet 核心,并且该插件已弃用。

你应该使用bindTooltip

onEachFeature: function(feature, layer) {
  layer.bindPopup(feature.properties.MAP_LABEL);
  layer.bindTooltip(feature.properties.MAP_LABEL);
}
Run Code Online (Sandbox Code Playgroud)