Clustering markers on mapbox / leaflet

后端 未结 2 1777
眼角桃花
眼角桃花 2021-02-09 08:00

I\'m trying to set up a clustered map on mapbox, like http://leaflet.github.io/Leaflet.markercluster/example/marker-clustering-realworld.388.html

But their example uses

相关标签:
2条回答
  • 2021-02-09 08:56
    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
    
      }
    
    0 讨论(0)
  • 2021-02-09 08:56

    Create a geoJson layer and then add that 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);
    
    0 讨论(0)
提交回复
热议问题