我不能使聚类工作

问题描述 投票:-2回答:1

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

    <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>

请帮我 ;-;

dictionary leaflet cluster-analysis markerclusterer leaflet.markercluster
1个回答
0
投票

我自己想通了,起初我不清楚官方的解释,正确的代码让它发挥作用

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

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

© www.soinside.com 2019 - 2024. All rights reserved.