在mapbox / leaflet上聚类标记 [英] Clustering markers on mapbox / leaflet
问题描述
我正在尝试在mapbox上设置聚簇地图,例如 http://leaflet.github.io/Leaflet.markercluster/example/marker-clustering-realworld.388.html
I'm trying to set up a clustered map on mapbox, like http://leaflet.github.io/Leaflet.markercluster/example/marker-clustering-realworld.388.html
但他们的示例使用普通的.js文件作为数据
http:// www.mapbox.com/mapbox.js/assets/realworld.388.js
But their example uses a plain .js file as data http://www.mapbox.com/mapbox.js/assets/realworld.388.js
我唯一能从mapbox获得的是.geojson
http://api.tiles.mapbox.com/v3 /thebteam.map-w9jzcznw/markers.geojson
And the only thing I can get from mapbox is .geojson http://api.tiles.mapbox.com/v3/thebteam.map-w9jzcznw/markers.geojson
我有没有办法将geojson转换为js(定期)?或者从mapbox导出javascript数组?
Is there a way I can convert the geojson to js (on a regular basis)? Or export a javascript array from mapbox?
编辑:最后将我的数据切换为CSV并找到解析器。如果有人需要,这是有效的代码:
ended up switching my data to CSV and finding a parser. Here's the code that worked, if anyone needs it:
var url = 'https://docs.google.com/spreadsheet/pub?key=abc123';
$.get(url, function(data) {
var addressPoints = $.csv.toArrays(data);
var map = L.mapbox.map('map', 'map-abc123').setView([20.30, 18.98], 2);
var markers = new L.MarkerClusterGroup({ showCoverageOnHover: false });
for (var i = 0; i < addressPoints.length; i++) {
var a = addressPoints[i];
var title = a[2];
var marker = L.marker(new L.LatLng(a[0], a[1]), {
icon: L.mapbox.marker.icon({'marker-size': 'small', 'marker-color': 'e8168c'}),
title: title
});
marker.bindPopup(title);
markers.addLayer(marker);
}
map.addLayer(markers);
});
推荐答案
var geojson = dataFromMapbox;
var lat;
var lng;
for(var i= 0;i<geojson.features.length;i++)
{
lat = geojson.features[i].geometry.coordinates[0];
lng = geojson.features[i].geometry.coordinates[1];
//create a marker with those values, pass it to a MarkerCluster object
}
这篇关于在mapbox / leaflet上聚类标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!