Angular Google Map的自定义样式

Custom style for Angular Google Map

本文关键字:自定义 样式 Map Google Angular      更新时间:2023-09-26

我正在使用Angular UI映射,似乎找不到更改样式的选项的指令。谷歌文档给出了一个使用谷歌对象的例子。我尝试过为映射获取ElementById,但是这导致了ui对象的大量错误。

我的控制器有:

$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添加到作用域中,没有更改任何内容,也没有导致任何错误。

添加样式非常简单,只需将它们添加到控制器中即可:

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
};

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