Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a featureLayer and I don't want to kill it and create another one. I want to delete all features from the current featureLayer. I found that I can use applyEdits method but in order to use it I need to have all features I want to delete. Whilst I don't want to store them separately. Do you know a better way to empty my featureLayer when using the ArcGIS Javascript API?

share|improve this question
up vote 3 down vote accepted

Use featureLayer.selectFeatures() with, as Kirk suggested, a where clause that will return all your features. Once you have all your features, pass them to applyEdits() as the deletes.

share|improve this answer
Won't this return a lot of features to the client? If this is a large dataset it could really be slow. – Kirk Kuykendall Jun 17 '11 at 16:37
The only problem is I can't specify the right where clause - I tried "1 = 1", "OBJECTID > 0", etc. But every time I have an error "FeatureLayer::selectFeatures - query contains one or more unsupported parameters". The code var query = new esri.tasks.Query(); query.where = "1 = 1"; featureLayer.selectFeatures(query, ...); – Kirill Lykov Jun 20 '11 at 5:46
Perhaps, if featurelayer is not connected with any feature service, it doen't support where clauses. What do you think? – Kirill Lykov Jun 20 '11 at 5:57
"if featurelayer is not connected with any feature service, it doen't support where clauses" - that's correct, but if so it also wouldn't support editing. From the API reference: "If the underlying layer ... is from a Feature Service, its features can be edited", implying that your featureLayer IS connected to a feature service – Stephen Lead Jun 21 '11 at 2:35
"it also wouldn't support editing" - I support editing even if it is not connected with service. Hovewer, I had to make some workarounds. – Kirill Lykov Jun 21 '11 at 10:44

Try making a REST delete features call with a where clause "1 = 1" or something similar.

share|improve this answer
hi is there any syntax to the REST delete features call? could you provide me an example as I am attempting to do that – jonleech Jan 10 '13 at 2:57

Check out the clear() method:

Clears all graphics.

share|improve this answer

If you have created the feature layer on the client side (no server side url), then you cannot use a query with a where clause. I was able to work around this by searching the extent of the map and then deleting all the items that I found. For example:

function removeAllLayerFeatures(map, layer) {
    require(['esri/tasks/query', 'esri/layers/FeatureLayer'], function (Query, FeatureLayer) {
        var query = new Query();
        query.geometry = map.extent;
        layer.selectFeatures(query, FeatureLayer.SELECTION_NEW, function (results) {
            for (var key in results) {
share|improve this answer

Use an Update Cursor, selecting all features ("*").

Use IFeature.Delete(), and store when done.

share|improve this answer
This question is asking for a JavaScript solution, not ArcObjects. – Derek Swingley Jun 17 '11 at 16:21 mistake! Please ignore. – ujjwalesri Jun 20 '11 at 11:59

Your Answer


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.