[OpenLayers-Dev] DeleteFeature control

Eric Lemoine eric.lemoine at camptocamp.com
Mon Jul 20 01:36:42 EDT 2009

On Friday, July 17, 2009, Alexandre Dube <adube at mapgears.com> wrote:
> Hey,

Hi Alexandre

>   I'd like to ask a couple of questions about this control.
>   Currently, the only thing it really does is change the state of the
> selected features to DELETE and on 'del' keypress, it triggers a
> 'deletefeatures' event, but it doesn't actually delete (commit, destroy,
> remove, etc.) anything.  The user needs to listen to the event and do
> what he wants himself.
>   That bugs me a little.  What good is a "DeleteFeature" control if it
> doesn't do anything by itself ?  So I'm thinking of adding a couple of
> functions that would take care of theses actions, but at the same time
> I'm aware of the Strategy.Save strategy that already has the role of
> committing changes.  It's not supporting HTTP/MapFish protocol at the
> moment though...

(I never used Protocol.MapFish and Strategy.Save together, I'm curious
to know why they don't play together)

>   Here's what I would do :
>   - add a boolean 'commit' property
>     - false : only destroy the features on screen
>     - true : commit the changes (using the Save strategy or
> protocol.commit...)

So long that the control user can be notified when a feature is
deleted I don't see the value of having the control committing the

>   Since I'm using featureserver and Protocol.MapFish (which is not part
> of the OpenLayers project) I can't figure how I could avoid to delete
> 'manually' the features, i.e. not in the control itself.

I don't understand. Can't you listen to "featuredeleted" from your
control and trigger saveStrategy.save()? (assuming Strategy.Save work
with Protocol.MapFish).

Some general comments on your control: from my understanding the
control has two activities, (1) when a feature is selected change its
state and redraw it, (2) when some delete key is pressed trigger
events. Since they are *independent* activities they could be done by
independent controls, and I think I'd disagree with wiring independent
activities within a single control.

If we had support for composite controls in the base Control class one
could do something like what follows to implement your delete
control's behavior:

var delCtrl = new OpenLayers.Control({
    handler: new OpenLayers.Handler.Keyboard({
        keydown: function(evt) {
             var delKey = ...
             if(delKey) {
    controls: [
        new OpenLayers.Control.SelectFeature(
            layer, {
                onSelect: function(f) {
                    f.state = DELETE;

(the support for composing controls I mentioned above involves having
the base Control class activates and deactivates every control that's
passed in the "controls" option.)

What do you think?


>   Any hint would be appreciated,
> Alexandre
> Alexandre Dube wrote:
>> Hi,
>>   I just sent (finally) a new patch for ticket 1882 (1) (DeleteFeature
>> control) and set the status to review.
>> (1) http://trac.openlayers.org/ticket/1882
>> Regards,
> --
> Alexandre Dubé
> Mapgears
> www.mapgears.com
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev

Eric Lemoine

Camptocamp France SAS
Savoie Technolac, BP 352
73377 Le Bourget du Lac, Cedex

Tel : 00 33 4 79 44 44 96
Mail : eric.lemoine at camptocamp.com

More information about the Dev mailing list