【发布时间】:2020-04-25 22:55:15
【问题描述】:
我正在尝试在 mapbox 上设置集群地图,例如 http://leaflet.github.io/Leaflet.markercluster/example/marker-clustering-realworld.388.html
目前,我的点数据正在从 MYSQL 中提取并使用 GeoPHP 转换为 GeoJson。 The map.
我想知道是否有办法将 MarkerCluster 插件与我的 GeoJson 文件一起使用,在下面的代码中称为 mysql_points_geojson.php:
// Bike Racks
var bikeRacksIcon = L.icon({
iconUrl: 'bicycleparking.png',
iconSize: [24, 28],
iconAnchor: [12, 28],
popupAnchor: [0, -25]
});
bikeRacks = new L.geoJson(null, {
pointToLayer: function (feature, latlng) {
return L.marker(latlng, {
icon: bikeRacksIcon,
title: feature.properties.city
});
},
onEachFeature: function (feature, layer) {
if (feature.properties) {
var content = '<table border="0" style="border-collapse:collapse;" cellpadding="2">' +
'<tr>' + '<th>City</th>' + '<td>' + feature.properties.city + '</td>' + '</tr>' +
'<tr>' + '<th>Country</th>' + '<td>' + feature.properties.country + '</td>' + '</tr>' +
'<table>';
layer.bindPopup(content);
}
}
});
$.getJSON("mysql_points_geojson.php", function (data) {
bikeRacks.addData(data);
}).complete(function () {
map.fitBounds(bikeRacks.getBounds());
});
【问题讨论】:
标签: javascript json leaflet mapbox geojson