<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic leaflet: removeLayer() work only once in JavaScript in Open Source Mapping Libraries Ques.</title>
    <link>https://community.esri.com/t5/open-source-mapping-libraries-ques/leaflet-removelayer-work-only-once-in-javascript/m-p/1131784#M101</link>
    <description>&lt;P&gt;&lt;A href="https://i.stack.imgur.com/isPYk.jpg" target="_blank" rel="noopener"&gt;&amp;nbsp; This is my map&lt;/A&gt;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;,my removeLayer in leaflet map remove once (&lt;/SPAN&gt;&lt;A href="https://i.stack.imgur.com/fCc16.jpg" target="_blank" rel="noopener"&gt;Removed picture&lt;/A&gt;&amp;nbsp;)&lt;SPAN&gt;and as you see in picture it remove marker perfectly but when I try to remove it again it don't!&amp;nbsp;&lt;A href="https://i.stack.imgur.com/EitmA.jpg" target="_blank" rel="noopener"&gt;checked is not true but it didnt remove for 2nd time&lt;/A&gt;&amp;nbsp;here is the function that called from checkbox :&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; &lt;SPAN class=""&gt;function&lt;/SPAN&gt; &lt;SPAN class=""&gt;myFunction&lt;/SPAN&gt;(&lt;SPAN class=""&gt;id&lt;/SPAN&gt;) {
    &lt;SPAN class=""&gt;var&lt;/SPAN&gt; marker = [];
    &lt;SPAN class=""&gt;var&lt;/SPAN&gt; checkBox = &lt;SPAN class=""&gt;document&lt;/SPAN&gt;.&lt;SPAN class=""&gt;getElementById&lt;/SPAN&gt;(id)
    &lt;SPAN class=""&gt;var&lt;/SPAN&gt; lat = checkBox.&lt;SPAN class=""&gt;name&lt;/SPAN&gt;;
    &lt;SPAN class=""&gt;var&lt;/SPAN&gt; lon = checkBox.&lt;SPAN class=""&gt;value&lt;/SPAN&gt;;
    &lt;SPAN class=""&gt;var&lt;/SPAN&gt; &lt;SPAN class=""&gt;RN&lt;/SPAN&gt; = checkBox.&lt;SPAN class=""&gt;className&lt;/SPAN&gt;;
    &lt;SPAN class=""&gt;console&lt;/SPAN&gt;.&lt;SPAN class=""&gt;log&lt;/SPAN&gt;(&lt;SPAN class=""&gt;RN&lt;/SPAN&gt;)
    
    &lt;SPAN class=""&gt;var&lt;/SPAN&gt; pop_cont = &lt;SPAN class=""&gt;`&amp;lt;img id="icon" src="sample.jpg" alt="shipPIC"/&amp;gt;&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;&lt;SPAN class=""&gt;${RN}&lt;/SPAN&gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt; latitude :&lt;SPAN class=""&gt;${lat}&lt;/SPAN&gt;&amp;lt;br&amp;gt;longitude: &lt;SPAN class=""&gt;${lon}&lt;/SPAN&gt;`&lt;/SPAN&gt;
    &lt;SPAN class=""&gt;if&lt;/SPAN&gt; (checkBox.&lt;SPAN class=""&gt;checked&lt;/SPAN&gt; == &lt;SPAN class=""&gt;true&lt;/SPAN&gt;) {
        marker = L.&lt;SPAN class=""&gt;marker&lt;/SPAN&gt;([lat, lon]).&lt;SPAN class=""&gt;addTo&lt;/SPAN&gt;(map);
        marker.&lt;SPAN class=""&gt;setIcon&lt;/SPAN&gt;(dish_icon);
        marker.&lt;SPAN class=""&gt;bindPopup&lt;/SPAN&gt;(pop_cont).&lt;SPAN class=""&gt;openPopup&lt;/SPAN&gt;();
        &lt;SPAN class=""&gt;console&lt;/SPAN&gt;.&lt;SPAN class=""&gt;log&lt;/SPAN&gt;(&lt;SPAN class=""&gt;"checked"&lt;/SPAN&gt;)

    } &lt;SPAN class=""&gt;else&lt;/SPAN&gt; {
        marker = L.&lt;SPAN class=""&gt;marker&lt;/SPAN&gt;([lat, lon])
        &lt;SPAN class=""&gt;var&lt;/SPAN&gt; x_id = L.&lt;SPAN class=""&gt;stamp&lt;/SPAN&gt;(markers);
        map.&lt;SPAN class=""&gt;removeLayer&lt;/SPAN&gt;(markers[id]);
        &lt;SPAN class=""&gt;console&lt;/SPAN&gt;.&lt;SPAN class=""&gt;log&lt;/SPAN&gt;(&lt;SPAN class=""&gt;"NOOOOT Check"&lt;/SPAN&gt;);

        
       
    }
}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; why removeLayer() work for first time remove but when i add that layer again and want to remove it , removeLayer don't work?!&lt;BR /&gt;thank you verymuch!&lt;/P&gt;</description>
    <pubDate>Fri, 25 Aug 2023 20:10:09 GMT</pubDate>
    <dc:creator>samadalien</dc:creator>
    <dc:date>2023-08-25T20:10:09Z</dc:date>
    <item>
      <title>leaflet: removeLayer() work only once in JavaScript</title>
      <link>https://community.esri.com/t5/open-source-mapping-libraries-ques/leaflet-removelayer-work-only-once-in-javascript/m-p/1131784#M101</link>
      <description>&lt;P&gt;&lt;A href="https://i.stack.imgur.com/isPYk.jpg" target="_blank" rel="noopener"&gt;&amp;nbsp; This is my map&lt;/A&gt;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;,my removeLayer in leaflet map remove once (&lt;/SPAN&gt;&lt;A href="https://i.stack.imgur.com/fCc16.jpg" target="_blank" rel="noopener"&gt;Removed picture&lt;/A&gt;&amp;nbsp;)&lt;SPAN&gt;and as you see in picture it remove marker perfectly but when I try to remove it again it don't!&amp;nbsp;&lt;A href="https://i.stack.imgur.com/EitmA.jpg" target="_blank" rel="noopener"&gt;checked is not true but it didnt remove for 2nd time&lt;/A&gt;&amp;nbsp;here is the function that called from checkbox :&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; &lt;SPAN class=""&gt;function&lt;/SPAN&gt; &lt;SPAN class=""&gt;myFunction&lt;/SPAN&gt;(&lt;SPAN class=""&gt;id&lt;/SPAN&gt;) {
    &lt;SPAN class=""&gt;var&lt;/SPAN&gt; marker = [];
    &lt;SPAN class=""&gt;var&lt;/SPAN&gt; checkBox = &lt;SPAN class=""&gt;document&lt;/SPAN&gt;.&lt;SPAN class=""&gt;getElementById&lt;/SPAN&gt;(id)
    &lt;SPAN class=""&gt;var&lt;/SPAN&gt; lat = checkBox.&lt;SPAN class=""&gt;name&lt;/SPAN&gt;;
    &lt;SPAN class=""&gt;var&lt;/SPAN&gt; lon = checkBox.&lt;SPAN class=""&gt;value&lt;/SPAN&gt;;
    &lt;SPAN class=""&gt;var&lt;/SPAN&gt; &lt;SPAN class=""&gt;RN&lt;/SPAN&gt; = checkBox.&lt;SPAN class=""&gt;className&lt;/SPAN&gt;;
    &lt;SPAN class=""&gt;console&lt;/SPAN&gt;.&lt;SPAN class=""&gt;log&lt;/SPAN&gt;(&lt;SPAN class=""&gt;RN&lt;/SPAN&gt;)
    
    &lt;SPAN class=""&gt;var&lt;/SPAN&gt; pop_cont = &lt;SPAN class=""&gt;`&amp;lt;img id="icon" src="sample.jpg" alt="shipPIC"/&amp;gt;&amp;lt;br&amp;gt;&amp;lt;b&amp;gt;&lt;SPAN class=""&gt;${RN}&lt;/SPAN&gt;&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt; latitude :&lt;SPAN class=""&gt;${lat}&lt;/SPAN&gt;&amp;lt;br&amp;gt;longitude: &lt;SPAN class=""&gt;${lon}&lt;/SPAN&gt;`&lt;/SPAN&gt;
    &lt;SPAN class=""&gt;if&lt;/SPAN&gt; (checkBox.&lt;SPAN class=""&gt;checked&lt;/SPAN&gt; == &lt;SPAN class=""&gt;true&lt;/SPAN&gt;) {
        marker = L.&lt;SPAN class=""&gt;marker&lt;/SPAN&gt;([lat, lon]).&lt;SPAN class=""&gt;addTo&lt;/SPAN&gt;(map);
        marker.&lt;SPAN class=""&gt;setIcon&lt;/SPAN&gt;(dish_icon);
        marker.&lt;SPAN class=""&gt;bindPopup&lt;/SPAN&gt;(pop_cont).&lt;SPAN class=""&gt;openPopup&lt;/SPAN&gt;();
        &lt;SPAN class=""&gt;console&lt;/SPAN&gt;.&lt;SPAN class=""&gt;log&lt;/SPAN&gt;(&lt;SPAN class=""&gt;"checked"&lt;/SPAN&gt;)

    } &lt;SPAN class=""&gt;else&lt;/SPAN&gt; {
        marker = L.&lt;SPAN class=""&gt;marker&lt;/SPAN&gt;([lat, lon])
        &lt;SPAN class=""&gt;var&lt;/SPAN&gt; x_id = L.&lt;SPAN class=""&gt;stamp&lt;/SPAN&gt;(markers);
        map.&lt;SPAN class=""&gt;removeLayer&lt;/SPAN&gt;(markers[id]);
        &lt;SPAN class=""&gt;console&lt;/SPAN&gt;.&lt;SPAN class=""&gt;log&lt;/SPAN&gt;(&lt;SPAN class=""&gt;"NOOOOT Check"&lt;/SPAN&gt;);

        
       
    }
}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; why removeLayer() work for first time remove but when i add that layer again and want to remove it , removeLayer don't work?!&lt;BR /&gt;thank you verymuch!&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2023 20:10:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/open-source-mapping-libraries-ques/leaflet-removelayer-work-only-once-in-javascript/m-p/1131784#M101</guid>
      <dc:creator>samadalien</dc:creator>
      <dc:date>2023-08-25T20:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: leaflet: removeLayer() work only once in JavaScript</title>
      <link>https://community.esri.com/t5/open-source-mapping-libraries-ques/leaflet-removelayer-work-only-once-in-javascript/m-p/1150179#M102</link>
      <description>&lt;P&gt;Hi, thank you for the question. Could you please create a demonstration example code (you can use &lt;A href="https://jsbin.com/yewimat/edit" target="_self"&gt;this JS Bin&lt;/A&gt; as a starter if you'd like) and post it here to help us understand your issue? Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 14:41:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/open-source-mapping-libraries-ques/leaflet-removelayer-work-only-once-in-javascript/m-p/1150179#M102</guid>
      <dc:creator>GavinRehkemper</dc:creator>
      <dc:date>2022-03-03T14:41:11Z</dc:date>
    </item>
  </channel>
</rss>

