Cluster markers on a file / leaflet

I am trying to create a cluster map on mapbox, for example http://leaflet.imtqy.com/Leaflet.markercluster/example/marker-clustering-realworld.388.html

But their example uses a simple .js file as the data http://www.mapbox.com/mapbox.js/assets/realworld.388.js

And the only thing I can get from mapbox is .geojson http://api.tiles.mapbox.com/v3/thebteam.map-w9jzcznw/markers.geojson

Is there a way to convert geojson to js (on a regular basis)? Or export javascript array from mapbox?

EDIT: The switch of my data to CSV and the search for the parser have ended. Here is the code that worked if someone needed 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); }); 
+6
source share
2 answers
 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 } 
+2
source

Create a geoJson layer, and then add this layer to MarkerCluster:

  var markers = new L.MarkerClusterGroup(); var geoJsonFeature = = { "type": "Feature", "properties": { "name": "Coors Field", "amenity": "Baseball Stadium", "popupContent": "This is where the Rockies play!" }, "geometry": { "type": "Point", "coordinates": [-104.99404, 39.75621] } }; var geoJsonLayer = L.geoJson(geoJsonFeature); markers.addLayer(geoJsonLayer); map.addLayer(markers); 
+9
source

Source: https://habr.com/ru/post/946878/


All Articles