S.Y
S.Y

Reputation: 35

Is a way to remove features without setting feature id?

I would like to remove features from layers when using Openlayers3. I know that we can feature.setId(id) when create features and get with feature.getId() to remove them. But if the features is loading from the database or geoserver, they don't have a proper 'ID' Property.

So is a way to remove the selected features without setting feature id?

Upvotes: 1

Views: 469

Answers (1)

pavlos
pavlos

Reputation: 3081

You have to make your question more clear. Do you want to delete the features from the DB or you just want to remove them from the client and take no further action on the DB?????

If you dont have an id I guess there should be something identical amoung the feature attributes. I mean if you executed an sql delete script wouldnt you use an identifier to delete them????

So I pressume your features have a primary key or something identical to distinguish them.

So lets assume your fetaures have an identical column named "MYPK". If so you can iterate throught features and grap this identical attribute

var pksToDelete = new Array();
 for (var i=0;i<features.length;i++){
 pksToDelete.push(features[i].get('MYPK'));
 }

now you have all the unique ids of your features into an array. If you want to delete them from DB go for a wfs-t request using these ids and then do a refresh to your layer.

Better provide a sample code you use and explain in detail your purpose so I can help you in detail.

Upvotes: 1

Related Questions