[OpenLayers-Users] disabling pan/zoom on map

Jon Blower jdb at mail.nerc-essc.ac.uk
Thu Feb 1 07:21:06 EST 2007


Hi Christopher,

Thanks very much for that.  I didn't make it clear that I not only wanted to
disable the pan/zoom buttons, but also the capability to drag the map.  This
is because I want to freeze the map while I load an animation, which will be
overlaid on top of the map in precisely the right place.  (The animation, by
the way, is generated on a WMS using the TIME parameter and animated GIF
format).

Happily however, this turns out to be a self-solving problem!  I load the
animation in a div which sits on top of the OpenLayers map.  When this div
is visible it prevents the mouse clicks from reaching the OL map,
effectively freezing it.  In order to "re-enable" the OL map, I simply hide
the div overlay.  The pan/zoom controls are still visible however, so it
would indeed be useful to be able to temporarily hide them so as not to
confuse the user.

Perhaps not the most elegant solution but it seems to work exactly as I
need.

Regards,
Jon

On 2/1/07, Christopher Schmidt <crschmidt at metacarta.com> wrote:
>
> 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
>



-- 
--------------------------------------------------------------
Dr Jon Blower              Tel: +44 118 378 5213 (direct line)
Technical Director         Tel: +44 118 378 8741 (ESSC)
Reading e-Science Centre   Fax: +44 118 378 6413
ESSC                       Email: jdb at mail.nerc-essc.ac.uk
University of Reading
3 Earley Gate
Reading RG6 6AL, UK
--------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20070201/c061427e/attachment.html


More information about the Users mailing list