sync problem between map and layerswitcher

42 views
Skip to first unread message

Pascal Boulesteix

unread,
Dec 22, 2024, 11:35:38 AM12/22/24
to Leaflet
Hello everyone

In my test page https://visiolittoral.fr/ANDROID_CAR...=46.15&ZOOM=12 I use several LeafLet features.

Among others, the ability to display geoJson data (lines 156 to 247).

The principle is to display geoJson data from three URLs that return the same geoJson structure.

In the geoJson, if the "typeloc" property starts with a "G", I do not want to display the layer but I want it to be present in the layerswitcher for on-demand display (Lines 228 to 231).

In the current version of the code, I start with an addTo(map) for all layers, the addition in the layerswitcher, then for the 'G', I remove the layer from the map. I tried simply not to do the addTo for the 'G', but that doesn't change the problem that I'm explaining to you now.

On the first display, the geoJson data other than the 'G' (Commune and neighboring commune) are displayed correctly. To display the 'G', you must in theory open the LayerSwitcher, uncheck the "eye" to display the map.

That's the problem!

On the first display, the "eye" of the "G" is "open in the layerSwitcher which means that the layer is displayed on the map, and this is not the case of course.

To find a perfect synchronization between map and layerswitcher, you have to click twice on the "eye", once to close it, once to open it.

There you go, since you didn't know what to do, I found you something to do!

Kind regards

Pascal

Phase 1
phase1.png
Phase 2phase2.png
Phase 3phase3.png

Pascal Boulesteix

unread,
Dec 22, 2024, 6:45:51 PM12/22/24
to Leaflet

Edwin Corrigan

unread,
Dec 26, 2024, 10:41:24 PM12/26/24
to leafl...@googlegroups.com
Hi Pascal, 

Think I was able to get what you want with this command, which I got it from the geoPortal documentation - https://ignf.github.io/geoportal-extensions/leaflet-latest/jsdoc/L.geoportalControl.LayerSwitcher.html:

layerSwitcher.setVisibility(geoJsonLayer, false)

I put a breakpoint in the picture below, and then executed the command above from the console. I think the command above will run map.removeLayer also, so you probably don't need the one there. It worked ok and seems to remove the layer from the map. Also after playing after the breakpoint, I can see that the eye is crossed, which I think is what you expect. Both pictures below. 

Next I would look into the visibility configuration in the layer.config property object. I think you can then add it to the map, without having to run the set visibility command at all - https://ignf.github.io/geoportal-extensions/leaflet-latest/jsdoc/module-Controls.html#.LayerSwitcher

Hope this helps,
Edwin 


image.png

image.png


--

---
You received this message because you are subscribed to the Google Groups "Leaflet" group.
To unsubscribe from this group and stop receiving emails from it, send an email to leaflet-js+...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/leaflet-js/decd025b-4f38-4526-b3b1-04057d85cfe4n%40googlegroups.com.

Pascal Boulesteix

unread,
Dec 27, 2024, 6:01:35 AM12/27/24
to Leaflet
Edwin.
You are ending the year with a bang! 
Thanks for this solution that works very well. 
Once again, thank you. 
Pascal
Reply all
Reply to author
Forward
0 new messages