1
我遇到問題。 我從服務中動態獲取樣式。樣式是數組,並檢查所有工作正常時添加內聯,但是當我動態地獲取數據映射呈現默認樣式。無法在角度谷歌地圖中動態傳遞地圖樣式
例如,以下是我的代碼:
var styleArray = data.settings.Theme.mapSelected;
if(data.settings.Theme.mapSelected != undefined) {
$scope.mapOptions = {
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
styles: styleArray
};
} else {
$scope.mapOptions = {
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
styles: [{"featureType":"landscape","stylers":[{"saturation":-100},{"lightness":65},{"visibility":"on"}]},{"featureType":"poi","stylers":[{"saturation":-100},{"lightness":51},{"visibility":"simplified"}]},{"featureType":"road.highway","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"road.arterial","stylers":[{"saturation":-100},{"lightness":30},{"visibility":"on"}]},{"featureType":"road.local","stylers":[{"saturation":-100},{"lightness":40},{"visibility":"on"}]},{"featureType":"transit","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"administrative.province","stylers":[{"visibility":"off"}]},{"featureType":"water","elementType":"labels","stylers":[{"visibility":"on"},{"lightness":-25},{"saturation":-100}]},{"featureType":"water","elementType":"geometry","stylers":[{"hue":"#ffff00"},{"lightness":-25},{"saturation":-97}]}]
};
}
在這裏,我的HTML
<ui-gmap-google-map center='settings.Location.coords' zoom='12' options='mapOptions' doRebuildAll="true">
<ui-gmap-marker idKey='settings.Content._id' coords='settings.marker.coords'></ui-gmap-marker>
</ui-gmap-google-map>
我得到正確的數據,我可以在檢查看到,當我登錄到控制檯,但地圖不會呈現選定的樣式數組,而是Google的默認值。
任何想法?
ps:if else語句正常工作,並且所有選項以及樣式數組也不是。
更新:如果我通過動態樣式數組內聯它的作品,只有變量它沒有。我tryid直接傳遞數據(data.settings.Theme.mapSelected),但它做了一些事情。
Plnkr:http://plnkr.co/edit/KtvcIoqTaa9HHG5Xc1E6?p=preview