[OpenLayers-Users] righ-click event stops left-click

dalsinao dalsinao at yahoo.es
Tue Mar 9 12:42:07 EST 2010


Hello all,

I want to capture in the same control both left and right click events.
Using examples, I've come to the control I add below. It seems to work fine:
Left click events are caught in my "onLeftClick" function and right click
events in "onRightClick" (see code below). However, after servicing for the
first time a right-click event, then left click event stops to work, even
though the right-click doesn't. 

Any idea on which is the problem? Or any better alternative to catch right
and left click events?

I use the old and crappy IE6 (not my choice, but I have to support it
anyhow).
Thanks in advance for any help!
David

Here is the code...


OpenLayers.Control.CAXRightClick = OpenLayers.Class(OpenLayers.Control, {

    handleRightClicks: true,
    handleLeftClicks: true,
   
    defaultHandlerOptions: {
        'single': true,
        'double': true,
        'pixelTolerance': 0,
        'stopSingle': false,
        'stopDouble': false
    },

    initialize: function(options) {
        this.handlerOptions = OpenLayers.Util.extend(
            {}, this.defaultHandlerOptions
        );
        OpenLayers.Control.prototype.initialize.apply(
            this, arguments
        );
        
        
        this.handlers = {};
        
        if (this.handleRightClicks){
            this.handlers.rightclick = new OpenLayers.Handler.Click(this,
{'rightclick': this.onRightClick}, this.handlerOptions);
        }
        
        if (this.handleLeftClicks){
            this.handlers.leftclick = new OpenLayers.Handler.Click(this,
{'click': this.onLeftClick}, this.handlerOptions);
        }
    },

	onLeftClick: function(evt){
	    alert("left clicked on map");
	},

	onRightClick: function(evt){
	    alert("right clicked on map");
	},
	
    activate: function () {
        if (!this.active) {
            for(var i in this.handlers) {
                this.handlers[i].activate();
            }
        }
        return OpenLayers.Control.prototype.activate.apply(
            this, arguments
        );
    },

    deactivate: function () {
        if (this.active) {
            for(var i in this.handlers) {
                this.handlers[i].deactivate();
            }
        }
        return OpenLayers.Control.prototype.deactivate.apply(
            this, arguments
        );
    },

    setMap: function(map) {
        OpenLayers.Control.prototype.setMap.apply(this, arguments);
        
        if (this.handleRightClicks && (typeof(this.handlers.rightclick) !=
"undefined")){
            this.handlers.rightclick.setMap(map);
        }
        
        if (this.handleLeftClicks && (typeof(this.handlers.leftclick) !=
"undefined")){
            this.handlers.leftclick.setMap(map);
        }

        this.disableContextMentu();
    },

...

});

-- 
View this message in context: http://n2.nabble.com/righ-click-event-stops-left-click-tp4703752p4703752.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.



More information about the Users mailing list