我以下面的地圖爲基礎。這是一個非常規則的地圖。根據情況更改Maps API樣式
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 2,
center: {lat: 23.9096187, lng: -29.6761281},
mapTypeId: google.maps.MapTypeId.SATELLITE,
disableDefaultUI: true
});
}
但是!如果某個條件成立,我想實現這些樣式(例如,如果var temp> 80,請添加此樣式)。這可能嗎?
{
stylers: [
{hue: '#890000'},
{visibility: 'simplified'},
{gamma: 0.5},
{weight: 0.5}
]
},
{
elementType: 'labels',
stylers: [{visibility: 'off'}]
},
{
featureType: 'water',
stylers: [{color: '#890000'}]
}
], {
name: 'Custom Style'
});
var customMapTypeId = 'custom_style';
map.mapTypes.set(customMapTypeId, customMapType);
map.setMapTypeId(customMapTypeId);
。當然您可以動態地改變風格。你做了什麼沒有奏效? – geocodezip