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 <ad...@mapgears.com> 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 : eric.lemo...@camptocamp.com
http://www.camptocamp.com
_______________________________________________
Dev mailing list
Dev@openlayers.org
http://openlayers.org/mailman/listinfo/dev

Reply via email to