1

我想在地图上显示传单 MarkerCluster,问题在于从 GeoJSON 检索数据:

{
    "type": "FeatureCollection",
    "features": 
    [
        {
            "type": "Feature",
            "id": "sto",
            "properties": {
                "name": "Stoke"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                   -0.0731,
                   51.5615
                ]
            }
        },
        {
            "type": "Feature",
            "id": "dal",
            "properties": {
                "name": "Dalston"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -0.070,
                    51.545
                ]
            }
        },
        {
            "type": "Feature",
            "id": "wan",
            "properties": {
                "name": "Wandsworth"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -0.1924,
                    51.4644
                ]
            }
        },
        {
            "type": "Feature",
            "id": "batt",
            "properties": {
                "name": "Battersea"
            },
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -0.1677,
                    51.4638
                ]
            }
        }
    ]
}

我试图在两个示例中重现相同的情况:

  1. 工作 MarkerCluster,但没有 geojson 数据
  2. 其次是 geojson,但 MarkerCluster 不起作用

有人知道为什么第二个示例中的 MarkerCluster 没有显示吗?我错过了geojson中的一些属性吗?

4

1 回答 1

0

你可以尝试这样的事情(讨论和代码片段在这里

// Get the countries geojson data from a JSON
$http.get("test.geojson").success(function(data, status) {
    addGeoJsonLayerWithClustering(data);

    function addGeoJsonLayerWithClustering(data) {
        var markers = L.markerClusterGroup();
        var geoJsonLayer = L.geoJson(data, {
            onEachFeature: function (feature, layer) {
                layer.bindPopup(feature.properties.Nome.value);
            }
        });
        markers.addLayer(geoJsonLayer);
        leafletData.getMap().then(function(map) {
            map.addLayer(markers);
            map.fitBounds(markers.getBounds());
        });
    }

});
于 2015-09-04T09:42:55.823 回答