[OpenLayers-Users] registering a click event on a map

Puneet Kishor punk.kish at gmail.com
Tue Sep 11 17:20:11 PDT 2012


On Sep 10, 2012, at 7:16 PM, Richard Greenwood <richard.greenwood at gmail.com> wrote:

> On Mon, Sep 10, 2012 at 1:38 PM, Puneet Kishor <punk.kish at gmail.com> wrote:
>> In OL 2.11 I used to do the following successfully
>> 
>>    map.events.register(
>>        "click",
>>        map,
>>        function(e) {
>>            fancyFunction({evt: e, other_params: "foo"});
>>        }
>>    );
>> 
>> The above has stopped working in Firefox (currently using FF v. 15.0.1) without any errors. It does work in Safari 6, but gives the following warning in the console.log
>> 
>>> event.layerX and event.layerY are broken and deprecated in WebKit. They will be removed from the engine in the near future.
>> 
>> Suggestions to fix both problems would be welcomed with thanks.
> 
> 
> I believe the correct way to register a click handler is something like:
> 
> var click = new OpenLayers.Control.Click( {
>  trigger: function(e) {
>    /* do stuff */
>  }
> });
> map.addControl(click);
> click.activate();
> 


Perhaps. But, when I use the above code, I get the following error

	TypeError: OpenLayers.Control.Click is not a constructor

I don't get any error when I use the following code (snitched from the example online), but the trigger function doesn't fire. Nothing happens.

    OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {                
        defaultHandlerOptions: {
            'single': true,
            'double': false,
            'pixelTolerance': 0,
            'stopSingle': false,
            'stopDouble': false
        },

        initialize: function(options) {
            this.handlerOptions = OpenLayers.Util.extend(
                {}, this.defaultHandlerOptions
            );
            OpenLayers.Control.prototype.initialize.apply(
                this, arguments
            ); 
            this.handler = new OpenLayers.Handler.Click(
                this, {
                    'click': this.trigger
                }, this.handlerOptions
            );
        }, 

        trigger: function(e) {
            fancyFunction(e);
        }

    });

    
    var click = new OpenLayers.Control.Click();
    map.addControl( click );
    click.activate();



Finally, note that my way listed above in my OP actually works in webkit (Safari and Chrome) but not in Firefox. So, what is going on?


--
Puneet Kishor


More information about the Users mailing list