copy feature

394
3
06-22-2021 09:19 AM
JayakumarKamalakannan
New Contributor

Hi All,

I have couple of layers one is "master" layer another one is "temporary" layer. Both layer have same fields.

User will create new feature in "temporary" layer , once approved the specific feature need to move to "master" layer. 

I need know the how to copy the feature from temporary layer to master layer.

Please help me if someone have idea.

Thanks in advance.

Tags (1)
0 Kudos
3 Replies
ReneRubalcava
Frequent Contributor II

I did something like in this blog post.

Here is a codepen.

It's something like this.

function copyLayer(lyr, title) {
    const tempLayer = new FeatureLayer({
        title,
        fields: lyr.fields.map(x => x.clone()),
        geometryType: lyr.geometryType,
        renderer: lyr.renderer.clone(),
        spatialReference: lyr.spatialReference.clone(),
        source: [],
        visible: false
    });
    return tempLayer;
}

// later, might need a where: 1=1 query
const { features } = await soureLayer.queryFeatures();
const result = await localLayer.applyEdits({
    addFeatures: features
})
.catch(err => console.log(error));
localLayer.refresh();
0 Kudos
JayakumarKamalakannan
New Contributor

Hi,

Thanks for the reply. Sample code seems to be copy entire feature from temp layer to master layer. I need to copy only few features not entire feature. Kindly let me know how to do it?

0 Kudos
ReneRubalcava
Frequent Contributor II

Change the query used for queryFeatures to only fetch the features you are interested in.

https://developers.arcgis.com/javascript/latest/api-reference/esri-tasks-support-Query.html