初始化地图后,是否可以更改Google Map的样式? [英] Is it possible to change Google Map styles after the map has been initialised?

查看:64
本文介绍了初始化地图后,是否可以更改Google Map的样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解如何使用以下自定义样式初始化地图:

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?

推荐答案

是.只需使用

map.setOptions(mapOptions);

这篇关于初始化地图后,是否可以更改Google Map的样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆