Hi Christopher,<br><br>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).
<br><br>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.
<br><br>Perhaps not the most elegant solution but it seems to work exactly as I need.<br><br>Regards,<br>Jon<br><br><div><span class="gmail_quote">On 2/1/07, <b class="gmail_sendername">Christopher Schmidt</b> <<a href="mailto:crschmidt@metacarta.com">
crschmidt@metacarta.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">On Thu, Feb 01, 2007 at 09:17:10AM +0000, Jon Blower wrote:
<br>> Hi all,<br>><br>> Is there a way to (temporarily) prevent the user from panning or zooming an<br>> OpenLayers map? I would like to stop the user moving the map while I am<br>> loading something else.
<br><br>You could remove the Controls from the map temporarily. If you don't<br>expect them to hit the panzoom buttons, that would be as easy as... er,<br>wait. Apparently we don't have a removeControl method on the map? ack. I
<br>guess that makes sense...<br><br>So, as far as I know, there is no easy way to do this. THe reason is<br>that controls don't tend to unregister their events. You could do<br>something like:<br><br>c = new OpenLayers.Control.MouseDefaults
();<br>map.addControl(c);<br><br>// Want to turn off controls now<br>oldevents = []<br>oldevents['mouseDown'] = c.defaultMouseDown;<br>c.defaultMouseDown = function(){};<br>oldevents['mouseClick'] = c.defaultMouseClick
;<br>c.defaultMouseClick = function() {}<br>...<br><br>// done now<br>c.defaultMouseDown=oldevents['mouseDown'];<br>c.defaultMouseClick = oldevents['mouseClick'];<br><br>It's not pretty, but it is a thought... I'd start from something like
<br>that, and move on. Unfortunately, doing the same thing for the panzoom<br>controller would be much more difficult.<br><br>It sounds like a removeControl method on the map, combined with teaching<br>controls how to clean up after themselves, would be a good idea.
<br><br>Regards,<br>--<br>Christopher Schmidt<br>MetaCarta<br></blockquote></div><br><br clear="all"><br>-- <br>--------------------------------------------------------------<br>Dr Jon Blower Tel: +44 118 378 5213 (direct line)
<br>Technical Director Tel: +44 118 378 8741 (ESSC)<br>Reading e-Science Centre Fax: +44 118 378 6413<br>ESSC Email: <a href="mailto:jdb@mail.nerc-essc.ac.uk">jdb@mail.nerc-essc.ac.uk</a><br>
University of Reading<br>3 Earley Gate<br>Reading RG6 6AL, UK<br>--------------------------------------------------------------