自定义样式的Angular Google地图

8

我正在使用Angular UI地图,但似乎找不到可以更改样式选项的指令。Google的文档给出了一个使用Google对象的示例。我尝试使用getElementById获取地图,但这导致了大量与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,但没有改变任何内容或引起任何错误。

1个回答

15

添加样式非常简单,只需像这样将它们添加到您的控制器中:

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

其余部分可以与您上面的代码保持相同。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接