Clone a FeatureLayer object in Arcgis 3.31 for javascript?

2555
5
Jump to solution
01-31-2020 12:43 PM
Phares_Andrew
New Contributor II

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?

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
LeoLiu1
Occasional Contributor

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.

View solution in original post

5 Replies
RobertScheitlin__GISP
MVP Emeritus

There is no such method on the clinetside JS API. 

LeoLiu1
Occasional Contributor

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)

Phares_Andrew
New Contributor II

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.

0 Kudos
LeoLiu1
Occasional Contributor

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.

Phares_Andrew
New Contributor II

That solved my issue – thank you!

0 Kudos