Leaflet MarkerCluster:是否可以打开多个群集组? [英] Leaflet MarkerCluster: Is it possible to open multiple cluster-groups?
问题描述
我最近开始使用传单.我找到了很棒的插件宣传页markercluster.我目前正在尝试同时打开多个群集组.不幸的是,我在Google上找不到任何东西.
I have recently started working with leaflet. I found the great plugin leaflet markercluster. I am currently trying to open several clustergroups at the same time. Unfortunately I can't find anything on google.
我有几个群集组,并绘制从一个标记到另一个标记的连接.用户应该能够打开绘制线所在的两个群集组:
I have several cluster groups and draw connections from one marker to another. The user should be able to open both cluster groups to which the drawn line goes:
因此,我的问题是:是否有我必须打开的功能或者根本没有同时打开多个组?
Therefore my question: Is there a function for this that I have to switch on or is opening several groups at the same time not provided at all?
推荐答案
好的,我现在已经对其进行了一些实验;)
Okay I have experimented a little bit on it now ;)
在leaflet.markercluster-src.js中,我创建了一个名为 _spiderMan []
的数组,其中填充了函数Spiderfy中单击的对象.
In the leaflet.markercluster-src.js I created an array called _spiderMan[]
which is filled with the clicked objects in the function spiderfy.
spiderfy: function() {
if (this._group._spiderfied === this || this._group._inZoomAnimation) {
return;
}
var childMarkers = this.getAllChildMarkers(null, true),
group = this._group,
map = group._map,
center = map.latLngToLayerPoint(this._latlng),
positions;
// this._group._unspiderfy(); //deactivated
var markers = markers + childMarkers;
_spiderMan.push(this); //new
if (childMarkers.length >= this._circleSpiralSwitchover) {
positions = this._generatePointsSpiral(childMarkers.length, center);
} else {
center.y += 10;
positions = this._generatePointsCircle(childMarkers.length, center);
}
this._animationSpiderfy(childMarkers, positions);
},
然后,我创建了一个for循环,该循环遍历整个数组并每次调用 _spiderMan [i] .unspiderfy(zoomDetails)
.我将此循环内置到函数 _unspiderfyZoomAnim
中进行测试.意味着每次放大或缩小时,所有打开的组都会被汇总.
Then I have created a for loop which runs through the array and calls _spiderMan[i].unspiderfy(zoomDetails)
every time. I built this loop into the function _unspiderfyZoomAnim
for testing. Means every time you zoom in or out, all open groups are summarized.
_unspiderfyZoomAnim: function(zoomDetails) {
if (L.DomUtil.hasClass(this._map._mapPane, 'leaflet-touching')) {
return;
}
this._map.off('zoomanim', this._unspiderfyZoomAnim, this);
var i;
for (i = 0; i < _spiderMan.length; i++) {
_spiderMan[i].unspiderfy(zoomDetails);
}
_spiderMan = [];
},
此外,必须在 unspiderfy
函数中停用以下几行:
In addition, the following lines must be deactivated in the unspiderfy
function:
unspiderfy: function(zoomDetails) {
/// <param Name="zoomDetails">Argument from zoomanim if being called in a zoom animation or null otherwise</param>
// if (this._group._inZoomAnimation) {
// return;
// }
this._animationUnspiderfy(zoomDetails);
// this._group._spiderfied = null;
},
因此,现在可以打开和关闭多个群集组,但这只是一种解决方法,我认为由于注释掉或删除了代码行,这将在某些地方产生不良影响.
So it's now possible to open and close mutiple cluster-groups but this is only a workaround and I think it will have some bad effects somewhere because of commenting out or removing code lines.
我认为在JS方面有更多经验的人,并且此插件应该找到一个更好,更舒适的解决方案;).
I think someone with more experience in JS and this plugin should find a better and more comfortable solution ;).
这篇关于Leaflet MarkerCluster:是否可以打开多个群集组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!