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?


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.

| 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
  • 2
    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.

| improve this answer | |
  • 1
    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

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) {
| improve this answer | |

Check out the clear() method:

Clears all graphics.

| improve this answer | |

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

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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