<?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: Calling map.allLayers removes all layers. in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/calling-map-alllayers-removes-all-layers/m-p/150648#M14036</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah ha! The smoking gun. I've since moved away from this style of implementation, since the return was simply not worth the trouble it caused. Thanks for solving the mystery though!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 28 Oct 2017 19:26:38 GMT</pubDate>
    <dc:creator>TristanSebens</dc:creator>
    <dc:date>2017-10-28T19:26:38Z</dc:date>
    <item>
      <title>Calling map.allLayers removes all layers.</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/calling-map-alllayers-removes-all-layers/m-p/150645#M14033</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've run into an interesting quirk in my code and I'm trying to track down the source of it. In my application I have about 40 layers, any combination of which can be displayed at one time as 3d polylines. What I want to do is implement a legend widget by adding all of the layers to a group layer, and then using that group layer as the basis for my legend widget.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's my function to accomplish that:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;function createLegend() { &lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;var legend = new Legend({&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;view: view,&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;layerInfos: [{&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;layer: new GroupLayer({&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;layers: map.allLayers;&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}),&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;title: "Layer Legend"&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}]&lt;BR /&gt; });&lt;/P&gt;&lt;P&gt;// Add widget to the bottom left corner of the view&lt;BR /&gt; view.ui.add(legend, "bottom-left");&lt;BR /&gt; }&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The interesting thing is this: as soon as I call map.allLayers, all of the layers disappear from the map. I have a layer list in the app, and it goes from full to empty instantaneously once the call is made. I even set a time delay on the function call: all of the layers remain in the map until map.allLayers gets called.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I put in a console.log( map ) statement before and after map.allLayers gets called, and sure enough the layers are there before the call, and gone after.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm wondering if anyone else has faced this kind of thing, and what I might do about it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Oct 2017 19:44:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/calling-map-alllayers-removes-all-layers/m-p/150645#M14033</guid>
      <dc:creator>TristanSebens</dc:creator>
      <dc:date>2017-10-05T19:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: Calling map.allLayers removes all layers.</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/calling-map-alllayers-removes-all-layers/m-p/150646#M14034</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Off the top of my head, you might try using map.layers as opposed to map.allLayers. &amp;nbsp;The main difference between those two is that map.allLayers includes the basemap layers.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In general though, it's not obvious to me that your method would work. &amp;nbsp;You aren't adding the group layer to the map, and the legend widget only shows up for layers that are in the current view. &amp;nbsp;Also, I'm not sure if the legend widget can handle group layers at all.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think, unfortunately, you might just be stuck having a legend that with layers infos that look like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;function&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;createLegend&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt; 
&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; infos &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; map&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;layers&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;map&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;lyr &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt;&lt;SPAN class="operator token"&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; lyr&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; title&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;title
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp; &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;toArray&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;

&amp;nbsp;&amp;nbsp; &lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; legend &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;new&lt;/SPAN&gt; &lt;SPAN class="token class-name"&gt;Legend&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; view&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; view&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layerInfos&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; infos
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="comment token"&gt;// Add widget to the bottom left corner of the view&lt;/SPAN&gt;
view&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ui&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;add&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;legend&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"bottom-left"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 08:07:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/calling-map-alllayers-removes-all-layers/m-p/150646#M14034</guid>
      <dc:creator>ThomasSolow</dc:creator>
      <dc:date>2021-12-11T08:07:04Z</dc:date>
    </item>
    <item>
      <title>Re: Calling map.allLayers removes all layers.</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/calling-map-alllayers-removes-all-layers/m-p/150647#M14035</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tristan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;The docs say this:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;A&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-Layer.html" style="color: #0079c1; background-color: #f8f8f8; text-decoration: none;"&gt;layer&lt;/A&gt;&amp;nbsp;may only be added to one parent. Adding the same layer to multiple&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-Map.html" style="color: #0079c1; background-color: #f8f8f8; text-decoration: none;"&gt;Maps&lt;/A&gt;&lt;SPAN style="color: #4c4c4c; background-color: #f8f8f8;"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;or&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-GroupLayer.html" style="color: #0079c1; background-color: #f8f8f8; text-decoration: none;"&gt;GroupLayers&lt;/A&gt;&amp;nbsp;is not possible. If you attempt to do so, the layer will automatically be removed from its current parent and placed in the new parent.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;So when adding then to the group layer you are removing them from the map and adding them only to the legend. I would think that you some how have to duplicate the layers before you add them to the GroupLayer and then the Legend.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Oct 2017 20:00:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/calling-map-alllayers-removes-all-layers/m-p/150647#M14035</guid>
      <dc:creator>RobertScheitlin__GISP</dc:creator>
      <dc:date>2017-10-05T20:00:35Z</dc:date>
    </item>
    <item>
      <title>Re: Calling map.allLayers removes all layers.</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/calling-map-alllayers-removes-all-layers/m-p/150648#M14036</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ah ha! The smoking gun. I've since moved away from this style of implementation, since the return was simply not worth the trouble it caused. Thanks for solving the mystery though!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 28 Oct 2017 19:26:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/calling-map-alllayers-removes-all-layers/m-p/150648#M14036</guid>
      <dc:creator>TristanSebens</dc:creator>
      <dc:date>2017-10-28T19:26:38Z</dc:date>
    </item>
  </channel>
</rss>

