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

calling setstyle after mvtSource has been added to map #80

Open
kewlspopo opened this issue Jan 14, 2018 · 2 comments
Open

calling setstyle after mvtSource has been added to map #80

kewlspopo opened this issue Jan 14, 2018 · 2 comments

Comments

@kewlspopo
Copy link

I need to set the style after the mvtSource has been added to the map but i'm having no luck.

i'm calling mvtsource.setStyle(function(){...})

but it doesn't seem to refer to the same object that's added to the map. Any way to retrieve a reference to the mvtSource from the map once it's already been added?

@apollolm
Copy link
Member

apollolm commented Feb 8, 2018

Can you provide a longer example of your code?

@jimjam-slam
Copy link

jimjam-slam commented Jun 21, 2018

I'm having a similar problem, having written a method that takes an arbitrary layer, adds one class to it using setStyle, adds it to a given map, then adds another class. Upon inspecting the DOM, the layer receives the first class but not the second.

_addAnnotation: function(overlay, map) {
    overlay.setStyle({ className: 'story-annotation' });
    overlay.addTo(map);
    overlay.setStyle({ className: 'story-annotation toggled_on' });
  }

If I modify the first setStyle call to use both classes (separated by spaces, as in the second call), the layer receives them both. If I move the second call to precede the call to addTo, both classes are received. So it seems that className can be altered, but only until the layer is attached to the map.

Also, if I add another property to the second call, such as fillColor: '#ff0000' to the path options, that is received even after attachment. So it seems like this problem is specific to className.

I'm using Leaflet 1.3.1 on Chrome 67.0.3396.87 for macOS 10.13.4.

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