基于完全相同位置的集群的 Mapbox 无缩放
Mapbox no zoom for cluster based at exact same location
如何设置视图,使基于完全相同位置的集群不缩放?我必须点击集群两次以放大,才发现地图上的同一确切位置有多个数据点。见下图。
集群代码:
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插件目前正式版的坑
有一个新代码可以纠正这种违反直觉的行为,但不幸的是,它尚未包含在已发布的版本中。使用新代码,集群 "spiderfies" 立即不缩放,如果即使在最大地图缩放下你仍然会得到相同的集群(这意味着你的标记仍然太近,不一定在完全相同的坐标)。
我会尝试找到一种方法来 "patch" 你的脚本,这样就可以包含这个新代码,而不必等待插件的新版本。
编辑
您应该将以下代码复制粘贴到您的脚本中:
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();
}
}
});
如果这不能解决您的问题,或者这不是您想要的,请告诉我。
如何设置视图,使基于完全相同位置的集群不缩放?我必须点击集群两次以放大,才发现地图上的同一确切位置有多个数据点。见下图。
集群代码:
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插件目前正式版的坑
有一个新代码可以纠正这种违反直觉的行为,但不幸的是,它尚未包含在已发布的版本中。使用新代码,集群 "spiderfies" 立即不缩放,如果即使在最大地图缩放下你仍然会得到相同的集群(这意味着你的标记仍然太近,不一定在完全相同的坐标)。
我会尝试找到一种方法来 "patch" 你的脚本,这样就可以包含这个新代码,而不必等待插件的新版本。
编辑
您应该将以下代码复制粘贴到您的脚本中:
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();
}
}
});
如果这不能解决您的问题,或者这不是您想要的,请告诉我。