DeleteFeature control

Alexandre Dubé

DeleteFeature control

Reply Threaded More More options
Print post
Permalink
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
[hidden email]
http://openlayers.org/mailman/listinfo/dev
Alexandre Dubé

Re: DeleteFeature control

Reply Threaded More More options
Print post
Permalink
Hey,

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

  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...)

  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.

  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
[hidden email]
http://openlayers.org/mailman/listinfo/dev
Eric Lemoine-2-2

DeleteFeature control

Reply Threaded More More options
Print post
Permalink
On Friday, July 17, 2009, Alexandre Dube <[hidden email]> 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
changes.


>
>   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) {
                 saveStrategy.save();
             }
        }
    }),
    controls: [
        new OpenLayers.Control.SelectFeature(
            layer, {
                onSelect: function(f) {
                    f.state = DELETE;
                    this.layer.drawFeature(f);
                }
        })
    ]
});

(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?

Cheers,




>
>   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
> [hidden email]
> 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 : [hidden email]
http://www.camptocamp.com
_______________________________________________
Dev mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/dev
Alexandre Dubé

Re: DeleteFeature control

Reply Threaded More More options
Print post
Permalink
Hi Eric,

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

I haven't tried either, but in the past I tried the HTTP protocol +
featureserver and the Save strategy wasn't able to read the insertedId
of the response received.  I should simply try it and see what's the
status now...

>
>
> 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
> changes.
>
>
>  

Ok

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

Yes.  I just wondered if it was better to do it internally...

> 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) {
>                  saveStrategy.save();
>              }
>         }
>     }),
>     controls: [
>         new OpenLayers.Control.SelectFeature(
>             layer, {
>                 onSelect: function(f) {
>                     f.state = DELETE;
>                     this.layer.drawFeature(f);
>                 }
>         })
>     ]
> });
>  

If I understand correctly, you would disagree to have this control added
as a new OpenLayers official control because of its 2 independent
actions, so you suggest instead I should define a customized control
like above but it requires to have controls within the control to be
automatically activated/deactivated on 'this' control
activation/deactivation.  Is that it ?

> (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?
>
> Cheers,
>
>  

About the 'controls' property and the act./dea. automatism : that's a
good idea, but wouldn't it be good to have a 'handlers' property also
and activate/deactivate all handlers as well ?  Currently, control has a
'handler' property only.  Would it make sense to have 'handlers' added a
do the same kind of automatism as the new 'controls' property ?

Regards,

Alexandre

>
>
>  
>>   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
>> [hidden email]
>> http://openlayers.org/mailman/listinfo/dev
>>
>>    
>
>
>  


--
Alexandre Dubé
Mapgears
www.mapgears.com

_______________________________________________
Dev mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/dev
Eric Lemoine-2-2

Re: DeleteFeature control

Reply Threaded More More options
Print post
Permalink
On Monday, July 20, 2009, Alexandre Dube <[hidden email]> wrote:

> Hi Eric,
>
> Eric Lemoine wrote:
>
>   (I never used Protocol.MapFish and Strategy.Save together, I'm curious
> to know why they don't play together)
>
>
>
>
> I haven't tried either, but in the past I tried the HTTP protocol + featureserver and the Save strategy wasn't able to read the insertedId of the response received.  I should simply try it and see what's the status now...

right. But a patch was committed before 2.8, so there's chance that
the save strategy and the mapfish protocol actually work together.


>
>
>
>
> 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
> changes.
>
>
>
>
>
> Ok
>
>
> I don't understand. Can't you listen to "featuredeleted" from your
> control and trigger saveStrategy.save()? (assuming Strategy.Save work
> with Protocol.MapFish).
>
>
>
>
> Yes.  I just wondered if it was better to do it internally...
>
>
> 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) {
>                  saveStrategy.save();
>              }
>         }
>     }),
>     controls: [
>         new OpenLayers.Control.SelectFeature(
>             layer, {
>                 onSelect: function(f) {
>                     f.state = DELETE;
>                     this.layer.drawFeature(f);
>                 }
>         })
>     ]
> });
>
>
>
> If I understand correctly, you would disagree to have this control added as a new OpenLayers official control because of its 2 independent actions, so you suggest instead I should define a customized control like above but it requires to have controls within the control to be automatically activated/deactivated on 'this' control activation/deactivation.  Is that it ?

That's basically it, yes. But I may wrong, and there may be value in
combining these two independent activities (as a helper control), I'm
just not convinced at this point. To get to the delete control


>
>
> (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?
>
> Cheers,
>
>
>
>
> About the 'controls' property and the act./dea. automatism : that's a good idea, but wouldn't it be good to have a 'handlers' property also and activate/deactivate all handlers as well ?  Currently, control has a 'handler' property only.  Would it make sense to have 'handlers' added a do the same kind of automatism as the new 'controls' property ?
>
> Regards,
>
> Alexandre
>
>
>
>
>
>
>   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
> [hidden email]
> http://openlayers.org/mailman/listinfo/dev
>
>
>
>
>
>
>
>
>
> --
> Alexandre Dubé
> Mapgears
> www.mapgears.com
>
>

--
Eric Lemoine

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

Tel : 00 33 4 79 44 44 96
Mail : [hidden email]
http://www.camptocamp.com
_______________________________________________
Dev mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/dev
Eric Lemoine-2-2

Re: DeleteFeature control

Reply Threaded More More options
Print post
Permalink
On Monday, July 20, 2009, Eric Lemoine <[hidden email]> wrote:

> On Monday, July 20, 2009, Alexandre Dube <[hidden email]> wrote:
>> Hi Eric,
>>
>> Eric Lemoine wrote:
>>
>>   (I never used Protocol.MapFish and Strategy.Save together, I'm curious
>> to know why they don't play together)
>>
>>
>>
>>
>> I haven't tried either, but in the past I tried the HTTP protocol + featureserver and the Save strategy wasn't able to read the insertedId of the response received.  I should simply try it and see what's the status now...
>
> right. But a patch was committed before 2.8, so there's chance that
> the save strategy and the mapfish protocol actually work together.
>
>
>>
>>
>>
>>
>> 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
>> changes.
>>
>>
>>
>>
>>
>> Ok
>>
>>
>> I don't understand. Can't you listen to "featuredeleted" from your
>> control and trigger saveStrategy.save()? (assuming Strategy.Save work
>> with Protocol.MapFish).
>>
>>
>>
>>
>> Yes.  I just wondered if it was better to do it internally...
>>
>>
>> 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) {
>>                  saveStrategy.save();
>>              }
>>         }
>>     }),
>>     controls: [
>>         new OpenLayers.Control.SelectFeature(
>>             layer, {
>>                 onSelect: function(f) {
>>                     f.state = DELETE;
>>                     this.layer.drawFeature(f);
>>                 }
>>         })
>>     ]
>> });
>>
>>
>>
>> If I understand correctly, you would disagree to have this control added as a new OpenLayers official control because of its 2 independent actions, so you suggest instead I should define a customized control like above but it requires to have controls within the control to be automatically activated/deactivated on 'this' control activation/deactivation.  Is that it ?
>
> That's basically it, yes. But I may wrong, and there may be value in
> combining these two independent activities (as a helper control), I'm
> just not convinced at this point. To get to the delete control


[argh, my email got sent before I finished it]

so, to get to the delete control you've been working on, I see more
value, in terms of flexibility, in adding "control composition" to the
control base class.




>
>
>>
>>
>> (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?
>>
>> Cheers,
>>
>>
>>
>>
>> About the 'controls' property and the act./dea. automatism : that's a good idea, but wouldn't it be good to have a 'handlers' property also and activate/deactivate all handlers as well ?  Currently, control has a 'handler' property only.  Would it make sense to have 'handlers' added a do the same kind of automatism as the new 'controls' property ?


Agreed.

>>
>> Regards,
>>
>> Alexandre
>>
>>
>>
>>
>>
>>
>>   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
>> [hidden email]
>> http://openlayers.org/mailman/listinfo/dev
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> --
>> Alexandre Dubé
>> Mapgears
>> www.mapgears.com
>>
>>
>
> --
> Eric Lemoine
>
> Camptocamp France SAS
> Savoie Technolac, BP 352
> 73377 Le Bourget du Lac, Cedex
>
> Tel : 00 33 4 79 44 44 96
> Mail : [hidden email]
> http://www.camptocamp.com
>

--
Eric Lemoine

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

Tel : 00 33 4 79 44 44 96
Mail : [hidden email]
http://www.camptocamp.com
_______________________________________________
Dev mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/dev
Alexandre Dubé

Re: DeleteFeature control

Reply Threaded More More options
Print post
Permalink
Eric Lemoine wrote:
>
>
> so, to get to the delete control you've been working on, I see more
> value, in terms of flexibility, in adding "control composition" to the
> control base class.
>
>
>  

I also agree.  Originally, the control had a Feature handler instead of
a SelectFeature control.  Looking at it now, it's too simple to be
justified as a new control.

>>>
>>> About the 'controls' property and the act./dea. automatism : that's a good idea, but wouldn't it be good to have a 'handlers' property also and activate/deactivate all handlers as well ?  Currently, control has a 'handler' property only.  Would it make sense to have 'handlers' added a do the same kind of automatism as the new 'controls' property ?
>>>      
>
>
> Agreed.
>
>  

Great.


--
Alexandre Dubé
Mapgears
www.mapgears.com

_______________________________________________
Dev mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/dev
Alexandre Dubé

Re: DeleteFeature control

Reply Threaded More More options
Print post
Permalink
Hi,

  I'm trying to reproduce what we discuss.  I'm not really familiar with
this method and I'm having difficulties with 'this'.  Here's what I have
so far :

/*** START ***/
var delCtrl = new OpenLayers.Control({
    layer: olWFSRoads,
      handlers: {"keyboard": new OpenLayers.Handler.Keyboard(this,{ //
<------- 'this' is not the control
            keydown: function(evt) {
            var code = evt.keyCode;
            //var features = this.layer.selectedFeatures; // <-------
this is not the control, and so on...
            var features = olWFSRoads.selectedFeatures; // <----- can we
avoid the use of olWFSRoads ?

            if(code == OpenLayers.Event.KEY_DELETE && features.length > 0 &&
               this.confirmDelete() ) {
                this.deleteFeatures(features);
                return;
            }
        }
      })},
    controls: [
        new OpenLayers.Control.SelectFeature(
            olWFSRoads, {
                onSelect: function(f) {
                    f.state = OpenLayers.State.DELETE;
                    this.layer.drawFeature(f);
                }
        })
    ],
    confirmDelete: function() {
        return (confirm("Delete selected features ?"))
    },
    deleteFeatures: function(features) {
        this.layer.destroyFeatures(features);
    }
});
/*** END ***/

I made the discussed changes to the OL.Control to be able to automatize
activation/deactivation/setMap.

If you look at the <---------- arrow, you'll see a 'this', which is
supposed to be the control, owner of the handler.  Well, that 'this' is
not the control, it's the html page (figures).  I tried to put 'delCtrl'
instead but it didn't work.  I really wonder how I am supposed to create
controls that way (without creating a class) and use the 'this' (or
something else).

Any hint would be greatly appreciated,

Alexandre

P.S. Also, I believe it's ok to have my 'user' functions, like
confirmDelete directly inside the control since the control is
completely custom-made (i.e. not using events).

Alexandre Dube wrote:

> Eric Lemoine wrote:
>  
>> so, to get to the delete control you've been working on, I see more
>> value, in terms of flexibility, in adding "control composition" to the
>> control base class.
>>
>>
>>  
>>    
>
> I also agree.  Originally, the control had a Feature handler instead of
> a SelectFeature control.  Looking at it now, it's too simple to be
> justified as a new control.
>
>  
>>>> About the 'controls' property and the act./dea. automatism : that's a good idea, but wouldn't it be good to have a 'handlers' property also and activate/deactivate all handlers as well ?  Currently, control has a 'handler' property only.  Would it make sense to have 'handlers' added a do the same kind of automatism as the new 'controls' property ?
>>>>      
>>>>        
>> Agreed.
>>
>>  
>>    
>
> Great.
>
>
>  


--
Alexandre Dubé
Mapgears
www.mapgears.com

_______________________________________________
Dev mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/dev
Alexandre Dubé

Re: DeleteFeature control

Reply Threaded More More options
Print post
Permalink
In reply to this post by Alexandre Dubé
Oh and by the way, here's what I did for the Control (attached).  Is it
ok (too much, i.e. about the use of hasOwnProperty functions) ?

Thanks,

Alexandre

Alexandre Dube wrote:

> Eric Lemoine wrote:
>  
>> so, to get to the delete control you've been working on, I see more
>> value, in terms of flexibility, in adding "control composition" to the
>> control base class.
>>
>>
>>  
>>    
>
> I also agree.  Originally, the control had a Feature handler instead of
> a SelectFeature control.  Looking at it now, it's too simple to be
> justified as a new control.
>
>  
>>>> About the 'controls' property and the act./dea. automatism : that's a good idea, but wouldn't it be good to have a 'handlers' property also and activate/deactivate all handlers as well ?  Currently, control has a 'handler' property only.  Would it make sense to have 'handlers' added a do the same kind of automatism as the new 'controls' property ?
>>>>      
>>>>        
>> Agreed.
>>
>>  
>>    
>
> Great.
>
>
>  

--
Alexandre Dubé
Mapgears
www.mapgears.com


Index: Control.js
===================================================================
--- Control.js (revision 9573)
+++ Control.js (working copy)
@@ -117,6 +117,20 @@
      */
     handler: null,
 
+    /**
+     * Property: handlers
+     * {Array of(<OpenLayers.Handler>)} null
+     */
+    handlers: null,
+
+    /**
+     * Property: controls
+     * Controls can contain other controls.  When this control is activated, all
+     * its child controls, i.e. this.controls should be activated as well.
+     * {Array of(<OpenLayers.Controls>)} null
+     */
+    controls: null,
+
     /**
      * APIProperty: eventListeners
      * {Object} If set as an option at construction, the eventListeners
@@ -235,6 +249,22 @@
         if (this.handler) {
             this.handler.setMap(map);
         }
+        if(this.handlers) {
+            for(var key in this.handlers) {
+                if(this.handlers.hasOwnProperty(key) &&
+                   typeof this.handlers[key].setMap == "function") {
+                    this.handlers[key].setMap(map);
+                }
+            }
+        }
+        if(this.controls) {
+            for(var key in this.controls) {
+                if(this.controls.hasOwnProperty(key) &&
+                   typeof this.controls[key].setMap == "function") {
+                    this.controls[key].setMap(map);
+                }
+            }
+        }
     },
   
     /**
@@ -303,6 +333,22 @@
         if (this.handler) {
             this.handler.activate();
         }
+        if(this.handlers) {
+            for(var key in this.handlers) {
+                if(this.handlers.hasOwnProperty(key) &&
+                   typeof this.handlers[key].activate == "function") {
+                    this.handlers[key].activate();
+                }
+            }
+        }
+        if(this.controls) {
+            for(var key in this.controls) {
+                if(this.controls.hasOwnProperty(key) &&
+                   typeof this.controls[key].activate == "function") {
+                    this.controls[key].activate();
+                }
+            }
+        }
         this.active = true;
         if(this.map) {
             OpenLayers.Element.addClass(
@@ -328,6 +374,22 @@
             if (this.handler) {
                 this.handler.deactivate();
             }
+            if(this.handlers) {
+                for(var key in this.handlers) {
+                    if(this.handlers.hasOwnProperty(key) &&
+                       typeof this.handlers[key].deactivate == "function") {
+                        this.handlers[key].deactivate();
+                    }
+                }
+            }
+            if(this.controls) {
+                for(var key in this.controls) {
+                    if(this.controls.hasOwnProperty(key) &&
+                       typeof this.controls[key].deactivate == "function") {
+                        this.controls[key].deactivate();
+                    }
+                }
+            }
             this.active = false;
             if(this.map) {
                 OpenLayers.Element.removeClass(

_______________________________________________
Dev mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/dev
Eric Lemoine-2-2

DeleteFeature control

Reply Threaded More More options
Print post
Permalink
On Tuesday, July 21, 2009, Alexandre Dube <[hidden email]> wrote:
> Oh and by the way, here's what I did for the Control (attached).  Is it ok (too much, i.e. about the use of hasOwnProperty functions) ?

why not using the regular

var i, len, control;
for(i = 0, len = controls.length; i < len; i++) {
    control = controls[i];
}

?

(the OpenLayers way, which is safer than using for in I guess)

>
> Thanks,
>
> Alexandre
>
> Alexandre Dube wrote:
>
> Eric Lemoine wrote:
>
>
> so, to get to the delete control you've been working on, I see more
> value, in terms of flexibility, in adding "control composition" to the
> control base class.
>
>
>
>
>
> I also agree.  Originally, the control had a Feature handler instead of a SelectFeature control.  Looking at it now, it's too simple to be justified as a new control.
>
>
>
> About the 'controls' property and the act./dea. automatism : that's a good idea, but wouldn't it be good to have a 'handlers' property also and activate/deactivate all handlers as well ?  Currently, control has a 'handler' property only.  Would it make sense to have 'handlers' added a do the same kind of automatism as the new 'controls' property ?
>
>
> Agreed.
>
>
>
>
> Great.
>
>
>
>
>
>
> --
> Alexandre Dubé
> Mapgears
> www.mapgears.com
>
>


--
Eric Lemoine

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

Tel : 00 33 4 79 44 44 96
Mail : [hidden email]
http://www.camptocamp.com
_______________________________________________
Dev mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/dev
Alexandre Dubé

Re: DeleteFeature control

Reply Threaded More More options
Print post
Permalink
Eric Lemoine wrote:

> On Tuesday, July 21, 2009, Alexandre Dube <[hidden email]> wrote:
>  
>> Oh and by the way, here's what I did for the Control (attached).  Is it ok (too much, i.e. about the use of hasOwnProperty functions) ?
>>    
>
> why not using the regular
>
> var i, len, control;
> for(i = 0, len = controls.length; i < len; i++) {
>     control = controls[i];
> }
>
> ?
>
> (

It seems I like to complicate things.  I won't be able to work more on
this this p.m. but as soon as I modify something I'll let you know.

BTW, do you know something about my 'this' problem ?

Many thanks,

--
Alexandre Dubé
Mapgears
www.mapgears.com

_______________________________________________
Dev mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/dev
Eric Lemoine-2-2

Re: DeleteFeature control

Reply Threaded More More options
Print post
Permalink
In reply to this post by Alexandre Dubé
On Tuesday, July 21, 2009, Alexandre Dube <[hidden email]> wrote:
> Hi,
>
>  I'm trying to reproduce what we discuss.  I'm not really familiar with this method and I'm having difficulties with 'this'.  Here's what I have so far :
>
> /*** START ***/
> var delCtrl = new OpenLayers.Control({
>    layer: olWFSRoads,
>      handlers: {"keyboard": new

either use "handler" or give "handlers" an array

OpenLayers.Handler.Keyboard(this,{ // <------- 'this' is not the control

indeed, it's not the control, it is the current scope/object. Here
it's the object that's building the control, it may be "window" if
you're not creating the control from a specific object


>            keydown: function(evt) {
>            var code = evt.keyCode;
>            //var features = this.layer.selectedFeatures; // <------- this is not the control, and so on...

yet another context, "this" refers to the keyboard handler here
("keydown" is a method of the keyboard handler)

>            var features = olWFSRoads.selectedFeatures; // <----- can we avoid the use of olWFSRoads ?

I'm not sure whethet you can give handlers a specific scope for
executing callbacks. I don't think so.

>
>            if(code == OpenLayers.Event.KEY_DELETE && features.length > 0 &&
>               this.confirmDelete() ) {
>                this.deleteFeatures(features);
>                return;
>            }
>        }
>      })},
>    controls: [
>        new OpenLayers.Control.SelectFeature(
>            olWFSRoads, {
>                onSelect: function(f) {
>                    f.state = OpenLayers.State.DELETE;
>                    this.layer.drawFeature(f);
>                }
>        })
>    ],
>    confirmDelete: function() {
>        return (confirm("Delete selected features ?"))
>    },
>    deleteFeatures: function(features) {
>        this.layer.destroyFeatures(features);
>    }
> });
> /*** END ***/
>
> I made the discussed changes to the OL.Control to be able to automatize activation/deactivation/setMap.
>
> If you look at the <---------- arrow, you'll see a 'this', which is supposed to be the control, owner of the handler.  Well, that 'this' is not the control, it's the html page (figures).  I tried to put 'delCtrl' instead but it didn't work.  I really wonder how I am supposed to create controls that way (without creating a class) and use the 'this' (or something else).
>
> Any hint would be greatly appreciated,
>
> Alexandre
>
> P.S. Also, I believe it's ok to have my 'user' functions, like confirmDelete directly inside the control since the control is completely custom-made (i.e. not using events).
>
> Alexandre Dube wrote:
>
> Eric Lemoine wrote:
>
>
> so, to get to the delete control you've been working on, I see more
> value, in terms of flexibility, in adding "control composition" to the
> control base class.
>
>
>
>
>
> I also agree.  Originally, the control had a Feature handler instead of a SelectFeature control.  Looking at it now, it's too simple to be justified as a new control.
>
>
>
> About the 'controls' property and the act./dea. automatism : that's a good idea, but wouldn't it be good to have a 'handlers' property also and activate/deactivate all handlers as well ?  Currently, control has a 'handler' property only.  Would it make sense to have 'handlers' added a do the same kind of automatism as the new 'controls' property ?
>
>
> Agreed.
>
>
>
>
> Great.
>
>
>
>
>
>
> --
> Alexandre Dubé
> Mapgears
> www.mapgears.com
>
>

--
Eric Lemoine

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

Tel : 00 33 4 79 44 44 96
Mail : [hidden email]
http://www.camptocamp.com
_______________________________________________
Dev mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/dev
Eric Lemoine-2-2

Re: DeleteFeature control

Reply Threaded More More options
Print post
Permalink
In reply to this post by Alexandre Dubé
> P.S. Also, I believe it's ok to have my 'user' functions, like confirmDelete directly inside the control since the control is completely custom-made (i.e. not using events).

yes that's fine.



--
Eric Lemoine

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

Tel : 00 33 4 79 44 44 96
Mail : [hidden email]
http://www.camptocamp.com
_______________________________________________
Dev mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/dev
Eric Lemoine-2-2

Re: DeleteFeature control

Reply Threaded More More options
Print post
Permalink
In reply to this post by Alexandre Dubé
Alexandre

I now understand one of your problems, you need to give the handler a
reference to the control, but the control does not exist yet since
you're actually creating it. Giving the handler a fake control, of the
form {map: map} (where map is the map instance) should do the trick.

I think handlers do not actually require a reference to the control,
they just need a reference to the map (to register listeners). So I
don't understand why we have this constraint. Anyone involved in the
design of handlers knows?

On Tuesday, July 21, 2009, Alexandre Dube <[hidden email]> wrote:

> Hi,
>
>  I'm trying to reproduce what we discuss.  I'm not really familiar with this method and I'm having difficulties with 'this'.  Here's what I have so far :
>
> /*** START ***/
> var delCtrl = new OpenLayers.Control({
>    layer: olWFSRoads,
>      handlers: {"keyboard": new OpenLayers.Handler.Keyboard(this,{ // <------- 'this' is not the control
>            keydown: function(evt) {
>            var code = evt.keyCode;
>            //var features = this.layer.selectedFeatures; // <------- this is not the control, and so on...
>            var features = olWFSRoads.selectedFeatures; // <----- can we avoid the use of olWFSRoads ?
>
>            if(code == OpenLayers.Event.KEY_DELETE && features.length > 0 &&
>               this.confirmDelete() ) {
>                this.deleteFeatures(features);
>                return;
>            }
>        }
>      })},
>    controls: [
>        new OpenLayers.Control.SelectFeature(
>            olWFSRoads, {
>                onSelect: function(f) {
>                    f.state = OpenLayers.State.DELETE;
>                    this.layer.drawFeature(f);
>                }
>        })
>    ],
>    confirmDelete: function() {
>        return (confirm("Delete selected features ?"))
>    },
>    deleteFeatures: function(features) {
>        this.layer.destroyFeatures(features);
>    }
> });
> /*** END ***/
>
> I made the discussed changes to the OL.Control to be able to automatize activation/deactivation/setMap.
>
> If you look at the <---------- arrow, you'll see a 'this', which is supposed to be the control, owner of the handler.  Well, that 'this' is not the control, it's the html page (figures).  I tried to put 'delCtrl' instead but it didn't work.  I really wonder how I am supposed to create controls that way (without creating a class) and use the 'this' (or something else).
>
> Any hint would be greatly appreciated,
>
> Alexandre
>
> P.S. Also, I believe it's ok to have my 'user' functions, like confirmDelete directly inside the control since the control is completely custom-made (i.e. not using events).
>
> Alexandre Dube wrote:
>
> Eric Lemoine wrote:
>
>
> so, to get to the delete control you've been working on, I see more
> value, in terms of flexibility, in adding "control composition" to the
> control base class.
>
>
>
>
>
> I also agree.  Originally, the control had a Feature handler instead of a SelectFeature control.  Looking at it now, it's too simple to be justified as a new control.
>
>
>
> About the 'controls' property and the act./dea. automatism : that's a good idea, but wouldn't it be good to have a 'handlers' property also and activate/deactivate all handlers as well ?  Currently, control has a 'handler' property only.  Would it make sense to have 'handlers' added a do the same kind of automatism as the new 'controls' property ?
>
>
> Agreed.
>
>
>
>
> Great.
>
>
>
>
>
>
> --
> Alexandre Dubé
> Mapgears
> www.mapgears.com
>
>

--
Eric Lemoine

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

Tel : 00 33 4 79 44 44 96
Mail : [hidden email]
http://www.camptocamp.com
_______________________________________________
Dev mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/dev
Alexandre Dubé

Re: DeleteFeature control

Reply Threaded More More options
Print post
Permalink
In reply to this post by Eric Lemoine-2-2
Hi,

  I'm going to work on my example today.  See below.

Eric Lemoine wrote:
> why not using the regular
>
> var i, len, control;
> for(i = 0, len = controls.length; i < len; i++) {
>     control = controls[i];
> }
>
> ?
>  

Right.  I just wondered if it could have been possible to have a {}
instead of a [] for controls, like {"selectControl": new OL.C.SF(),
"myCustomControl": new OL.C.Custom() } (like the handlers) instead of
[new OL.C.SF, OL.C.Custom]...

I'll just go with [] then.  Thanks,

--
Alexandre Dubé
Mapgears
www.mapgears.com

_______________________________________________
Dev mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/dev
Alexandre Dubé

Re: DeleteFeature control

Reply Threaded More More options
Print post
Permalink
In reply to this post by Eric Lemoine-2-2
Eric Lemoine wrote:

> Alexandre
>
> I now understand one of your problems, you need to give the handler a
> reference to the control, but the control does not exist yet since
> you're actually creating it. Giving the handler a fake control, of the
> form {map: map} (where map is the map instance) should do the trick.
>
> I think handlers do not actually require a reference to the control,
> they just need a reference to the map (to register listeners). So I
> don't understand why we have this constraint. Anyone involved in the
> design of handlers knows?
>
>
>  
Mmm... I understand, but since I need to use callbacks on "handler"
events, I think it's simpler to create my control the way I already did
it.  I won't go any further in this example.

I still agree with automatic controls and handlers
activation/deactivation.  Attached an new patch with the simple changes
needed.  Is it ok ?  If it is, I'll open a ticket.

Again, many thanks for your help,

--
Alexandre Dubé
Mapgears
www.mapgears.com


Index: Control.js
===================================================================
--- Control.js (revision 9573)
+++ Control.js (working copy)
@@ -117,6 +117,20 @@
      */
     handler: null,
 
+    /**
+     * Property: handlers
+     * {Array of(<OpenLayers.Handler>)} null
+     */
+    handlers: null,
+
+    /**
+     * Property: controls
+     * Controls can contain other controls.  When this control is activated, all
+     * its child controls, i.e. this.controls should be activated as well.
+     * {Array of(<OpenLayers.Controls>)} null
+     */
+    controls: null,
+
     /**
      * APIProperty: eventListeners
      * {Object} If set as an option at construction, the eventListeners
@@ -235,6 +249,16 @@
         if (this.handler) {
             this.handler.setMap(map);
         }
+        if(this.handlers) {
+            for(var key in this.handlers) {
+                this.handlers[key].setMap(map);
+            }
+        }
+        if(this.controls) {
+            for(var i=0, len=this.controls.length; i<len; i++) {
+                this.controls[i].setMap(map);
+            }
+        }
     },
   
     /**
@@ -303,6 +327,16 @@
         if (this.handler) {
             this.handler.activate();
         }
+        if(this.handlers) {
+            for(var key in this.handlers) {
+                this.handlers[key].activate();
+            }
+        }
+        if(this.controls) {
+            for(var i=0, len=this.controls.length; i<len; i++) {
+                this.controls[i].activate();
+            }
+        }
         this.active = true;
         if(this.map) {
             OpenLayers.Element.addClass(
@@ -328,6 +362,16 @@
             if (this.handler) {
                 this.handler.deactivate();
             }
+            if(this.handlers) {
+                for(var key in this.handlers) {
+                    this.handlers[key].deactivate();
+                }
+            }
+            if(this.controls) {
+                for(var i=0, len=this.controls.length; i<len; i++) {
+                    this.controls[i].deactivate();
+                }
+            }
             this.active = false;
             if(this.map) {
                 OpenLayers.Element.removeClass(

_______________________________________________
Dev mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/dev
Eric Lemoine-2-2

Re: DeleteFeature control

Reply Threaded More More options
Print post
Permalink
On Wed, Jul 22, 2009 at 7:22 PM, Alexandre Dube<[hidden email]> wrote:

> Eric Lemoine wrote:
>>
>> Alexandre
>>
>> I now understand one of your problems, you need to give the handler a
>> reference to the control, but the control does not exist yet since
>> you're actually creating it. Giving the handler a fake control, of the
>> form {map: map} (where map is the map instance) should do the trick.
>>
>> I think handlers do not actually require a reference to the control,
>> they just need a reference to the map (to register listeners). So I
>> don't understand why we have this constraint. Anyone involved in the
>> design of handlers knows?
>>
>>
>>
>
> Mmm... I understand, but since I need to use callbacks on "handler" events,
> I think it's simpler to create my control the way I already did it.  I won't
> go any further in this example.

Ok.

>
> I still agree with automatic controls and handlers activation/deactivation.
>  Attached an new patch with the simple changes needed.  Is it ok ?  If it
> is, I'll open a ticket.

Ok to me.

Thanks Alexandre,



--
Eric Lemoine

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

Tel : 00 33 4 79 44 44 96
Mail : [hidden email]
http://www.camptocamp.com
_______________________________________________
Dev mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/dev
Alexandre Dubé

Re: DeleteFeature control

Reply Threaded More More options
Print post
Permalink
Hi,

Eric Lemoine wrote:

>
>> I still agree with automatic controls and handlers activation/deactivation.
>>  Attached an new patch with the simple changes needed.  Is it ok ?  If it
>> is, I'll open a ticket.
>>    
>
> Ok to me.
>
> Thanks Alexandre,
>  

http://trac.openlayers.org/ticket/2196

currently unassigned

Regards,

--
Alexandre Dubé
Mapgears
www.mapgears.com

_______________________________________________
Dev mailing list
[hidden email]
http://openlayers.org/mailman/listinfo/dev