<?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: Creating a Collection of FeatureLayerViews in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/creating-a-collection-of-featurelayerviews/m-p/1168019#M77145</link>
    <description>&lt;P&gt;You don't need a typed Collection&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Collection.ofType(FeatureLayerView)&lt;/LI-CODE&gt;&lt;P&gt;When you do this, the Collection will try to initialize the added object as a new FeatureLayerView() and that doesn't work because it's already a class.&lt;/P&gt;&lt;P&gt;If this is for TypeScript, you can do this.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const featureLayersViews = new Collection&amp;lt;FeatureLayerView&amp;gt;();&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 26 Apr 2022 17:48:52 GMT</pubDate>
    <dc:creator>ReneRubalcava</dc:creator>
    <dc:date>2022-04-26T17:48:52Z</dc:date>
    <item>
      <title>Creating a Collection of FeatureLayerViews</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/creating-a-collection-of-featurelayerviews/m-p/1168007#M77144</link>
      <description>&lt;P&gt;Hi Esri Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P data-unlink="true"&gt;I'm trying to build a &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-core-Collection.html" target="_self"&gt;Collection&lt;/A&gt; of &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-layers-FeatureLayerView.html" target="_self"&gt;FeatureLayerViews&amp;nbsp;&lt;/A&gt; but I am getting a "W is not a function" when I execute&amp;nbsp; try to .add(layerView)&lt;/P&gt;&lt;P data-unlink="true"&gt;Any suggestion would be greatly appreciated.&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://codepen.io/mjnesius/pen/RwxvgVL?editors=1001" target="_self"&gt;Codepen&lt;/A&gt; reproducing my error (code shown below)&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;require(["esri/Map", "esri/views/MapView", "esri/layers/FeatureLayer", "esri/views/layers/FeatureLayerView","esri/core/Collection"], 
        function(Map, MapView, FeatureLayer, FeatureLayerView, Collection) {
        const map = new Map({
          basemap: "dark-gray-vector"
        });

        const view = new MapView({
          container: "sceneDiv",
          map: map,
          center: [-73.95, 40.702],
          zoom: 12,
          padding: {
            right: 300
          }
        });

        /********************
         * Add feature layers
         ********************/

        // Create the FeatureLayers
        const FLUrls =[
            {url:"https://sampleserver6.arcgisonline.com/arcgis/rest/services/EmergencyFacilities/FeatureServer/0", title: "Facilities", id: "Facilities"},
            {url:"https://sampleserver6.arcgisonline.com/arcgis/rest/services/LocalGovernment/WaterValveInspections/FeatureServer/0", title: "Water", id: "Water"},
            {url:"https://sampleserver6.arcgisonline.com/arcgis/rest/services/LocalGovernment/SewerManholeInspections/FeatureServer/0", title: "Sewer", id: "Sewer"}
        ]
        const FLs = FLUrls.map( (x) =&amp;gt; (
            new FeatureLayer({
                url:  x.url,
                title: x.title,
                id: x.id,
                visible: false
            } )
        ));
        const show = (...a) =&amp;gt; console.log(...a);
        const layerTitles = a =&amp;gt; show(a.title);
        const layerIDs = a =&amp;gt; show(a.id);
        const layerViews = a =&amp;gt; {
          console.log("feature layer view a:  " + a.title)
          view.whenLayerView(a)
            .then( layerView =&amp;gt; {
              console.log("when layer view:  " + layerView.layer.title)
              try{
                featureLayersViews.add(layerView);
                // Not sure why add() is throwing "W is not a function"
              } catch(e) {
                console.error("\t" + e.message)
              }
            })
          .catch(err =&amp;gt; {
            console.log("error with feature layer view: " )//+ layerView.layer.title)
            console.error(err)
          })
        };
        const addLayerResults = results =&amp;gt; {
            // Add the FeatureLayers to the map
            map.addMany(results)
            //console log the titles of the layers
            results.map(layerTitles)
            // pass the layers to a whenLayerView function that adds them to the view Collection
            results.map(layerViews)
        }
        
        //collection of FeatureLayers
        let FeatureLayerCollection = Collection.ofType(FeatureLayer);
        const featureLayers = new FeatureLayerCollection();
        
        //collection of FeatureLayersViews
        let FeatureLayerViewCollection = Collection.ofType(FeatureLayerView);
        const featureLayersViews = new FeatureLayerViewCollection();
  
        featureLayersViews.on("after-add", event =&amp;gt; {
            console.log(`${event.item.title} was added to featureLayersViews collection`);
        })
  
        featureLayers.on("after-add", event =&amp;gt; {
            console.log(`${event.item.title} was added to featureLayers collection`);
        })
  
        featureLayers.addMany(FLs);
        view.when( function () {
          console.log("View loaded ");
          Promise.all(featureLayers.map(a =&amp;gt; a.load()).toArray())
                    .then(addLayerResults)
                    .catch(show)
         }
        )
     })&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 26 Apr 2022 17:24:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/creating-a-collection-of-featurelayerviews/m-p/1168007#M77144</guid>
      <dc:creator>MichaelNesius1</dc:creator>
      <dc:date>2022-04-26T17:24:26Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a Collection of FeatureLayerViews</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/creating-a-collection-of-featurelayerviews/m-p/1168019#M77145</link>
      <description>&lt;P&gt;You don't need a typed Collection&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Collection.ofType(FeatureLayerView)&lt;/LI-CODE&gt;&lt;P&gt;When you do this, the Collection will try to initialize the added object as a new FeatureLayerView() and that doesn't work because it's already a class.&lt;/P&gt;&lt;P&gt;If this is for TypeScript, you can do this.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const featureLayersViews = new Collection&amp;lt;FeatureLayerView&amp;gt;();&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 26 Apr 2022 17:48:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/creating-a-collection-of-featurelayerviews/m-p/1168019#M77145</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2022-04-26T17:48:52Z</dc:date>
    </item>
  </channel>
</rss>

