小编elt*_*aco的帖子

带有 GeoJson 的传单 MarkerCluster

我目前正在使用外部 geojson 文件作为数据输入的传单项目。由于 json 包含很多对象,我想使用MarkerCluster从 Mappbox 获得的插件:

<script src='https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v0.4.0/leaflet.markercluster.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v0.4.0/MarkerCluster.css' rel='stylesheet' />
<link href='https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-markercluster/v0.4.0/MarkerCluster.Default.css' rel='stylesheet' />
Run Code Online (Sandbox Code Playgroud)

在没有集群的情况下显示 json-layer 工作得很好,但是如果我尝试将它分配给集群,则不会显示任何内容。

var markersBar = L.markerClusterGroup();        
var barLayer = new L.GeoJSON.AJAX("json/eat_drink/bar.geojson", {
    pointToLayer: function(feature, latlng) {
        var icon = L.icon({
                        iconSize: [27, 27],
                        iconAnchor: [13, 27],
                        popupAnchor:  [1, -24],
                        iconUrl: 'icon/' + feature.properties.amenity + '.png'
                        });
        return L.marker(latlng, {icon: icon})
    }, 
    onEachFeature: function(feature, layer) {
        layer.bindPopup(feature.properties.name + ': ' + feature.properties.opening_hours);
    }
});
markersBar.addLayer(barLayer);
console.log(markersBar);
map.addLayer(markersBar);
Run Code Online (Sandbox Code Playgroud)

console.log 输出让我假设没有对象,但我不明白为什么。

Object { …
Run Code Online (Sandbox Code Playgroud)

json markerclusterer leaflet

3
推荐指数
1
解决办法
3992
查看次数

标签 统计

json ×1

leaflet ×1

markerclusterer ×1