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.
The feature layer is initialized as
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
});
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
this.polygonsFeatureLayer.queryFeatures().then((results) => {
console.log(results);
const deleteEdits = {
deleteFeatures: results.features
};
// apply edits to the layer
this.polygonsFeatureLayer.applyEdits(deleteEdits).then((results) => {
console.log(results);
// if edits were removed
if (results.deleteFeatureResults.length > 0) {
console.log(
results.deleteFeatureResults.length,
"features have been removed"
);
}
});
});
Then when the new features are received and collected. I am running the addFeatures to add new items to the existing feature layer.
const addEdits = {
addFeatures: results.features
};
this.polygonsFeatureLayer.applyEdits(addEdits).then((results) => {
console.log(results);
// if edits were removed
if (results.addFeatureResults.length > 0) {
console.log(
results.addFeatureResults.length,
"features have been added"
);
}
});
map.add(this.polygonsFeatureLayer);
But I am getting the following errors,
[esri.views.2d.layers.FeatureLayerView2D] #resolve() Failed to resolve layer view (layer title: 'test', id: '17e720aea79-layer-28') o {name: 'featurelayerview:table-not-supported', details: {…}, message: "table feature layer can't be displayed"}
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}
ERROR Error: Uncaught (in promise): [featurelayerview:table-not-supported]: table feature layer can't be displayed
What am I missing here?