Coder Social home page Coder Social logo

overlappingmarkerspiderfier-leaflet's Introduction

Overlapping Marker Spiderfier for Leaflet

Ever noticed how, in Google Earth, marker pins that overlap each other spring apart gracefully when you click them, so you can pick the one you meant?

And ever noticed how, when using the Leaflet API, the same thing doesn’t happen?

This code makes Leaflet map markers behave in that Google Earth way (minus the animation). Small numbers of markers (yes, up to 8) spiderfy into a circle. Larger numbers fan out into a more space-efficient spiral.

The compiled code has no dependencies beyond Leaflet. And it’s under 3K when compiled out of CoffeeScript, minified with Google’s Closure Compiler and gzipped.

It’s a port of my original library for the Google Maps API. (Since the Leaflet API doesn’t let us observe all the event types that the Google one does, the main difference between the original and the port is this: you must first call unspiderfy if and when you want to move a marker in the Leaflet version).

Doesn’t clustering solve this problem?

You may have seen the marker clustering libraries, which also help deal with markers that are close together.

That might be what you want. However, it probably isn’t what you want (or isn’t the only thing you want) if you have markers that could be in the exact same location, or close enough to overlap even at the maximum zoom level. In that case, clustering won’t help your users see and/or click on the marker they’re looking for.

Demo

See the demo map (the data is random: reload the map to reposition the markers).

Download

Download the compiled, minified JS source.

Or use it straight from cdnjs: <script src="https://cdnjs.cloudflare.com/ajax/libs/OverlappingMarkerSpiderfier-Leaflet/0.2.6/oms.min.js"></script>.

How to use

See the demo map source, or follow along here for a slightly simpler usage with commentary.

Create your map like normal (using the beautiful Stamen watercolour OSM map):

var map = new L.Map('map_canvas', {center: new L.LatLng(51.505, -0.09), zoom: 13});
var layer = new L.StamenTileLayer('watercolor');
map.addLayer(layer);

Create an OverlappingMarkerSpiderfier instance:

var oms = new OverlappingMarkerSpiderfier(map);

Instead of adding click listeners to your markers directly via marker.addEventListener or marker.on, add a global listener on the OverlappingMarkerSpiderfier instance instead. The listener will be passed the clicked marker as its first argument.

var popup = new L.Popup();
oms.addListener('click', function(marker) {
  popup.setContent(marker.desc);
  popup.setLatLng(marker.getLatLng());
  map.openPopup(popup);
});

You can also add listeners on the spiderfy and unspiderfy events, which will be passed an array of the markers affected. In this example, we observe only the spiderfy event, using it to close any open InfoWindow:

oms.addListener('spiderfy', function(markers) {
  map.closePopup();
});

Finally, tell the OverlappingMarkerSpiderfier instance about each marker as you add it, using the addMarker method:

for (var i = 0; i < window.mapData.length; i ++) {
  var datum = window.mapData[i];
  var loc = new L.LatLng(datum.lat, datum.lon);
  var marker = new L.Marker(loc);
  marker.desc = datum.d;
  map.addLayer(marker);
  oms.addMarker(marker);  // <-- here
}

Docs

Loading

The Leaflet L object must be available when this code runs — i.e. put the Leaflet API <script> tag before this one. The code has been tested with the 0.4 API version.

Construction

new OverlappingMarkerSpiderfier(map, options)

Creates an instance associated with map (an L.Map).

The options argument is an optional Object specifying any options you want changed from their defaults. The available options are:

keepSpiderfied (default: false)

By default, the OverlappingMarkerSpiderfier works like Google Earth, in that when you click a spiderfied marker, the markers unspiderfy before any other action takes place.

Since this can make it tricky for the user to work through a set of markers one by one, you can override this behaviour by setting the keepSpiderfied option to true.

nearbyDistance (default: 20).

This is the pixel radius within which a marker is considered to be overlapping a clicked marker.

circleSpiralSwitchover (default: 9)

This is the lowest number of markers that will be fanned out into a spiral instead of a circle. Set this to 0 to always get spirals, or Infinity for all circles.

legWeight (default: 1.5)

This determines the thickness of the lines joining spiderfied markers to their original locations.

Instance methods: managing markers

Note: methods that have no obvious return value return the OverlappingMarkerSpiderfier instance they were called on, in case you want to chain method calls.

addMarker(marker)

Adds marker (an L.Marker) to be tracked.

removeMarker(marker)

Removes marker from those being tracked.

clearMarkers()

Removes every marker from being tracked. Much quicker than calling removeMarker in a loop, since that has to search the markers array every time.

getMarkers()

Returns an Array of all the markers that are currently being tracked. This is a copy of the one used internally, so you can do what you like with it.

Instance methods: managing listeners

addListener(event, listenerFunc)

Adds a listener to react to one of three events.

event may be 'click', 'spiderfy' or 'unspiderfy'.

For 'click' events, listenerFunc receives one argument: the clicked marker object. You’ll probably want to use this listener to do something like show an L.Popup.

For 'spiderfy' or 'unspiderfy' events, listenerFunc receives two arguments: first, an Array of the markers that were spiderfied or unspiderfied; second, an Array of the markers that were not. One use for these listeners is to make some distinction between spiderfied and non-spiderfied markers when some markers are spiderfied — e.g. highlighting those that are spiderfied, or dimming out those that aren’t.

removeListener(event, listenerFunc)

Removes the specified listener on the specified event.

clearListeners(event)

Removes all listeners on the specified event.

unspiderfy()

Returns any spiderfied markers to their original positions, and triggers any listeners you may have set for this event. Unless no markers are spiderfied, in which case it does nothing. Be sure to call this before you call setLatLng on any tracked marker.

Properties

You can set the following properties on an OverlappingMarkerSpiderfier instance:

legColors.usual and legColors.highlighted

These determine the usual and highlighted colours of the lines.

You can also get and set any of the options noted in the constructor function documentation above as properties on an OverlappingMarkerSpiderfier instance.

Licence

This software is released under the MIT licence.

overlappingmarkerspiderfier-leaflet's People

Contributors

jawj avatar mourner avatar ryanjhodge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

overlappingmarkerspiderfier-leaflet's Issues

How to implement this in R?

Hi,

Not really a bug but more a request/question. I am using Leaflet through R and would need OverlappingMarkerSpiderfier-Leaflet for the map I want to plot, but I don't think this is implemented in the Leaflet R package. Is it planned? In the meantime, is there a way to implement it manually without knowing anything about JS? Or can I edit one of the output files I get from R when rendering my project as a web page?

Thank you.

Two Spiderfiers + Default Spiderfication?

Hi Jawj,

1] Is it possible to have two different spiderfiers on the same map without breaking anything?

2] Is it possible to have the default setting be that all markers are spiderfied?

Thanks for the awesome plugin,
Jeff

How to work it with markerClusterGroup

Hey, I'm really new to leaflet but I'm trying to do exactly what's said on the read me file in the principal folder. I can't figure out how to combine the MarkerClusterGroup plugin with this spider plugin. A little help, please.

integration with L.LayerGroup

Hi, do you know if this behavior can be used with markers within a a LayerGroup?
I don't seem to be able to get the spiderfy effect to work on a LayerGroup.

Thanks a lot!

question about zoom level

any way to easily have the spiderfy only active if the map zoom level is greater than X?
I only need the spiderfying on high zoom levels.
I am trying to avoid this behavior:
4th of July

circleMarker click not getting called

Hi, I see that the click event doesn't get called for circleMarker, but does get called for normal Marker. Any help?

http://jsfiddle.net/abarik/crk3jrhp/2/

html

<div id="map"></div>

css

#map {
    height: 440px;
}

javascript

map = L.map('map', {
    center: [7.2, 40.9],
    zoom: 2
});

L.tileLayer('http://{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.png', {
    attribution: "Map: Tiles Courtesy of MapQuest (OpenStreetMap, CC-BY-SA)",
    subdomains: ["otile1", "otile2", "otile3", "otile4"],
    maxZoom: 12,
    minZoom: 2
}).addTo(map);

var oms = new OverlappingMarkerSpiderfier(map);
var popup = new L.Popup();
oms.addListener('click', function(marker) {
  popup.setContent(marker.__name);
  popup.setLatLng(marker.getLatLng());
  map.openPopup(popup);
});

var marker1 = new L.Marker([1, 1]);
marker1.__name = 'marker1'
map.addLayer(marker1);
oms.addMarker(marker1);

var marker2 = new L.Marker([1, 1]);
marker2.__name = 'marker2'
map.addLayer(marker2);
oms.addMarker(marker2);

var marker1 = new L.circleMarker([20, 20]);
marker1.__name = 'cirmarker1'
map.addLayer(marker1);
oms.addMarker(marker1);

var marker2 = new L.circleMarker([20, 20]);
marker2.__name = 'cirmarker2'
map.addLayer(marker2);
oms.addMarker(marker2);

Problem in IE8 (and IE9's IE8 mode)

Adding this as an issue for information, in case others run into it -- thanks to Michal Zimmerman for the emailed report.


as I don't have github account, I'd like to report a bug via e-mail.
Clicking the spiderfied markers for the first time causes the map pan
in IE8 (Leaflet 0.4.4, latest version). Other clicks than the first
one work as they are supposed to. Console says "not implemented" in
http://cdn.leafletjs.com/leaflet-0.4.4/leaflet.js on row 6, char 8158
on page load.


Hmm. Can you give me a test URL that demonstrates this? And can you tell me whether the demo page (http://jawj.github.com/OverlappingMarkerSpiderfier-Leaflet/demo.html) shows the same problem?

The demo page seems fine to me in IE9's IE8 mode.


You can see the issue at http://dev.zimmi.cz/leaflet/. Your demo map
works fine as long as you don't include the newest Leaflet version,
but if you load it with <script src="http://cdn.leafletjs.com/leaflet-0.4.4/leaflet.js"></script>,
you'll see the bug (I have already tried it out with the demo map to
make sure it is not caused by the code I wrote).


OK, I can reproduce this with v 0.4.4 of Leaflet, but I don't think it has anything to do with my library -- you'll see the same thing happen on the map on Leaflet's front page, http://leaflet.cloudmade.com/.

Replacing the minified Leaflet with the -src version, it seems to be caused by an assignment to document.onselectstart on line 716 (in function: enableSelectStart).

I suggest you report this to the Leaflet maintainers.


You're right, I'll let them know.

Problems with instantiate

when I try to instantiate it just don't work, this error appears, if someone know how to solve it I will be thankful.
image

Spider legs remaining when layer switched off

Great plugin which has been a huge help, so firstly thanks!

I found what I think is a small bug. If I create the spiderfier using:

new OverlappingMarkerSpiderfier(map,{keepSpiderfied: true});

Now click on a group to "spiderfy".
Now from the layer control, switch off the layer while the group is still spidered - the markers are removed but he "legs" remain.

[Not an issue] Info for React integration

For any interested react-leaflet users, you can integrate this lib following way:

declare global {
  interface Window {
    OverlappingMarkerSpiderfier: any;
  }
}

interface ISpiderify {
  onClick?: (marker: L.Marker<any>) => void;
  onSpiderfy?: (markers: Marker<any>[]) => void;
  onUnspiderfy?: (markers: L.Marker<any>[]) => void;
  children?: React.ReactNode;
}
export const Spiderify = (props: ISpiderify) => {
  const map = useMap();

  const oms: any = useMemo(() => {
    const _oms =new window.OverlappingMarkerSpiderfier(map, {
      keepSpiderfied: false,
      nearbyDistance: 20, // This is the pixel radius within which a marker is considered to be overlapping a clicked marker. D=20
      circleSpiralSwitchover: Infinity, // This is the lowest number of markers that will be fanned out into a spiral instead of a circle. Set this to 0 to always get spirals, or Infinity for all circles.
      legWeight: 1.5, // This determines the thickness of the lines joining spiderfied markers to their original locations.
    });
    _oms.addListener("spiderfy", (markers: Marker[]) => {
      markers.forEach((m) => m.closePopup()); //force to close popup
      if (props.onSpiderfy) props.onSpiderfy(markers);
    });
    _oms.addListener("unspiderfy", (markers: Marker[]) => {
      if (props.onUnspiderfy) props.onUnspiderfy(markers);
    });
    _oms.addListener("click", (marker: Marker) => {
      if (props.onClick) props.onClick(marker);
    });
    return _oms;
  }, [map, props]);

  const childrenWithProps = React.Children.map(props.children, (child) => {
    // Checking isValidElement is the safe way and avoids a
    // typescript error too.
    if (React.isValidElement(child)) {
      // @ts-ignore
      return React.cloneElement(child, { oms });
    }
    return child;
  });
  return <LayerGroup>{childrenWithProps}</LayerGroup>;
};

Then in your MapContainer:

<Spiderify
  onClick={(m) => {
    console.log("click", m);
  }}
>
      {... all your <Marker /> ...}
</Spiderify>

Probably it can be improved...

adjust the opacity/visibility of unspiderified markers on click

I think one enhancement to this plugin which would greatly improve usability is to have the plugin set all of the markers which are not being spiderified as opaque when the spiderify function is called so that when the markers are moved outward and covering up other nearby markers it is still easy to tell which markers are the spiderified markers. This is especially useful for maps with a lot of marker on the screen.

unspiderfy() should always fire 'unspiderfy' event

When the unspiderfy() method is called it should always fire the 'unspiderfy' event before the method returns, even if no markers were spiderfied or moved to confirm to other listeners that all markers on the map are now unspiderfied.

When modifying or moving points and measuring distances, it is sometime useful to have method which only runs when you have confirmed all of the markers are unspiderfied. This means you need to set a listener for the 'unspiderfy' function which listens to the event that is emitted when you call oms.unspiderfy() so that after all of the markers are unspiderfied, you can have a callback which modifies, moves, or measures distances between the points.

icon.popupAnchor not adhered to . WAS: marker.iconAnchor not adhered to

Reposting from incorrect project OverlappingMarkerSpiderfier.
And with a completely incorrect description. Must have been late yesterday or something.

What I wanted to say is the following:

When using spiderfier, popups appear on top of my offset icon instead of above (which happens correctly when not using spiderfier) .

rom the description of 'icon.popupAnchor': "The coordinates of the point from which popups will "open", relative to the icon anchor."

An example:

MARKER DECLARATION

var pointToLayer = function (feature, latlng) {
   .....
   return marker = new L.Marker(latlng,{
    icon: L.divIcon({
                className: 'micon micon-' + feature.properties.cssPostfix,
        iconAnchor: [15, 30],
        popupAnchor: [1, -32]
    })
   });
}

POPUP DECLARATION WITHOUT SPIDERFIER (WORKS)

function onEachFeature(feature, layer) {
   if(!doSpiderify){
          layer.bindPopup("SOME TEXT"));
   }                            
}

POPUP DECLARATION WITH SPIDERFIER (DOESN'T WORK)

//NOTE: DECLARED ONCE INSTEAD OF IN ONEACHFEATURE
if(doSpiderify){
    oms = new window.OverlappingMarkerSpiderfier(map,{nearbyDistance :28});
    oms.addListener('spiderfy', function(markers) {
        map.closePopup();
    });
       var popup = new L.Popup();
       oms.addListener('click', function(marker) {
            popup.setContent("SOME TEXT");
            popup.setLatLng(marker.getLatLng());
            map.openPopup(popup);
      });
}

Geert-Jan

Handle layers/markers that are not visible

I created a map with two layers of markers that can be turned on and off.

There seems to be a problem that if one of the layers is turned off. Spiderify doesn't take into account the visibility of markers. Clicking a marker for the layer that is visible which is close to one of the hidden markers the visible one jump aside for no reason.

In this scenario the user sees a 'leg' (or legs) with nothing at the end as some of the markers are hidden.

I understand a workaround would be to use add/remove/clear markers functions when toggling layers on and off, but it would be nice if this wasn't necessary.

OverlappingMarkerSpiderfier for iOS

Hai Sir,

OverlappingMarkerSpiderfier is working ultimately in android platform. But the same is missing for iOS, so please can u post similar library for iOS as well.

Thanks

Oops.

Please delete this, wrong account.

angular 4 and overlappingMarkerSpiderfier

I am trying t use overlappingmarkerspiderfier with leaflet in my angular 4 application.
It worked with angular1 app, But the same is not for angular4
I installed the package with
npm install npm i overlapping-marker-spiderfier

But when I add
var oms = new OverlappingMarkerSpiderfier(mmap);

It gives the error that google not defined

When I add the google-map api to index.html the error is
InvalidValueError: setMap: not an instance of Map; and not an instance of StreetViewPanorama

How can I solve this issue and get it working in angular4

Configurable leg length

Hello!

Can we include a feature to configure the length of the spiderfy leg? Right now, we only have legWeight and it would help a lot if we would also have that as an option when creating the layer.

Thank you!

how to reinitizialise spiderfy

hi,
is there a way to reinitialise spiderfy.
My problem is:
I load all markers and the user can select different filter where some markers are hidden.
now the problem is if a marker that was spiderfied in the "all marker" view could be not spiderfied in the filtered view.

So I am looking for a way to "reset" and "reload" spiderfy on the filtered markers.

thx for your help!

cheers,

ToM

keepSpiderfied: true does not work

Hi,

I was hoping that spiderfied results would stay open when clicking between different results. This isn't the case using the following code however:

var oms = new OverlappingMarkerSpiderfier(map, { keepSpiderfied : true});

On a somewhat related note, is it possible to spiderfy each item automatically without a click?

How to specify custome marker/icon when "unspiderfied"

Hello,

Thanks for this great module.

I'm wondering how the main marker is choosed (the one displayed by default).
Is there any way to specify my own ?

In my case, I plot on a map several computers in the same physical place. I'd like having a specific icon representing the physical place itself. Then, clicking on it shows me all the computers.

Any clue ?

keepSpiderfied does nothing

I'm expecting keepSpiderfied to keep all the spiderfied markers to be expanded, instead it changes nothing to the behaviour, I still have to click a markergroup to expand them, and when I click another group, the old one collapses again.

I want functionality that a user does not have to click at all, all groups are expanded by default. Is this possible? Isn't this what the keepSpiderfied option is supposed to do?

Not working correctly with circleMarker

I tried to use this with circleMarker but it doesn't seem to work as expected. Instead of expanding the entire group, it only expands one marker per click.

I managed to reproduce the behaviour with the demo by changing
var marker = new L.Marker(loc, {icon: new darkIcon()});
to
var marker = new L.circleMarker(loc, { color: 'red', radius: 5 });

split animation

I am just curious to better understand why it seems to be such a challenge to animate markers so they indeed spring apart.

The only example I have seen which accomplished this capability is the solution put in place by redfin. Notice the animation of markers upon zooming in/out at given levels.

Working example:
http://www.redfin.com/homes-for-sale#!disp_mode=M&market=socal&region_id=16904&region_type=6&v=6

Would you mind outlining the complexities of developing a similar solution and/or break down how they seem to accomplish this?

BTW, I raised this issue on the user voices thread for leaflet and its one of the top requested features.

Link: http://leaflet.uservoice.com/forums/150880-ideas-and-suggestions-for-leaflet/suggestions/2752544-animated-marker-controls

Popup pop once after clic in the spiderly pin

Hi,

The behavior of spiderfier is different if I clic on the pin spiderfier. I explain:

  1. Clic on a spiderfier pin
  2. Clic on the same pin again to open a popup.
  3. Clic outside to unspiderfier
  4. Clic on spiderfier pin => the popup shows directly instead of me clicking another time.

So, it's different behavior and I try to patch without success.

Can someone give me a light or something to look after ?

Thank.

Best regards,
Mafyou.

spiderify markers ADA accessibility

I have been working on making my maps more accessible to users with screen readers and users who navigate via keyboards, and one issue I have noticed is that when I am using OMS, some of the functionality is not not very accessible.

When I 'tab' to a marker which is overlapping with other markers, and press 'enter' the overlapping markers spiderify, and my focus remains on the original marker which is great, but when I start tabbing again, the focus shifts off of the spiderified markers to other markers on the screen. Additionally, there is currently no way to unspiderify the markers when they are spiderified(pressing 'enter' spiderifies, but we need another key option to unspiderify).

I think 2 improvements which we could make to this plugin which would make it more accessible is to:

  1. Add a default event handler to the 'esc' key when markers are spiderified which unspiderifies markers.
  2. When markers are spiderified maintain the focus to the spiderified markers by preventing the other markers on the map from being getting focus from tabbing. Tabbing can be used to navigate between the spiderified markers in a clockwise order until the markers are unspiderified when the focus can again shift to the other markers on the map. Additionally if a spiderified marker has the focus the 'left' and 'right' arrow keys should also be usable to allow users to switch between spiderified markers, while the up and down keys should be able to spiderify and unspiderify.

Upload to CDNJS

I have opened issue cdnjs/cdnjs#10893 back in March but haven't had much activity in this area.

I want to use this in a project, but require the item to be in the CDNJS repository.

I can see that your original https://github.com/jawj/OverlappingMarkerSpiderfier is already in the repository. Hoping there might be something you can do to help get this into CDNJS quicker. I'm new to this whole GitHub thing and haven't had success so far.

Programmatically trigger event

Hi!

Love the OMS, works great :-)

Just wanted to check if it is possible to programmatically trigger e.g. the "spiderfy" event?

Use case being populating a group of related markers, where one is kind of "current", and at that marker position, another marker is also present. Desire is to show both those markers initially...

Cheers
-jo

Spiderfied marker differs from initial loaded spider marker

our setup

We (our community project & me aka tech dabbler) have an L.map with various layers of L.markers loading from a dynamic array of events spanning a monthly period. 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

Each marker is put into one of several marker Layers depending on day of week or whether the event has been confirmed / expires e.g. 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.

the issue

We have everything loading and stacking as required and it all works fine until we 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 (i.e. also the OMS version for Google Maps API v3), and found a couple of closed ones that seemed to suggest a similar issue:

OMS should remember original zIndex of marker #76
z-Indices reset #117 (previous fix closes this)

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.

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.

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

// 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).

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:

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

Spiderfy

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

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)


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!


If you find the time to look at this and perhaps examine the dev console results or anything else in the below jsfiddle below we would really appreciate your feedback.

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


Environment specific versions:
leaflet.js (1.6.0), Leaflet.awesome-markers (2.0.2), OverlappingMarkerSpiderfier-Leaflet (0.2.6)


post scriptum

It goes without saying OMS for Leaflet is a really fabulous project and much appreciated by an undoubtedly growing number of users. Many thanks ❤️

Reopening: feature request: icon offset

Since icons often are offset from the actual point (using iconAnchor: [15, 30] for instance) it makes sense to take this into account (it doesn't seem to do so at the moment) . After all, goal is to clarify which icon is clicked / are present.

Would this make sense?

Best,
Geert-Jan

P.s: and of course thanks for this great plugin!

No support for moving markers

When a marker is moved, e.g. via setLatLng, 'move' event is not catched in the plugin, so it's marker['_omsData'].usualPosition is not updated accordingly, which results in wrong marker location after unspiderfying it.

Where to find non-minified source?

I might just be dense, but I can't find the code in the github files.

I'm trying to add a "hasMarker" function, but I don't see the code in github.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.