[OpenLayers-Users] Insert additional parameters to event listeners

Mike Purvis mike at uwmike.com
Wed May 19 09:53:19 EDT 2010


Hi Ads,

It kinda depends what parameters you want in there. The "featureAdded"
handler is going to be a generic one, so it will have to get a lot of its
information about the feature and so-on at its own runtime. However, what
you probably want to do is use a closure:

var control = new OpenLayers.Control.DrawFeature(
 someLayer, OpenLayers.Handler.Point, {
   featureAdded: this.createFeatureAddedHandler(param1, param2)
 });

...

function: createFeatureAddedHandler(param1, param2) {
return function(feature) {
// In here you have access perpetually to the param1 and param2
// that were passed in when the handler was created.
}
}

If you'd like further information, the Wikipedia article has some good
examples, despite the obtuse introduction:
http://en.wikipedia.org/wiki/Closure_(computer_science)



On Tue, May 18, 2010 at 10:37 PM, adstan <nikida78 at gmail.com> wrote:

>
> Hi all,
>
> Is there a way I could add additional parameters to event listeners? Please
> refer to this example:
>
> var control = new OpenLayers.Control.DrawFeature(
>  someLayer, OpenLayers.Handler.Point, {
>    featureAdded: someFunction
>  });
>
> ...
>
> function: someFunction(feature, param2) {
> ...
> }
>
> In the abovementioned example, how can I get the featureAdded event to
> insert additional parameters to the "someFunction" method?
>
> Thanks!!!
>
> Ads
> --
> View this message in context:
> http://osgeo-org.1803224.n2.nabble.com/Insert-additional-parameters-to-event-listeners-tp5073085p5073085.html
> Sent from the OpenLayers Users mailing list archive at Nabble.com.
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>



-- 
http://uwmike.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20100519/da7ac039/attachment.html


More information about the Users mailing list