<?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: API 4: Add all layers from a feature service to map in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/api-4-add-all-layers-from-a-feature-service-to-map/m-p/1071439#M73595</link>
    <description>&lt;P&gt;I figured out that this is possible to get the number of layers using the REST api and then add each layer individually. Please let me know in case there is a more direct way to achieve this.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// get number of layers in service
    let url = "...?f=pjson"; // Feature Service url from portal page
    esriRequest(url, {
      responseType: "json"
    }).then(function(response){
      let responseJSON = response.data;
      let numberOfLayers = responseJSON.layers.length;
      // load each service layer
      for (let i = 0; i &amp;lt; numberOfLayers; i++) {
        layer = new FeatureLayer({
          portalItem: {
            id: "..."
          },
          layerId: i
        });
        map.add(layer);
      }
    });&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 23 Jun 2021 13:07:01 GMT</pubDate>
    <dc:creator>LukasWürsch</dc:creator>
    <dc:date>2021-06-23T13:07:01Z</dc:date>
    <item>
      <title>API 4: Add all layers from a feature service to map</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/api-4-add-all-layers-from-a-feature-service-to-map/m-p/1070983#M73581</link>
      <description>&lt;P&gt;Hello there&lt;/P&gt;&lt;P&gt;I want to load all layers of a Hosted Feature service using the JS Api 4. It is possible to add a single layer to the map like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;layer = new FeatureLayer({
      portalItem: {
        id: portalItemId
      }
      layerId: 0
    });

map.add(layer);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to list, or count all layers within a Hosted Feature Service (using JS API 4), so each of them could be added using new FeatureLayer?&lt;/P&gt;&lt;P&gt;Or is there a direct way to add all layers of a Hosted Feature Service to the map?&lt;/P&gt;&lt;P&gt;Kind Regards&lt;/P&gt;&lt;P&gt;Lukas&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 14:51:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/api-4-add-all-layers-from-a-feature-service-to-map/m-p/1070983#M73581</guid>
      <dc:creator>LukasWürsch</dc:creator>
      <dc:date>2021-06-22T14:51:54Z</dc:date>
    </item>
    <item>
      <title>Re: API 4: Add all layers from a feature service to map</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/api-4-add-all-layers-from-a-feature-service-to-map/m-p/1071439#M73595</link>
      <description>&lt;P&gt;I figured out that this is possible to get the number of layers using the REST api and then add each layer individually. Please let me know in case there is a more direct way to achieve this.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// get number of layers in service
    let url = "...?f=pjson"; // Feature Service url from portal page
    esriRequest(url, {
      responseType: "json"
    }).then(function(response){
      let responseJSON = response.data;
      let numberOfLayers = responseJSON.layers.length;
      // load each service layer
      for (let i = 0; i &amp;lt; numberOfLayers; i++) {
        layer = new FeatureLayer({
          portalItem: {
            id: "..."
          },
          layerId: i
        });
        map.add(layer);
      }
    });&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 23 Jun 2021 13:07:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/api-4-add-all-layers-from-a-feature-service-to-map/m-p/1071439#M73595</guid>
      <dc:creator>LukasWürsch</dc:creator>
      <dc:date>2021-06-23T13:07:01Z</dc:date>
    </item>
  </channel>
</rss>

