4

I am not very good at js and new with leaflet so i my code may be a bit messy but stil... I have a problem with my legends, i have 2 legends and many overlays and i want some legends to be "linked" with some overlays. I followed every example i saw but still i have a problem with the name of the layer, it's like my names don't work so controls can't change legends properly

I made a jsfiddle that can explains more obviously my problem. http://jsfiddle.net/qs6wkru4/3/

I want the legend to change when i click on "Cuivre" and not on others...

3
  • the external ressources in your jsfiddle point to "localhost". can you please update the jsfiddle so that it's working
    – Thomas B
    Commented Sep 30, 2015 at 9:23
  • Oh didn't see ! Done
    – Gautier
    Commented Sep 30, 2015 at 13:00
  • so your actual version is now jsfiddle.net/qs6wkru4/4 ...the link above not up to date anymore ;)
    – Thomas B
    Commented Sep 30, 2015 at 15:27

1 Answer 1

2

Your Leaflet-Version is 1.0dev. There the eventlayer.name is missing.

I also added a counter so see when the other legend has to be removed. Was this the functionality you were looking for?

http://jsfiddle.net/expedio/7LskL5e1/

2
  • It's working ! So it comes from the version of leaflet? U did what i wanted, having a legend that changes with layers. I think i will go with "base layers" instead of layers because i only want 1 layer at time !
    – Gautier
    Commented Oct 1, 2015 at 8:37
  • yes.with baselayers you will have to listen to the baselayerchange-event... something like this: jsfiddle.net/expedio/3xnxfo6q/4
    – Thomas B
    Commented Oct 1, 2015 at 21:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.