google-maps-api-3

Change Google Maps v3 mapOptions object after load


How can I modify a V3 map's mapOptions after the initial map has been loaded?

Specifically, I would like to be able to flip the

draggable: false

option to

draggable: true

When an action (such as a click on a div) is triggered.

Additionally, I have tried loading jquery-ui-map and using:

$('#map').gmap('option', 'draggable', true);

However this seems to reload the map and forget all the other existing options. I could redefine them all, but that seems a bit hackish.

Any pointers appreciated.

Thanks!


Solution

  • Found that I don't even need jQuery for this – it's already part of the Google Maps API. Simply do:

    map.set('draggable', true);
    

    Too easy! Hope it helps someone.

    2020 update

    You should use:

    map.setOptions({ draggable: true });