我不能使聚类工作

时间:2017-12-30 18:26:09

标签: dictionary leaflet cluster-analysis markerclusterer leaflet.markercluster

所以这是我的第一张地图,也是我第一次尝试编码,它是一个带有等值线的集群图 我搜索了如何使它工作,我不能。 这是代码行

    <script type="text/javascript" src="sectores.js"></script> 
<script type="text/javascript" src="geo.js"></script> 

<body>
<script>
 $.getJSON("geo.js",function(data){
    });
    var geo = L.geoJson(data,{
      pointToLayer: function(feature,latlng){
        var marker = L.marker(latlng,{icon: ratIcon});
        marker.bindPopup(feature.properties.geometry.coordinates + '<br/>' + feature.properties.OPEN_DT);
        return marker;
      }
    });
    var clusters = L.markerClusterGroup();
    clusters.addLayer(geo);
    map.addLayer(clusters);
  });
</script>
</body>

这是geo.js中的300分之一

    var geo =
  {"type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {
        "Fecha": "05/01/2017",
        "Dia": null,
        "Hora": null,
        "Caratula": "Robo",
        "Pais": "Argentina",
        "Calle": "CANADA Y ARCACHON",
        "Localidad": "Pinamar",
        "Provincia": "Buenos Aires",
        "Codigo Pos": 7167,
        "addrtype": "intersection",
        "addrlocat": "GEOMETRIC_CENTER"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          -56.8951216,
          -37.1321522
        ]
      }
    },

最后这是文件的开头

<!DOCTYPE html>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" />
    <link rel="stylesheet" type="text/css" href="http://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.css" />
    <link rel="stylesheet" type="text/css" href="http://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.Default.css" />

    <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js'></script>
    <script type='text/javascript' src='http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js'></script>
    <script type='text/javascript' src='http://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/leaflet.markercluster.js'></script>

请帮助我; - ;

1 个答案:

答案 0 :(得分:0)

我想出了我的自己,起初对我的正式解释并不清楚,正确的代码使其成功

var clusterGroup = L.markerClusterGroup();
var geojsonLayer = L.geoJson(geo); //where it goes your .js file
clusterGroup.addLayer(geojsonLayer); 
map.addLayer(clusterGroup);
}

这就是它,它是我需要改变的唯一一条线,我希望这对像我这样的新手有帮助哈哈