Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working correctly with circleMarker #13

Open
96187 opened this issue Jul 1, 2014 · 3 comments
Open

Not working correctly with circleMarker #13

96187 opened this issue Jul 1, 2014 · 3 comments

Comments

@96187
Copy link

96187 commented Jul 1, 2014

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 });

@therealtakeshi
Copy link

Running into this same issue as well. I have multiple maps, one using regular Marker with icons, the other using circleMarker.
The Marker one will expand all nearby markers as expected, while the circleMarker expands only 1 per click.

@therealtakeshi
Copy link

cc @96187:

This looks like it's related to the marker.setZIndexOffset() method used on lines 296 and 326. In my local version, I've gotten the expected results on a group using circleMarker by adding a simple IF check for marker._path (since circleMarker extends Path, not Marker). See below.

l296:
if (marker._path) { marker.bringToFront(); } else { marker.setZIndexOffset(1000000); }

l326:
if (marker._path) { marker.bringToBack(); } else { marker.setZIndexOffset(0); }

@Greigrm
Copy link

Greigrm commented Oct 16, 2015

Its a long time since there was activity on this project and while I'm converting my other work to Leaflet 1.0 I thought I'd have a look at this issue. I know nothing about coffescript, so cut/paste it into a website to convert to js and am using that directly now, so all of the below is in the raw js.

As @therealtakeshi above pointed out, when using a circlemarker the zIndexOffset function doesn't apply. I also replaced the accessing of the private variable (_path) by using a 'marker instanceof L.CircleMarker' comparison. That fixed the script error, but now the circle markers simply didn't spiderfy - nothing happened at all. I got firebug into action and stepped through the code and could see that the markers were actually spiderfying and then immediately unspiderfying. It looks as is the click event on the marker was correctly spiderfying, but then the click event was propagating through to the map itself, which caused the normal unspiderfy action called as if the map was clicked in "open space".

To fix it I did a quick hack - there is probably a more elegant solution to this which stops the propagation of the leaflet event, but with my deadlines I'm all about the quick hack.

What I did:

  1. add a private variable in the class definition, simply
     this._stopUnspider = false; 
  1. find the existing line marker.setZIndexOffset(1000000);
    replace with
   if (marker instanceof L.CircleMarker) 
         {this._stopUnspider = true;} 
   else {marker.setZIndexOffset(1000000);}
  1. find the existing line marker.setZIndexOffset(0);
    replace with
       if (!marker instanceof L.CircleMarker) { marker.setZIndexOffset(0); }
  1. finally, in the unspiderfy function, find this:
   if (this.spiderfied == null) {
      return this;
    }

replace with:

   if (this.spiderfied == null || this._stopUnspider) {
      this._stopUnspider = false;
      return this;
    }

I hope that helps someone else. Sorry for not doing the "proper" update through github, but I don't do coffeescript, and it looks as if this plugin has been abandoned anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants