我想知道您是否可以像在 styledmaptype 上那样更改混合 map 类型的功能。我问这个是因为我想显示仅包含国家边界、没有道路城市名称等的卫星 map (或更改后的混合 map )。
提前致谢!
最佳答案
您可以观察 map 的maptypeid_changed事件。
使用 getMapTypeId() 检查当前的 mapTypeId,如果它等于 google.maps.MapTypeId.HYBRID
,则使用 map.setOptions()
{
featureType: "all",
elementType: "labels",//hides all labels
stylers: [
{ visibility:'off' }
]
},
{
featureType: "road",//hides the roads
stylers: [
{ visibility:'off' }
]
}
当mapTypeId不是google.maps.MapTypeId.HYBRID
时,应用相同的样式,但将两个可见性样式器设置为on
最终它可能看起来像这样:
google.maps.event.addListener(map, 'maptypeid_changed', function() {
var onoff=(this.getMapTypeId()==google.maps.MapTypeId.HYBRID)
?'off'
:'on';
this.setOptions(
{
styles:[{
featureType: "all",
elementType: "labels",
stylers: [{ visibility:onoff }]
},
{
featureType: "road",
stylers: [{ visibility:onoff}]}
]
}
);
});
google.maps.event.trigger(map,'maptypeid_changed');
关于google-maps-api-3 - 是否可以将混合 map 类型更改为 StyledMapType?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9501044/