I have two feature layers layer1 & layer2. I want to copy a feature from layer1 to layer2 and chnage its attributes as per layer2. I had already created a graphic from layer1 and how can i copy this to layer2 please ???
Solved. The problem was i was not using proxy.
Hi Grish..
I tried to as you said the following way, there is no error but it simple does not work meaning the feature is not saved in the Geodatabase. Can you please check...
for (var i = 0; i < results.features.length; i++) {
//Create the graphic for the parcels
var graphic = results.features;
graphic.setSymbol(symbol);
app.map.graphics.add(graphic);
app.map.setExtent(graphic.geometry.getExtent().expand(2));
var schAttrib = " " + graphic.attributes.PIN;
var schTextSymbol = new esri.symbol.TextSymbol(schAttrib);
schTextSymbol.setColor(new dojo.Color([255, 0, 0]));
var schFont = new esri.symbol.Font("9pt",
esri.symbol.Font.STYLE_NORMAL,
esri.symbol.Font.VARIANT_NORMAL,
esri.symbol.Font.WEIGHT_BOLD, "Arial");
//text symbol for the PIN
schTextSymbol.setAlign(esri.symbol.TextSymbol.ALIGN_MIDDLE);
schTextSymbol.setFont(schFont);
var pt = graphic.geometry.getExtent().getCenter();
var gra = new esri.Graphic(pt, schTextSymbol);
app.map.graphics.add(gra);
app.map.removeLayer(cadastrePlotLayer);
var newFeature = new esri.Graphic(graphic.toJson());
ladpTempLayer.applyEdits([newFeature], null, null)
}
Thank you Girish Yadav
Oh yes i passing the graphic object directly to ApplyEdits .
I will try the JSON thing and come back.
cadgis m,
Are you passing the graphic object directly to ApplyEdits? I guess that would cause it not to save because If you directly fetch feature out from FeatureLayer then it has few properties that are referenced to its parent feature layer.
Try to get the JSON from the graphic and create a new Graphic using that JSON and save this new graphic to Layer2.
var newFeature = new Graphic(graphic.toJson());
featureLayer.applyEdits([newFeature], null, null)
you can also update the attributes of the newFeature before applying edits.
-Girish
Thank you Robert Scheitlin..
Yes, Layer2 is published as Featureservice. What I am trying to do is select the feature from Layer1 as graphic, and trying to do ApplyEdit (graphic to Layer2) is this the right way? But it fails. I meanLayer2 is not updated in the Geodatabase.
cadgis,
Is Layer2 a FeatureService? You can only edit features using a FeatureService (i.e. FeatureServer instead of MapServer in the url). If it is then you can use applyEdits
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.