[OpenLayers-Users] How to set scope for callbacks in
	SelectFeature control?
    Andreas Hocevar 
    ahocevar at opengeo.org
       
    Tue Apr 20 06:48:37 EDT 2010
    
    
  
On Apr 20, 2010, at 12:05 , Casper Børgesen wrote:
> How do I set the scope for any of the callbacks associated in the SelectFeature control?
It is recommended to use event listeners instead of callbacks, but if you want to use a callback, the way to set the scope is to use
OpenLayers.Function.bind(fn, scope);
Regards,
Andreas.
>  
> Var featSelect = new OpenLayers.Control.SelectFeature(
>               this.Layer,
>               {
>                   ...
>                   scope: this, // Appearently not for the callbacks
>                   callbacks: { 'click': this.handleClick }
>               }
> );
>  
> Using closures doesn’t seem to work either.
>  
> Var featSelect = new OpenLayers.Control.SelectFeature(
>               this.Layer,
>               {
>                   ...
>                   scope: this, // Appearently not for the callbacks
>                   callbacks: { 'click': function (feat) {
>                                             this.handleClick(feat);
>                                         }
>                   }
>               }
> );
>  
> I’m still working on learning how to understand the OpenLayers source and how to handle scopes in general :)
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
-- 
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.
    
    
More information about the Users
mailing list