Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change Google Map styles after the map has been initialised?

I understand how to initialise a map with custom styles like the following:

var styles =   [
    {
      featureType: "water",
      stylers: [
        { visibility: "on" },
        { color: "#ffffff" }
      ]
    }
  ];

var mapOptions = {
      zoom: 13,
      maxZoom: 15,
      minZoom: 12,
      center: new google.maps.LatLng(50.924229,-1.396841),
      disableDefaultUI: true,
      mapTypeId: google.maps.MapTypeId.ROADMAP
      styles: styles
    };
    map = new google.maps.Map(document.getElementById('map'), mapOptions);

But is it possible to change to another style once the map has already been initialised? For example changing the colours of the map when certain events are triggered?

like image 870
Probocop Avatar asked Aug 08 '12 13:08

Probocop


2 Answers

Yes, create a new style object and then change the style by setting the option: map.setOptions({styles: styles});

like image 83
Mano Marks Avatar answered Jan 01 '23 19:01

Mano Marks


Yes. just use

map.setOptions(mapOptions);
like image 35
Marcelo Avatar answered Jan 01 '23 21:01

Marcelo