[OpenLayers-Users] disabling pan/zoom on map

Christopher Schmidt crschmidt at metacarta.com
Thu Feb 1 06:48:22 EST 2007


On Thu, Feb 01, 2007 at 09:17:10AM +0000, Jon Blower wrote:
> Hi all,
> 
> Is there a way to (temporarily) prevent the user from panning or zooming an
> OpenLayers map?  I would like to stop the user moving the map while I am
> loading something else.

You could remove the Controls from the map temporarily. If you don't
expect them to hit the panzoom buttons, that would be as easy as... er,
wait. Apparently we don't have a removeControl method on the map? ack. I
guess that makes sense...

So, as far as I know, there is no easy way to do this. THe reason is
that controls don't tend to unregister their events. You could do
something like:

c = new OpenLayers.Control.MouseDefaults();
map.addControl(c);

// Want to turn off controls now
oldevents = []
oldevents['mouseDown'] = c.defaultMouseDown;
c.defaultMouseDown = function(){};
oldevents['mouseClick'] = c.defaultMouseClick;
c.defaultMouseClick = function() {}
...

// done now
c.defaultMouseDown=oldevents['mouseDown'];
c.defaultMouseClick = oldevents['mouseClick'];

It's not pretty, but it is a thought... I'd start from something like
that, and move on. Unfortunately, doing the same thing for the panzoom
controller would be much more difficult. 

It sounds like a removeControl method on the map, combined with teaching
controls how to clean up after themselves, would be a good idea. 

Regards,
-- 
Christopher Schmidt
MetaCarta



More information about the Users mailing list