我正在使用Leaflet-Markercluster插件对我的点数据进行聚类。我已经将名为“ street”的geojson数据加载到地图中。该数据具有各自属性的大约40个点。我想在传单地图中将这些点聚类。但是即使标记也没有显示在我的地图上。请帮助我找出错误。我的代码在这里:
var OpenStreetMap_Mapnik = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
var street = {...my_geojson_data...}
var s_light_style = {
radius: 8,
fillColor: "#ff7800",
color: "#000",
weight: 1,
opacity: 1,
fillOpacity: 0.8
};
var markers = L.markerClusterGroup();
L.geoJSON(street, {
onEachFeature : function(feature, layer){
var popupContent = '<h4 class = "text-primary">Street Light</h4>' +
'<div class="container"><table class="table table-striped">' +
'<thead><tr><th>Properties</th><th>Value</th></tr></thead>' +
'<tbody><tr><td> Name </td><td>'+ feature.properties.Name +'</td></tr>' +
'<tr><td>Elevation </td><td>' + feature.properties.ele +'</td></tr>' +
'<tr><td> Power (watt) </td><td>' + feature.properties.Power_Watt + '</td></tr>' +
'<tr><td> Pole Height </td><td>' + feature.properties.pole_hgt + '</td></tr>' +
'<tr><td> Time </td><td>' + feature.properties.time + '</td></tr>';
layer.bindPopup(popupContent)
},
pointToLayer: function (feature, latlng) {
return markers.addLayer(L.marker(latlng))
}
}).map.addTo(markers);
答案 0 :(得分:0)
通过
替换代码L.geoJSON(street, {
onEachFeature : function(feature, layer){
var popupContent = '<h4 class = "text-primary">Street Light</h4>' +
'<div class="container"><table class="table table-striped">' +
'<thead><tr><th>Properties</th><th>Value</th></tr></thead>' +
'<tbody><tr><td> Name </td><td>'+ feature.properties.Name +'</td></tr>' +
'<tr><td>Elevation </td><td>' + feature.properties.ele +'</td></tr>' +
'<tr><td> Power (watt) </td><td>' + feature.properties.Power_Watt + '</td></tr>' +
'<tr><td> Pole Height </td><td>' + feature.properties.pole_hgt + '</td></tr>' +
'<tr><td> Time </td><td>' + feature.properties.time + '</td></tr>';
layer.bindPopup(popupContent)
},
pointToLayer: function (feature, latlng) {
return markers.addLayer(L.circleMarker(latlng, s_light_style))
}
})
map.addLayer(markers);
在上面的代码中,我指定了map.addTo(markers)。但是实际上我必须将“ addTo”关键字替换为“ addLayer”。我必须添加图层。这样,我解决了geojson markerCluster问题。