<?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 Re: map.removeLayer(myLyr) does not work in ArcGIS API for Flex Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-flex-questions/map-removelayer-mylyr-does-not-work/m-p/720022#M16026</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Problem solved,&lt;/P&gt;&lt;P&gt;if (this.map.getLayer (layerID)) this.map.removeLayer (this.map.getLayer (layerID));&lt;/P&gt;&lt;P&gt;where layerID is the given layer.id when the layer is created, e.g., could be the same as lyr.name in your case.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 22 May 2018 13:03:06 GMT</pubDate>
    <dc:creator>FabioPires</dc:creator>
    <dc:date>2018-05-22T13:03:06Z</dc:date>
    <item>
      <title>map.removeLayer(myLyr) does not work</title>
      <link>https://community.esri.com/t5/arcgis-api-for-flex-questions/map-removelayer-mylyr-does-not-work/m-p/720019#M16023</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Scenario description:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Created several checkboxes.&amp;nbsp; If a checkbox is checked, a layer is added, or else, the layer will be removed (see the code below).&amp;nbsp; However, I can't remove the added layer(s).&amp;nbsp; I run debugging, it does go through map.removeLayer(lyr), but the layer I created is still on the map.&amp;nbsp; If you have a better approach or find anything wrong in my code, please help.&amp;nbsp; Thanks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;private function ChkSettings (chk:ImageCheckBox, lyr:GraphicsLayer, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ac:ArrayCollection, lyrName:String ):void {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; if (chk.selected == false) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; lyr.clear();&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; for (var i:Number = 0; i &amp;lt; map.layers.length; i++) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; if (map.layers&lt;I&gt;.name == lyrName) {&lt;/I&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; map.removeLayer(lyr);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; } else {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; lyr = AddGeocodeLayer2(ac);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; lyr.name = lyrName;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; map.addLayer(lyr);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Oct 2010 16:40:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-flex-questions/map-removelayer-mylyr-does-not-work/m-p/720019#M16023</guid>
      <dc:creator>ShaningYu</dc:creator>
      <dc:date>2010-10-25T16:40:21Z</dc:date>
    </item>
    <item>
      <title>Re: map.removeLayer(myLyr) does not work - Problem solved</title>
      <link>https://community.esri.com/t5/arcgis-api-for-flex-questions/map-removelayer-mylyr-does-not-work/m-p/720020#M16024</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Problem solved by change&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;map.removeLayer(lyr);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;to&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;map.removeLayer(map.layers&lt;I&gt;);&lt;/I&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 Oct 2010 18:06:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-flex-questions/map-removelayer-mylyr-does-not-work/m-p/720020#M16024</guid>
      <dc:creator>ShaningYu</dc:creator>
      <dc:date>2010-10-25T18:06:24Z</dc:date>
    </item>
    <item>
      <title>Re: map.removeLayer(myLyr) does not work</title>
      <link>https://community.esri.com/t5/arcgis-api-for-flex-questions/map-removelayer-mylyr-does-not-work/m-p/720021#M16025</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi - I'm having issues with this too - I've tried&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-family:Arial;"&gt;map.removeLayer&lt;/SPAN&gt;&lt;SPAN style="font-family:Arial, Helvetica, sans-serif;"&gt;(map.layers[0]);&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-family:Arial, Helvetica, sans-serif;"&gt;(The layer I want to remove is index 0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-family:Arial, Helvetica, sans-serif;"&gt;This results in[&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-family:Arial, Helvetica, sans-serif;"&gt;CODE]&lt;BR /&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;UL&gt;&lt;BR /&gt;&lt;LI&gt;&lt;SPAN style="color:red !important;"&gt;ncaught TypeError: Cannot read property '0' of undefined &lt;A href="http://emap2_dev/common/basecode.js"&gt;basecode.js:981&lt;/A&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;BR /&gt;&lt;UL&gt;&lt;BR /&gt;&lt;LI&gt;&lt;SPAN style="color:red !important;"&gt;switchBaseMap&lt;/SPAN&gt;&lt;A href="http://emap2_dev/common/basecode.js"&gt;basecode.js:981&lt;/A&gt;&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;&lt;SPAN style="color:red !important;"&gt;onClick&lt;/SPAN&gt;&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;&lt;SPAN style="color:red !important;"&gt;_d66._onClick&lt;/SPAN&gt;&lt;A href="http://emap2/arcgis_js_api/library/3.3/jsapi/init.js"&gt;init.js:34&lt;/A&gt;&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;&lt;SPAN style="color:red !important;"&gt;_2cf&lt;/SPAN&gt;&lt;A href="http://emap2/arcgis_js_api/library/3.3/jsapi/init.js"&gt;init.js:15&lt;/A&gt;&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;&lt;SPAN style="color:red !important;"&gt;_b24._onClick&lt;/SPAN&gt;&lt;A href="http://emap2/arcgis_js_api/library/3.3/jsapi/init.js"&gt;init.js:34&lt;/A&gt;&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;&lt;SPAN style="color:red !important;"&gt;(anonymous function)&lt;/SPAN&gt;&lt;A href="http://emap2/arcgis_js_api/library/3.3/jsapi/init.js"&gt;init.js:15&lt;/A&gt;&lt;/LI&gt;&lt;BR /&gt;&lt;LI&gt;&lt;SPAN style="color:red !important;"&gt;_7bb&lt;/SPAN&gt;&lt;A href="http://emap2/arcgis_js_api/library/3.3/jsapi/init.js"&gt;init.js:34&lt;/A&gt;&lt;/LI&gt;&lt;BR /&gt;&lt;/UL&gt;&lt;/UL&gt;&lt;SPAN style="font-family:Arial, Helvetica, sans-serif;"&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt; map.removeLayer('mainmap');&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family:Arial;"&gt;&lt;BR /&gt;The gives no errors, but doesn't do anything, the layer is still showing if I Look at console.debug(map)&lt;BR /&gt;&lt;BR /&gt;Cheers&lt;BR /&gt;&lt;BR /&gt;ACM&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Apr 2013 08:58:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-flex-questions/map-removelayer-mylyr-does-not-work/m-p/720021#M16025</guid>
      <dc:creator>AdrianMarsden</dc:creator>
      <dc:date>2013-04-22T08:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: map.removeLayer(myLyr) does not work</title>
      <link>https://community.esri.com/t5/arcgis-api-for-flex-questions/map-removelayer-mylyr-does-not-work/m-p/720022#M16026</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Problem solved,&lt;/P&gt;&lt;P&gt;if (this.map.getLayer (layerID)) this.map.removeLayer (this.map.getLayer (layerID));&lt;/P&gt;&lt;P&gt;where layerID is the given layer.id when the layer is created, e.g., could be the same as lyr.name in your case.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 22 May 2018 13:03:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-flex-questions/map-removelayer-mylyr-does-not-work/m-p/720022#M16026</guid>
      <dc:creator>FabioPires</dc:creator>
      <dc:date>2018-05-22T13:03:06Z</dc:date>
    </item>
  </channel>
</rss>

