The java api has a method to copy a FeatureLayer: FeatureLayer (ArcGIS Runtime SDK for Java 100.7.0) , but I can't find a similar method here: FeatureLayer (legacy) | API Reference | ArcGIS API for JavaScript 3.31 . How do I clone a FeatureLayer in Arcgis 3.31 for javascript?
Solved! Go to Solution.
Hi Andrew,
Can you share a piece of your codes? Wondering you probably just need to keep a copy of the selected features. It's an array of Graphics.
Leo.
There is no such method on the clinetside JS API.
Not sure the reason you want to copy a feature layer, you can try it in the JavaScript way:
var copiedFeatureLayer = JSON.parse(JSON.stringify(objFeatureLayer))
or
var
copiedFeatureLayer = Object.assign({}, objFeatureLayer)
I've tried cloning via the last method, but this.inherited(arguments) is undefined for the feature layer (and I'm not sure what I need to add to the copied feature layer to avoid this).
The reason I'm is that whenever I call 'featureLayer.clearSelection' or make a new selection on the layer with selectFeatures, the layer deletes the selected objects (instead of just clearing the selection). My solution to this was to try and restore a cloned copy of the layer after every new selection / clear.
Hi Andrew,
Can you share a piece of your codes? Wondering you probably just need to keep a copy of the selected features. It's an array of Graphics.
Leo.
That solved my issue – thank you!