<p dir="auto"><code class="notranslate">layersAdded</code> is a leftover from <code class="notranslate">updateLayers</code> logic before <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="2770637460" data-permission-text="Title is private" data-url="https://github.com/openstreetmap/openstreetmap-website/issues/5474" data-hovercard-type="pull_request" data-hovercard-url="/openstreetmap/openstreetmap-website/pull/5474/hovercard" href="https://github.com/openstreetmap/openstreetmap-website/pull/5474">#5474</a>, when there was a single loop that both added and removed layers. Now there are two loops, the first one is removing layers, while the second one is adding, but it can only add one layer.</p>
<p dir="auto">Before this PR:</p>
<ul dir="auto">
<li>the second loop checks the layer code</li>
<li>if it matches, the layer is added and its code is recorded into <code class="notranslate">layersAdded</code></li>
<li>on the final iteration if there's no match, <code class="notranslate">layersAdded</code> is checked</li>
<li>if it's empty, layer[0] is added</li>
</ul>
<p dir="auto">After:</p>
<ul dir="auto">
<li>the second loop checks the layer code match OR if it's the final iteration *</li>
<li>if the condition is true, the layer is added and the function returns because there's nothing else to do</li>
</ul>
<p dir="auto">* I'm checking <code class="notranslate">i == 0</code> inside the loop instead of adding layer[0] after the loop to allow the function to work with empty base layer set. Maybe that's going to be useful for someone.</p>
<hr>
<h4>You can view, comment on, or merge this pull request online at:</h4>
<p> <a href='https://github.com/openstreetmap/openstreetmap-website/pull/5560'>https://github.com/openstreetmap/openstreetmap-website/pull/5560</a></p>
<h4>Commit Summary</h4>
<ul>
<li><a href="https://github.com/openstreetmap/openstreetmap-website/pull/5560/commits/a7da2a5b3962a28e2cafbd6ae606290a29639a78" class="commit-link">a7da2a5</a> Remove layersAdded variable from map.updateLayers()</li>
</ul>
<h4 style="display: inline-block">File Changes </h4> <p style="display: inline-block">(<a href="https://github.com/openstreetmap/openstreetmap-website/pull/5560/files">1 file</a>)</p>
<ul>
<li>
<strong>M</strong>
<a href="https://github.com/openstreetmap/openstreetmap-website/pull/5560/files#diff-f060eef487077b042f45b3a12e7a2cbd54a446f8c744cdb98405a1295430e8b9">app/assets/javascripts/leaflet.map.js</a>
(9)
</li>
</ul>
<h4>Patch Links:</h4>
<ul>
<li><a href='https://github.com/openstreetmap/openstreetmap-website/pull/5560.patch'>https://github.com/openstreetmap/openstreetmap-website/pull/5560.patch</a></li>
<li><a href='https://github.com/openstreetmap/openstreetmap-website/pull/5560.diff'>https://github.com/openstreetmap/openstreetmap-website/pull/5560.diff</a></li>
</ul>
<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/5560">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLPFFJC64XZMNNEEMSL2MZHHPAVCNFSM6AAAAABV6L5576VHI2DSMVQWIX3LMV43ASLTON2WKOZSHAYTGMZVGQ2DMNA">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AAK2OLLRFVGMKBOWAGTTIXD2MZHHPA5CNFSM6AAAAABV6L5576WGG33NNVSW45C7OR4XAZNFJFZXG5LFVJRW63LNMVXHIX3JMTHKPMDB4A.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/5560</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/5560",
"url": "https://github.com/openstreetmap/openstreetmap-website/pull/5560",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>