0

I need to prevent panning and zooming initially when loading my google map. Only when all my markers have been loaded and fitbounds called, should the user be allowed to control the view. What's the best way of toggling this?

jenswirf
  • 7,087
  • 11
  • 45
  • 65

2 Answers2

2

When you create the map you turn off all the controls that you dont want active and then when you have added your markers you can call map.setOptions and pass in what you want to activate:

map.setOptions({
   panControl: true,
   zoomControl: true
});
PiTheNumber
  • 22,828
  • 17
  • 107
  • 180
Manatok
  • 5,506
  • 3
  • 23
  • 32
  • No, I can't this is now my question ;) – PiTheNumber Feb 29 '12 at 09:26
  • Well, actually, it doesn't work, it toggles the controls, not the "control" of the map. Bad choice of words by me I guess. I want to stop panning and zooming completely. Including using mousewheel or touch gestures on a mobile device. – jenswirf Feb 29 '12 at 14:57
1

There are lots of map options you can set, including

  • disableDefaultUI
  • disableDoubleClickZoom
  • draggable
  • keyboardShortcuts
  • overviewMapControl
  • scrollwheel

-- just set to true or false as required. disableDefaultUI removes a lot of controls so they can't be used, but you still need to take care of dragging, wheel-zoom, etc.

Andrew Leach
  • 12,945
  • 1
  • 40
  • 47
  • http://www.acleach.me.uk/gmaps/v3/helloworld.htm works in Firefox under Windows and in Safari on my iPad (or rather, it doesn't! It's entirely static). I had to remove POIs so they couldn't be clicked, so because it's now a styled map it's subject to daily usage limits. If you're not worried out clickable POIs you don't need the style and can just disable bits of the UI. – Andrew Leach Mar 01 '12 at 13:39