<?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 Get feature count of an empty FeatureLayer and applyEdits in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-feature-count-of-an-empty-featurelayer-and/m-p/1134935#M75982</link>
    <description>&lt;P&gt;How can I add the queryFeatureCount function to a feature layer whose source is not set and will later be set? The next time this function is called again, it will have some features to delete.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The feature layer is initialized as&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;polygonsFeatureLayer = new FeatureLayer({
title: "test",
objectIdField: "OBJECTID",
source: [],
renderer: {
type: "simple", // autocasts as new SimpleFillSymbol()
symbol: {
type: "simple-fill", // autocasts as new SimpleFillSymbol()
color: [255, 0, 0, 0.5],
outline: { // autocasts as new SimpleLineSymbol()
color: [255, 255, 0],
width: 3
}
}
} as any
});&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;In another function, I am trying to add new features to the same layer, but I need to delete the old features if there are any in the layer, so I am running the following code to do so&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;this.polygonsFeatureLayer.queryFeatures().then((results) =&amp;gt; {
console.log(results);
const deleteEdits = {
deleteFeatures: results.features
};
// apply edits to the layer
this.polygonsFeatureLayer.applyEdits(deleteEdits).then((results) =&amp;gt; {
console.log(results);
// if edits were removed
if (results.deleteFeatureResults.length &amp;gt; 0) {
console.log(
results.deleteFeatureResults.length,
"features have been removed"
);
}
});
});&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Then when the new features are received and collected. I am running the addFeatures to add new items to the existing feature layer.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const addEdits = {
addFeatures: results.features
};
this.polygonsFeatureLayer.applyEdits(addEdits).then((results) =&amp;gt; {
console.log(results);
// if edits were removed
if (results.addFeatureResults.length &amp;gt; 0) {
console.log(
results.addFeatureResults.length,
"features have been added"
);
}
});

map.add(this.polygonsFeatureLayer);&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;But I am getting the following errors,&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;[esri.views.2d.layers.FeatureLayerView2D] #resolve() Failed to resolve layer view (layer title: 'test', id: '17e720aea79-layer-28') o&amp;nbsp;{name: 'featurelayerview:table-not-supported', details: {…}, message: "table feature layer can't be displayed"}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;Logger.js:5 [esri.views.LayerViewManager] Failed to create layerview for layer title:'test', id:'17e720aea79-layer-28' of type 'feature'. {layer: a, error: o}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR Error: Uncaught (in promise): [featurelayerview:table-not-supported]: table feature layer can't be displayed&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;What am I missing here?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 19 Jan 2022 13:00:51 GMT</pubDate>
    <dc:creator>arahman_mdmajid</dc:creator>
    <dc:date>2022-01-19T13:00:51Z</dc:date>
    <item>
      <title>Get feature count of an empty FeatureLayer and applyEdits</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-feature-count-of-an-empty-featurelayer-and/m-p/1134935#M75982</link>
      <description>&lt;P&gt;How can I add the queryFeatureCount function to a feature layer whose source is not set and will later be set? The next time this function is called again, it will have some features to delete.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The feature layer is initialized as&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;polygonsFeatureLayer = new FeatureLayer({
title: "test",
objectIdField: "OBJECTID",
source: [],
renderer: {
type: "simple", // autocasts as new SimpleFillSymbol()
symbol: {
type: "simple-fill", // autocasts as new SimpleFillSymbol()
color: [255, 0, 0, 0.5],
outline: { // autocasts as new SimpleLineSymbol()
color: [255, 255, 0],
width: 3
}
}
} as any
});&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;In another function, I am trying to add new features to the same layer, but I need to delete the old features if there are any in the layer, so I am running the following code to do so&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;this.polygonsFeatureLayer.queryFeatures().then((results) =&amp;gt; {
console.log(results);
const deleteEdits = {
deleteFeatures: results.features
};
// apply edits to the layer
this.polygonsFeatureLayer.applyEdits(deleteEdits).then((results) =&amp;gt; {
console.log(results);
// if edits were removed
if (results.deleteFeatureResults.length &amp;gt; 0) {
console.log(
results.deleteFeatureResults.length,
"features have been removed"
);
}
});
});&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Then when the new features are received and collected. I am running the addFeatures to add new items to the existing feature layer.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const addEdits = {
addFeatures: results.features
};
this.polygonsFeatureLayer.applyEdits(addEdits).then((results) =&amp;gt; {
console.log(results);
// if edits were removed
if (results.addFeatureResults.length &amp;gt; 0) {
console.log(
results.addFeatureResults.length,
"features have been added"
);
}
});

map.add(this.polygonsFeatureLayer);&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;But I am getting the following errors,&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;[esri.views.2d.layers.FeatureLayerView2D] #resolve() Failed to resolve layer view (layer title: 'test', id: '17e720aea79-layer-28') o&amp;nbsp;{name: 'featurelayerview:table-not-supported', details: {…}, message: "table feature layer can't be displayed"}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;Logger.js:5 [esri.views.LayerViewManager] Failed to create layerview for layer title:'test', id:'17e720aea79-layer-28' of type 'feature'. {layer: a, error: o}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR Error: Uncaught (in promise): [featurelayerview:table-not-supported]: table feature layer can't be displayed&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;What am I missing here?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jan 2022 13:00:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-feature-count-of-an-empty-featurelayer-and/m-p/1134935#M75982</guid>
      <dc:creator>arahman_mdmajid</dc:creator>
      <dc:date>2022-01-19T13:00:51Z</dc:date>
    </item>
    <item>
      <title>Re: Get feature count of an empty FeatureLayer and applyEdits</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-feature-count-of-an-empty-featurelayer-and/m-p/1134965#M75986</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I modified an existing sample to remove all features before new features are added. Essentially, you have to wait until existing features are deleted before new ones are added.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Test app:&amp;nbsp;&lt;A href="https://codepen.io/U_B_U/pen/PoJvbab?editors=1000" target="_blank"&gt;https://codepen.io/U_B_U/pen/PoJvbab?editors=1000&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Take a look at the addFeatures function.&lt;/P&gt;&lt;P&gt;Hope this helps,&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jan 2022 15:20:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-feature-count-of-an-empty-featurelayer-and/m-p/1134965#M75986</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2022-01-19T15:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Get feature count of an empty FeatureLayer and applyEdits</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-feature-count-of-an-empty-featurelayer-and/m-p/1135333#M76010</link>
      <description>&lt;P&gt;I was able to get the feature count on an empty featureLayer as per your code. And I was also able to add the feature to the feature layer using addFeatures.&lt;/P&gt;&lt;P&gt;But when I add the layer to the map, it still gives me the following error.&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;[esri.views.2d.layers.FeatureLayerView2D] #resolve() Failed to resolve layer view (layer title: 'test', id: '17e720aea79-layer-28') o&amp;nbsp;{name: 'featurelayerview:table-not-supported', details: {…}, message: "table feature layer can't be displayed"}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;Logger.js:5 [esri.views.LayerViewManager] Failed to create layerview for layer title:'test', id:'17e720aea79-layer-28' of type 'feature'. {layer: a, error: o}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR Error: Uncaught (in promise): [featurelayerview:table-not-supported]: table feature layer can't be displayed&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;I am adding doing a console.log of the features added to the addFeatures method, and it shows like this.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="features snap.PNG" style="width: 694px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/31863iD41533D60FC5496F/image-size/large?v=v2&amp;amp;px=999" role="button" title="features snap.PNG" alt="features snap.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The feature after shows as&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="feature added.PNG" style="width: 523px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/31864i26526D1B4ACB28EE/image-size/large?v=v2&amp;amp;px=999" role="button" title="feature added.PNG" alt="feature added.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;But when the same featureLayer is added to the map afterward, it gives the errors&lt;/P&gt;&lt;P&gt;Thanks for the help.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2022 07:50:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-feature-count-of-an-empty-featurelayer-and/m-p/1135333#M76010</guid>
      <dc:creator>arahman_mdmajid</dc:creator>
      <dc:date>2022-01-20T07:50:26Z</dc:date>
    </item>
    <item>
      <title>Re: Get feature count of an empty FeatureLayer and applyEdits</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-feature-count-of-an-empty-featurelayer-and/m-p/1135484#M76019</link>
      <description>&lt;P&gt;The error indicates that FeatureLayer you creating is a non-spatial FeatureLayer. Meaning that graphics you are adding to the FeatureLayer does not have geometry, just attributes. Is this what you are adding? If you are then you cannot add non-spatial FeatureLayer to the map. &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#creating-a-featurelayer" target="_self"&gt;Creating a FeatureLayer&lt;/A&gt; doc explains how non-spatial FeatureLayers can be used. See under Read more.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you are creating spatial FeatureLayer then several things to check.&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. You can only add graphics with same geometry types.&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. Are you graphic geometries valid?&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. You should set the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#geometryType" target="_self"&gt;FeatureLayer.geometryType&lt;/A&gt; in the layer's constructor. &amp;nbsp;The &lt;A href="https://codepen.io/U_B_U/pen/PoJvbab?editors=1000" target="_self"&gt;codepen app&lt;/A&gt; sets the params required to initialize FeatureLayer. If you don't then the API will try to infer required parameters from the graphics you pass in and will fail if it cannot infer the params.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2022 16:29:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-feature-count-of-an-empty-featurelayer-and/m-p/1135484#M76019</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2022-01-20T16:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: Get feature count of an empty FeatureLayer and applyEdits</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-feature-count-of-an-empty-featurelayer-and/m-p/1136316#M76044</link>
      <description>&lt;P&gt;Yes, thank you for mentioning the third point.&lt;/P&gt;&lt;BLOCKQUOTE&gt;3. You should set the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#geometryType" target="_self"&gt;FeatureLayer.geometryType&lt;/A&gt; in the layer's constructor. &amp;nbsp;The &lt;A href="https://codepen.io/U_B_U/pen/PoJvbab?editors=1000" target="_self"&gt;codepen app&lt;/A&gt; sets the params required to initialize FeatureLayer. If you don't then the API will try to infer required parameters from the graphics you pass in and will fail if it cannot infer the params.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This point helped me and solved the issue, so now my initialization of the featureLayer looks like this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;  polygonsFeatureLayer = new FeatureLayer({
    title: "test",
    objectIdField: "OBJECTID",
    geometryType: "polygon",
    source: [],
    renderer: {
      type: "simple",  // autocasts as new SimpleFillSymbol()
      symbol: {
        type: "simple-fill",  // autocasts as new SimpleFillSymbol()
        color: [255, 0, 0, 0.5],
        outline: {  // autocasts as new SimpleLineSymbol()
          color: [255, 255, 0],
          width: 3
        }
      }
    } as any
  });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As for the previous two points&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;1. You can only add graphics with same geometry types.&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I made sure that it was only storing polygon type features.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;SPAN&gt;2. Are you graphic geometries valid?&amp;nbsp;&lt;/SPAN&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I was convinced that the features were valid since I added and showed them using a&amp;nbsp;&lt;SPAN&gt;GraphicsLayer.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 11:07:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/get-feature-count-of-an-empty-featurelayer-and/m-p/1136316#M76044</guid>
      <dc:creator>arahman_mdmajid</dc:creator>
      <dc:date>2022-01-24T11:07:38Z</dc:date>
    </item>
  </channel>
</rss>

