<p></p>
<p dir="auto">I remade PR. I abandoned <code class="notranslate">overlaylayerchange</code> because this event is not in Leaflet and it is not suitable in our situation.</p>
<p dir="auto">In the case of <code class="notranslate">baselyerchange</code>, 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, <code class="notranslate">baslaverchange</code> 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.</p>
<p dir="auto">However, after rejecting <code class="notranslate">layerremove</code>, 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)</p>
<p dir="auto">So I use <code class="notranslate">overlayadd</code>/<code class="notranslate">overlayremove</code> which are in Leaflet <a href="https://leafletjs.com/reference.html#map-event" rel="nofollow">https://leafletjs.com/reference.html#map-event</a><br>
I fire these events when the <code class="notranslate">add</code>/<code class="notranslate"> remove</code> is triggered, as well as for active objects that should be shown on the map (current node, paths, note, ...)</p>
<hr>
<p dir="auto">What was tested:</p>
<p dir="auto">1: Basic layer switching functionality</p>
<p dir="auto"><a href="https://github.com/user-attachments/assets/1d7bce4e-3ab6-4366-874f-6a2bb16afb00">https://github.com/user-attachments/assets/1d7bce4e-3ab6-4366-874f-6a2bb16afb00</a></p>
<ol start="2" dir="auto">
<li>Switching layers in the URL</li>
</ol>
<p dir="auto"><a href="https://github.com/user-attachments/assets/6a201eab-65cd-44a9-804e-1efddcc3e256">https://github.com/user-attachments/assets/6a201eab-65cd-44a9-804e-1efddcc3e256</a></p>
<ol start="3" dir="auto">
<li>Update links to the active object in the Edit button</li>
</ol>
<p dir="auto"><a href="https://github.com/user-attachments/assets/539fd547-09af-4d0f-8299-0b1699581a2b">https://github.com/user-attachments/assets/539fd547-09af-4d0f-8299-0b1699581a2b</a></p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/pull/5474#issuecomment-2615702185">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLOA7PM6L5KCFOQ47NT2MYU2HAVCNFSM6AAAAABUVSY6FWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMMJVG4YDEMJYGU">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AAK2OLPRUBR366KLW7XSG7D2MYU2HA5CNFSM6AAAAABUVSY6FWWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTU35BZKS.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><openstreetmap/openstreetmap-website/pull/5474/c2615702185</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/pull/5474#issuecomment-2615702185",
"url": "https://github.com/openstreetmap/openstreetmap-website/pull/5474#issuecomment-2615702185",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>