Assuming that one already has a WMSGetFeatureInfo on the map then its quite simple:
-
Add new class
-
Use new class
New class
// A control class for capturing click events...
OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
defaultHandlerOptions: {
'single': true,
'double': true,
'pixelTolerance': 0,
'stopSingle': false,
'stopDouble': false
},
handleRightClicks: true,
initialize: function (options) {
this.handlerOptions = OpenLayers.Util.extend(
{}, this.defaultHandlerOptions
);
OpenLayers.Control.prototype.initialize.apply(
this, arguments
);
this.handler = new OpenLayers.Handler.Click(
this, this.eventMethods, this.handlerOptions
);
},
CLASS_NAME: "OpenLayers.Control.Click"
});
Use it
// Add an instance of the Click control that listens to various click events:
var oClick = new OpenLayers.Control.Click({ eventMethods: {
'rightclick': function (e) {
//the infotool has already been added to the map so lets use it! No need to fuff about and do the request ourselves is there?
infoTool.request(e.xy);
}
}
});
map.addControl(oClick);
oClick.activate();