Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

How do I delete a selected feature from database when it is clicked on in the ArcGIS API for javascript?

share|improve this question
    
mil gracias por la colaboración, excelente ejemplo. Saludos --- Translation (via Google Translate) thanks for the collaboration, excellent example. regards –  user18510 May 25 '13 at 14:40
add comment

2 Answers

Do you mean 'feature' instead of 'feature class'? If so, the default editing widget for the javascript api handles deleting features. Here is a link to the Esri sample: http://help.arcgis.com/en/webapi/javascript/arcgis/jssamples/#sample/ed_default_editingwidget

share|improve this answer
    
YES i use already editing widget but i don't able to capture the function of delete in button delete to check if map have graphic or not –  eman Feb 22 '13 at 19:07
add comment

I don't understand exactly what you're asking, but if you want to handle the delete manually and check whether a graphic is actually selected before trying to delete, you could do something like this:

var myFeatureLayer = new esri.layers.FeatureLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Petroleum/KGS_OilGasFields_Kansas/MapServer/0",{
    mode: esri.layers.FeatureLayer.MODE_SELECTION,
    outFields: ["*"]
});

//get the selected graphic from the feature layer, only gets the first graphic, [0]
var targetGraphic = myFeatureLayer .getSelectedFeatures()[0];
//check if there is a selected graphic
if (targetGraphic) {
    //Delete subblock feature
    myFeatureLayer.applyEdits(null, null, [targetGraphic], function (adds, updates, deletes) {
        dojo.byId('infoPane').innerHTML = "Deleted feature successfully, OBJECTID: " + deletes[0].objectId;
        //operationalLayer.refresh();
    }, dojo.byId('infoPane').innerHTML = "Error when deleting feature");
}
share|improve this answer
    
this function can delete feature layer from geo database . can me ask what is subblockEditFeatureLayer mean –  eman Feb 22 '13 at 20:45
    
Just a name for the feature layer-- you could call it myFeatureLayer. See edit above.. –  awesomo Feb 22 '13 at 20:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.