[openstreetmap/openstreetmap-website] Use baselayerchange/overlayadd/overlayremove instead of layeradd/layerremove (PR #5474)

Roman Deev notifications at github.com
Mon Jan 27 13:01:23 UTC 2025


I remade PR. I abandoned `overlaylayerchange` because this event is not in Leaflet and it is not suitable in our situation.

In the case of `baselyerchange`, we can expect that our last base layer is always removed and a new base layer is added. Therefore, the removal event is not necessary to track the layer, `baslaverchange` is enough. But in the case of overlays, this is not so, overlays can just be removed from the map, without adding a new one.

However, after rejecting `layerremove`, it becomes important to maintain the invariant that there can't be multiple base layers on the map. I.e. first remove all previous layers and only then add a new one (this is important for example for a field with an iframe, sometimes you can see two base layers at the same time)

So I use `overlayadd`/`overlayremove` which are in Leaflet https://leafletjs.com/reference.html#map-event
I fire these events when the `add`/` remove` is triggered, as well as for active objects that should be shown on the map (current node, paths, note, ...)

---

What was tested:

1: Basic layer switching functionality

https://github.com/user-attachments/assets/1d7bce4e-3ab6-4366-874f-6a2bb16afb00

2. Switching layers in the URL

https://github.com/user-attachments/assets/6a201eab-65cd-44a9-804e-1efddcc3e256

3. Update links to the active object in the Edit button

https://github.com/user-attachments/assets/539fd547-09af-4d0f-8299-0b1699581a2b






-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/5474#issuecomment-2615702185
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/pull/5474/c2615702185 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20250127/d8633d75/attachment.htm>


More information about the rails-dev mailing list