gpt4 book ai didi

javascript - Angular 谷歌地图的自定义样式

转载 作者:数据小太阳 更新时间:2023-10-29 04:05:14 24 4
gpt4 key购买 nike

我正在使用 Angular UI map 似乎无法找到更改样式选项的指令。 Googles documention给出了一个使用 google 对象的例子。我为 map 尝试了 getElementById,但这会导致 ui 对象出现过多错误。

我的 Controller 有:

$scope.map = { center: { latitude: 42.99, longitude: -81.255 }, zoom: 14, bounds: {}}; 

而 HTML 是:

<div id="map_canvas">
<ui-gmap-google-map id='customMap' center="map.center" zoom="map.zoom" draggable="true" options="options" bounds="map.bounds">
<ui-gmap-markers models="eventMarkers" coords="'self'" idKey="'id'" icon="'icon'" click="'onClick'">
<ui-gmap-windows show="show">
<div ng-non-bindable>{{content}}</div>
</ui-gmap-windows>
</ui-gmap-markers>
</ui-gmap-google-map>
</div>

用适当的代码向作用域添加 style 的简单尝试,没有改变任何东西,也没有导致任何错误。

最佳答案

添加样式非常简单,只需像这样将它们添加到您的 Controller 中即可:

var styleArray = [ //any style array defined in the google documentation you linked
{
featureType: "all",
stylers: [
{ saturation: -80 }
]
},{
featureType: "road.arterial",
elementType: "geometry",
stylers: [
{ hue: "#00ffee" },
{ saturation: 50 }
]
},{
featureType: "poi.business",
elementType: "labels",
stylers: [
{ visibility: "off" }
]
}
];
$scope.options = {
styles: styleArray
};

其他一切都可以与上面的代码保持一致。

关于javascript - Angular 谷歌地图的自定义样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28463667/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com