gpt4 book ai didi

javascript - Mapbox 无法缩放基于完全相同位置的集群

转载 作者:行者123 更新时间:2023-12-02 15:30:00 25 4
gpt4 key购买 nike

如何设置 View ,以便基于相同位置的集群不会缩放?我必须单击集群两次才能放大,才发现 map 上同一确切位置有多个数据点。请参阅下面的图片。

enter image description here

enter image description here

集群代码:

var markerClusterLayer = new L.MarkerClusterGroup({
maxClusterRadius: 25,
disableClustringAtZoom: 18,
spiderfyDistanceMultiplier: 3,
zoomToBoundsOnClick: true,
showCoverageOnHover: false,
iconCreateFunction: function (cluster) {
var childCount = cluster.getChildCount();

var c = ' custom-marker-cluster-';
if (childCount < 10) {
c += 'small';
} else if (childCount < 30) {
c += 'medium';
} else {
c += 'large';
}

return new L.DivIcon({
html: '<div><span>' + childCount + '</span></div>',
className: 'marker-cluster' + c,
iconSize: new L.Point(40, 40) });
}
});

最佳答案

这是当前正式版MarkerCluster插件的一个缺陷。

有一个新代码可以纠正这种违反直觉的行为,但不幸的是它尚未包含在发布的版本中。使用新代码,即使在最大 map 缩放下,您仍然会得到相同的集群(这意味着您的标记仍然太近,不一定处于完全相同的坐标),集群会立即“蜘蛛化”而无需缩放。

我将尝试找到一种方法来“修补”您的脚本,以便可以包含此新代码,而无需等待插件的新版本。

<小时/>

编辑

您应该可以将以下代码复制粘贴到脚本中:

L.MarkerClusterGroup.include({
_zoomOrSpiderfy: function (e) {
var map = this._map;
// The following first condition is the part that is missing in the
// current plugin release, and which triggers a spiderfy if all
// contained markers are still clustered at maximum zoom.
if (e.layer._bounds._northEast.equals(e.layer._bounds._southWest)) {
if (this.options.spiderfyOnMaxZoom) {
e.layer.spiderfy();
}
} else if (map.getMaxZoom() === map.getZoom()) {
if (this.options.spiderfyOnMaxZoom) {
e.layer.spiderfy();
}
} else if (this.options.zoomToBoundsOnClick) {
e.layer.zoomToBounds();
}

// Focus the map again for keyboard users.
if (e.originalEvent && e.originalEvent.keyCode === 13) {
map._container.focus();
}
}
});

如果这不能解决您的问题,或者这不是您想要的,请告诉我。

关于javascript - Mapbox 无法缩放基于完全相同位置的集群,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33396289/

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