var editSignSupports = new esri.layers.FeatureLayer("https://myserver/pubgis/rest/services/Signs/Signs2/FeatureServer/1", { id: 'editSignSupports', //always assign the layer id to all layers of all types; never let the api do it mode: esri.layers.FeatureLayer.MODE_ONDEMAND, outFields: ["*"] }); dojo.connect(editSignSupports, 'onEditsComplete', function(result) { var add = result[0]; if (add !== undefined && add.success) { //check to see that add was successful and in fact this was an add and not an update or delete dojo.forEach(editSignSupports.graphics, function(graphic) { //iterate through feature layer graphics if (graphic.attributes.OBJECTID === add.objectId) { graphic.attributes.SOME_OTHER_FIELD = add.objectId; //set your other field with object id editSignSupports.applyEdits(null, [graphic], null, function (response) { //apply edits to object //console.log(response); }, function (error) { //console.log(error) }); return; //stop loop once the only feature with that object id has been updated } }) } });
//create "feature" app.editLayer.applyEdits([feature], null, null, function (response) { console.log('feature added'); feature.attributes.SOME_OTHER_FIELD = response.addResults[0].objectId; app.editLayer.applyEdits(null, [feature], null, function (response) { console.log('feature updated'); }, function (error) { console.log(error) }) }, function (error) { console.log(error) });
var editSignSupports = new esri.layers.FeatureLayer("https://myserver/pubgis/rest/services/Signs/Signs2/FeatureServer/1", { mode: esri.layers.FeatureLayer.MODE_ONDEMAND, outFields: ["*"] }); mapLayers.push(editSignSupports); legendLayers.push({layer:editSignSupports,title:'SignSupport'});
function initEditing(results) { var featureLayerInfos = dojo.map(results, function(result) { return { 'featureLayer': result.layer }; }); editorSettings = { map: map, layerInfos: featureLayerInfos }; //when the editor tab is clicked we'll initialize the editor var showHandler = dojo.connect(dijit.byId('editTab'),'onShow',function(evt){ //disconnect the handler so the editor is only initialized once dojo.disconnect(showHandler); var params = { settings: editorSettings }; var editorWidget = new esri.dijit.editing.Editor(params, 'editorDiv'); editorWidget.startup(); }); }
The callback on applyEdits returns the objectId of the new feature.In the add feature callback function update the attribute and send it back for an update.//create "feature" app.editLayer.applyEdits([feature], null, null, function (response) { console.log('feature added'); feature.attributes.SOME_OTHER_FIELD = response.addResults[0].objectId; app.editLayer.applyEdits(null, [feature], null, function (response) { console.log('feature updated'); }, function (error) { console.log(error) }) }, function (error) { console.log(error) });
Thanks! This helped me out a lot with a project I am working on!
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.