【发布时间】:2015-01-06 04:59:54
【问题描述】:
我在 GeoJson 文件中标记了 6 个多边形。我在每个多边形质心上使用 circleMarker,然后调用 .bindLabel,但出现此错误:“circleMarker.bindLabel 不是函数”。 Leaflet.label.js 被调用。
GeoJSON 代码:
var districts = L.geoJson(null, {
style: function (feature) {
return {
weight: 1,
opacity: 1,
color: 'blueviolet',
fillColor: 'plum',
fillOpacity: 0.5
};
},
onEachFeature: function (feature, layer) {
layer.on('mouseover', function () {
this.setStyle({
'fillColor': '#0000ff'
});
});
layer.on('mouseout', function () {
this.setStyle({
'fillColor': 'plum'
});
});
layer.on('click', function () {
window.location = feature.properties.URL;
});
var circleMarker = L.circleMarker(layer.getBounds().getCenter());
// e.g. using Leaflet.label plugin
circleMarker.bindLabel(feature.properties['NAME'], { noHide: true })
.circleMarker.addTo(map);
}
});
$.getJSON("data/districts.geojson", function (data) {
districts.addData(data);
});
【问题讨论】:
标签: javascript leaflet geojson