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?
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!
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.
Not sure the reason you want to copy a feature layer, you can try it in the JavaScript way:
<SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;">var copiedFeatureLayer = JSON</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;">parse</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;">(</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;">JSON</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;">.</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;">stringify</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;">(</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;">objFeatureLayer</SPAN><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;">))</SPAN>
or
<SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;">copiedFeatureLayer = Object.assign({}, objFeatureLayer)</SPAN><CODE style="background-color: #eff0f1; border: 0px; font-weight: inherit;"><SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;">var </SPAN>
<SPAN class="" style="color: #303336; border: 0px; font-weight: inherit; font-size: 13px;">copiedFeatureLayer = Object.assign({}, objFeatureLayer)</SPAN>
<SPAN class="" style="color: #0077aa; border: 0px;"></SPAN>
There is no such method on the clinetside JS API.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.