简体   繁体   English

OMS--传单标记在spiderfy之后有不同的堆叠顺序

[英]OMS--Leaflet markers have different stack order after spiderfy

our setup我们的设置

We have an L.map with various layers of L.markers loading from a dynamic array of events spanning a monthly period.我们有一个L.map ,其中包含从跨越一个月的动态事件数组加载的各种L.markers层。 Many of the listed venues hold numerous events during any given period and hence we end up with numerous markers sharing locations that are very nicely spiderfied using the OMS-Leaflet plugin (0.2.6) we run from CDN许多列出的场所在任何特定时期都会举办许多活动,因此我们最终得到了许多标记共享位置,这些位置使用我们从 CDN 运行的OMS-Leaflet 插件 (0.2.6)非常好地蜘蛛化

Each marker is put into one of several marker Layers depending on day of week or whether the event has been confirmed / expires eg here is one that falls on a weekend:根据星期几或事件是否已确认/过期,每个标记被放入多个标记层之一,例如,这是一个周末:

markerWeekEnd = L.marker([lat, lon], { %options% });
markerWeekEnd.addTo(map);
weekend.addLayer(markerWeekEnd);
oms.addMarker(markerWeekEnd);

It took me a while to figure out how to stack the markers correctly so that they shows up in a certain order ( 1. upcoming markers, 2 . other future date markers and 3 . any expired markers if applicable) using zIndexOffset as the bringToFront() method does not support L.markers.我花了一段时间才弄清楚如何正确堆叠标记,以便它们按特定顺序显示( 1.即将到来的标记, 2 .其他未来日期标记和3.任何过期标记,如果适用)使用zIndexOffset作为bringToFront( )方法不支持 L.markers。

the issue问题

We have everything loading and stacking as required and it all works fine until we unspiderfy / spiderfy .我们已根据需要加载和堆叠所有内容,并且在我们unspiderfy / spiderfy之前一切正常 When the markers get re-spiderfied the one that ends up on top is not the one initially displayed .当标记被重新蜘蛛化时,最终出现在顶部的标记不是最初显示的标记。

I took a look at all the OMS issues, not just OMS-Leaflet (ie also the OMS version for Google Maps API v3 ), and found a couple of closed ones that seemed to suggest a similar issue:我查看了所有 OMS 问题,而不仅仅是OMS-Leaflet (即Google Maps API v3 的 OMS 版本),并发现了几个似乎暗示类似问题的已关闭问题:

OMS should remember original zIndex of marker #76 z-Indices reset #117 (previous fix closes this) OMS 应该记住标记的原始 zIndex #76 z-Indices 重置 #117(之前的修复关闭了这个)

Now as far as I can tell the related fix for these appears to have been applied to OverlappingMarkerSpiderfier/1.0.2/oms.js (also 1.0.3 now I imagine) but perhaps not the OverlappingMarkerSpiderfier-Leaflet/0.2.6/oms.js version.据我所知,这些的相关修复似乎已应用于OverlappingMarkerSpiderfier/1.0.2/oms.js (我想现在也是 1.0.3),但也许不是OverlappingMarkerSpiderfier-Leaflet/0.2.6/oms。 js版本。

In any case our subsequent efforts to get around the issues described above did seem to address the zIndex somewhat but not overcome our stacking issue relating to OMS spiderfy.无论如何,我们随后为解决上述问题所做的努力似乎确实在一定程度上解决了 zIndex,但并未克服与 OMS spiderfy 相关的堆叠问题。

what we tried我们尝试了什么

Decided to tweak my marker options to retain the original zIndexOffset settings L.marker([lat, lon], {... zIndexOffset: mIndex, mDay: mDay}) and to see if resetting the zIndex using the retained values could fix my stacking issue决定调整我的标记选项以保留原始 zIndexOffset设置L.marker([lat, lon], {... zIndexOffset: mIndex, mDay: mDay})并查看使用保留值重置 zIndex 是否可以修复我的堆叠问题

// for both spiderfy & unspiderfy
oms.addListener('spiderfy', function(markers) { 
   markers.forEach(function(marker) { zIndexCheck(marker); });
}
function zIndexCheck(marker){
   L.setOptions( marker, { zIndex: mIndex, zIndexOffset: mIndex });
}

Sadly even though it seem to retain the zIndex values for markers before and after the unspiderfy / spiderfy , the eventual marker that remains on top is not the one that was there before , nor the one with the highest supplied zIndex count (addListener for spiderfy).遗憾的是,尽管它似乎保留了unspiderfy / spiderfy之前和之后标记的 zIndex 值,但最终保留在顶部的标记不是之前的标记,也不提供 zIndex 计数最高的标记(spiderfy 的 addListener) .

I have re-created a stripped down version of our sites functionality on the following jsfiddle and console logged the zIndexes of the initial markers before and after the spiderfy:我在以下jsfiddle控制台上重新创建了我们网站功能的精简版本,并记录了 spiderfy前后初始标记的 zIndexes:

Marker Title: 'London Socials #1 (1/2)' startTime:ENDED: 1st Feb zIndex:-10
Marker Title: 'London Socials #2 (14/2)' startTime:Fri 14th Feb zIndex:5054 (Active)
Marker Title: 'London Socials #3 (28/2)' startTime:Fri 28th Feb zIndex:2026

#2 is the active item initially #2最初是活动项目

Spiderfy蜘蛛侠

[London Socials #1 (1/2)]  index:990
[London Socials #2 (14/2)]  index:5027
[London Socials #3 (28/2)]  index:5013

UnSpiderfy UnSpiderfy

[London Socials #1 (1/2)]  index:990
[London Socials #2 (14/2)]  index:5027
[London Socials #3 (28/2)]  index:5013 (Active)

#3 is now the active item after spiderfy/unspiderfy (see final elements below) #3现在是 spiderfy/unspiderfy 之后的活动项目(请参阅下面的最终元素)

Final marker element最终标记元素

<div class="awesome-marker-icon-blue awesome-marker leaflet-zoom-animated leaflet-interactive" 
title="London Socials #2 (14/2)" tabindex="0" style="margin-left: -17px; margin-top: -42px; width: 35px; height: 45px; transform: translate3d(83px, 218px, 0px); 
z-index: 5218;"><i class=" fa fa-moon  icon-white"></i></div>

<div class="awesome-marker-icon-blue awesome-marker leaflet-zoom-animated leaflet-interactive" 
title="London Socials #3 (28/2)" tabindex="0" style="margin-left: -17px; margin-top: -42px; width: 35px; height: 45px; transform: translate3d(83px, 218px, 0px); 
z-index: 5218;"><i class=" fa fa-moon  icon-white"></i></div>

And this is as far as I got to, unable to figure out how item 3 with a previously lower zIndex (compared to item 2) managed to end up on top with a new z-index: 5218 which just so happens to be the same new z-index value as for item 2 !据我所知,无法弄清楚具有先前较低 zIndex(与项目 2 相比)的项目 3 如何以新的z-index: 5218最终排在首位,这恰好是相同项目 2的新 z-index 值

I posted this as a bug on gitHub, but now I'm not so sure it is a bug with OMS-Leaflet.我将此作为错误发布在 gitHub 上,但现在我不太确定这是 OMS-Leaflet 的错误。 So am posting on here as well.所以我也在这里发帖。 Here's the fiddle showing the issues:这是显示问题的小提琴:

https://jsfiddle.net/magicmb/17j2z4gy/ https://jsfiddle.net/magicmb/17j2z4gy/

Environment specific versions: leaflet.js (1.6.0), Leaflet.awesome-markers (2.0.2), OverlappingMarkerSpiderfier-Leaflet (0.2.6)环境特定版本:leaflet.js (1.6.0)、Leaflet.awesome-markers (2.0.2)、OverlappingMarkerSpiderfier-Leaflet (0.2.6)

Turns out it's not exactly a bug with OMS-Leaflet but more an issue with Leaflet and how it handles z-Indexes事实证明,这不完全是 OMS-Leaflet 的错误,而是 Leaflet 及其处理 z-Indexes 的方式的问题

Here's an extract from a thread I discovered on gis.stackexchange that was answered by YaFred way back in Oct 2 '14 and still very much relevant today:这是我在gis.stackexchange上发现的一个线程的摘录, YaFred早在 2014 年 10 月 2 日就回答了这个线程,今天仍然非常相关:


Until somebody finds a better solution, here what I would do...在有人找到更好的解决方案之前,我会这样做......

As you noticed, leaflet is using pixel position to set zIndex (in Marker.js)如您所见,leaflet 使用像素 position 设置 zIndex(在 Marker.js 中)

pos = this._map._latLngToNewLayerPoint(this._latlng, opt.zoom, opt.center).round();
this._zIndex = pos.y + this.options.zIndexOffset;

What I suggest is to undo leaflet zIndex using setZIndexOffset()我的建议是使用 setZIndexOffset() 撤消 leaflet zIndex

Say you want to set zIndex = 100, you would do假设你想设置 zIndex = 100,你会做

var pos = map.latLngToLayerPoint(marker.getLatLng()).round();
marker.setZIndexOffset(100 - pos.y);

There is a bit of a glitch : you have to do it every time the map is zoomed :( [EDIT: Spiderfied in our case!]有一点小故障每次缩放 map 时都必须这样做:( [EDIT: Spiderfied in our case!]

Here is a JSFiddle example (comment the code in adjustZindex() to see the difference)这是一个JSFiddle 示例(注释 adjustZindex() 中的代码以查看区别)


For my OMS Spiderfy case this was resolved by adding:对于我的 OMS Spiderfy 案例,这是通过添加解决的:

function adjustZindex() {
    var markers = oms.getMarkers();
    for (var i = 0, len = markers.length; i < len; i ++) {
      var marker = markers[i];
      var latlng = marker._latlng, mIndexOffset = marker.options.mIndexOffset ;
      var pos = map.latLngToLayerPoint(latlng).round();
      marker.setZIndexOffset(mIndexOffset - pos.y);
    }
  }
  adjustZindex();

and then calling adjustZindex() from my spiderfy listeners然后从我的 spiderfy 监听器中调用 adjustZindex()

oms.addListener('spiderfy', function(markers) {
    layersBring2Front(); 
    adjustZindex();
  });

So I guess whether OMS should remember original zIndex of marker #76 was resolved in the version of OMS-Leaflet is kinda irrelevant as in all probability it would not have solved our issue.所以我想OMS 是否应该记住标记 #76 的原始 zIndex在 OMS-Leaflet 版本中得到解决有点无关紧要,因为它很可能不会解决我们的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM