Probocop
Probocop

Reputation: 10552

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?

Upvotes: 9

Views: 9064

Answers (2)

Mano Marks
Mano Marks

Reputation: 8819

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

Upvotes: 10

Marcelo
Marcelo

Reputation: 9407

Yes. just use

map.setOptions(mapOptions);

Upvotes: 20

Related Questions