gpt4 book ai didi

leaflet - 标记簇切换开/关

转载 作者:行者123 更新时间:2023-12-02 16:44:48 27 4
gpt4 key购买 nike

他们要求我提供一个“切换按钮”来打开和关闭集群有人可以帮助我实现集群的打开/关闭吗?

注意:加载超过30,000点

最佳答案

创建两层,一层有标记聚类,一层没有标记聚类,并将它们添加到传单控件中。例如:

var littleton = L.marker([39.61, -105.02]).bindPopup('This is Littleton, CO.'),
denver = L.marker([39.74, -104.99]).bindPopup('This is Denver, CO.'),
aurora = L.marker([39.73, -104.8]).bindPopup('This is Aurora, CO.'),
golden = L.marker([39.77, -105.23]).bindPopup('This is Golden, CO.');

var cities = L.layerGroup([littleton, denver, aurora, golden]);

var citiesClustered = new L.MarkerClusterGroup();
markers.addLayer(littleton);
markers.addLayer(denver);
markers.addLayer(aurora);
markers.addLayer(golden);

var streets = L.tileLayer(mapboxUrl, {id: 'examples.map-i86knfo3', attribution: mapboxAttribution});
var map = L.map('map', {
center: [39.73, -104.99],
zoom: 10,
layers: [streets, cities]
});

var baseMaps = {
"Streets": streets
};

var overlayMaps = {
"Cities": cities,
"Clustered cities": citiesClustered
};

L.control.layers(baseMaps, overlayMaps).addTo(map);

您还可以创建一个自定义控件来对标记进行分簇,但此控件已经存在并且很容易实现。

关于leaflet - 标记簇切换开/关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25867804/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com