[OpenLayers-Users] Mouse.Default help

Christopher Schmidt crschmidt at metacarta.com
Sat Mar 3 21:26:45 EST 2007


On Sun, Mar 04, 2007 at 12:47:48PM +1100, bradleyspencer wrote:
> I am not a trained Object Oriented programmer so I apologise for this dumb
> question.
> 
> I want to suppress the use of doubleClick on the map as a re-centre
> operation and use it as a getFeatureInfo operation instead.
> 
> To do this the doco says I need to ?create a subclass of MouseDefaults,
> replacing the functions whose behavior you wish to change?.
> 
> There are no examples of this and whilst I have made an event listener to do
> the getFeatureInfo quite successfully, I am not at all sure how to make a
> new subclassof MouseDefaults as stated and link this event into that
> subclass.

If you only want to do it for one control (for example, when you only
have one map in the page):

 control = new OpenLayers.Control.MouseDefaults();
 control.defaultDblClick = function(evt) {
   var point = this.map.getLonLatFromViewPortPx( evt.xy );
   alert("Got point:" + point);
   OpenLayers.Event.stop(evt);
   return false;
 }

If you have multiple maps, or don't want to change the default controls
when creating the map:
 
 OpenLayers.Control.MouseDefaults.prototype.defaultDblClick = function(evt) {
   var point = this.map.getLonLatFromViewPortPx( evt.xy );
   alert("Got point:" + point);
   OpenLayers.Event.stop(evt);
   return false;
 }

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list