【发布时间】:2016-08-23 12:14:12
【问题描述】:
我想用 mapbox.js 实现带有 MarkerCluster 的 GEOJson。
没有 Markercluster,一切正常:
$.ajax({
url: 'dashboard/geoJSON',
dataType: 'json',
type: 'POST',
success: function(geojson) {
locations = L.mapbox.featureLayer().addTo(map)
locations.on('layeradd', function (e) {
var marker = e.layer;
markers.push(marker);
});
locations.setGeoJSON(geojson);
...
但是当我尝试实现 MarkerCluster 时,它只显示 1 个标记
...
success: function(geojson) {
locations = L.mapbox.featureLayer().addTo(map)
var clusterGroup = new L.MarkerClusterGroup();
locations.on('layeradd', function (e) {
var marker = e.layer;
markers.push(marker);
clusterGroup.addLayer(markers);
});
locations.setGeoJSON(geojson);
map.addLayer(clusterGroup);
并显示以下错误:
TypeError: t.onAdd is not a function
谁能帮帮我,我怎样才能从远程服务器成功地将markercluster与GEOJson结合起来? 提前致谢
// 编辑:找到一个已经可以使用的不同示例:
var markers = L.markerClusterGroup();
var geoJsonLayer = L.geoJson(geojson, {
onEachFeature: function (feature, layer) {
}
});
markers.addLayer(geoJsonLayer);
map.addLayer(markers);
map.fitBounds(markers.getBounds());
但现在它使用“marker-color”-“marker-size”等属性失去了我的“默认”样式。
我现在如何设计我的标记?
Mapbox 有点奇怪,看起来总有至少 10 种方法可以解决这些问题;)
【问题讨论】:
标签: javascript leaflet mapbox