无法找出用于自定义Google地图的js。

时间:2015-04-09 18:24:58

标签: javascript json google-maps customization

当谈到js时,我是新鲜的船。地图显示在原位,但样式不起作用。

它一直告诉我,我主要是代码而没有足够的信息,所以我只是写这个,所以它会消失。

    function initialize() {

        var mapCanvas = document.getElementById('map-canvas');
        var mapOptions = {
          center: new google.maps.LatLng(34.695301,-82.401196),
          zoom: 15,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        }
        var map = new google.maps.Map(mapCanvas, mapOptions)
      }


      google.maps.event.addDomListener(window, 'load', initialize);

          [
  {
    "featureType": "landscape.natural",
    "stylers": [
      { "color": "#2e2d2d" }
    ]
  },{
    "elementType": "labels.text.stroke",
    "stylers": [
      { "visibility": "off" }
    ]
  },{
    "elementType": "labels.text.fill",
    "stylers": [
      { "color": "#facf0b" }
    ]
  },{
    "featureType": "road.local",
    "elementType": "labels.text.fill",
    "stylers": [
      { "color": "#808080" }
    ]
  },{
    "featureType": "road.arterial",
    "elementType": "labels",
    "stylers": [
      { "color": "#808080" }
    ]
  },{
  }
]

1 个答案:

答案 0 :(得分:0)

您需要设置样式

  map.set('styles', [
  {
    featureType: 'road',
    elementType: 'geometry',
    stylers: [
      { color: '#000000' },
      { weight: 1.6 }
    ]
  }]);

使用您创建地图的变量(var map)并设置样式。

示例:

var styles = [
  {
    stylers: [
      { hue: "#00ffe6" },
      { saturation: -20 }
    ]
  },{
    featureType: "road",
    elementType: "geometry",
    stylers: [
      { lightness: 100 },
      { visibility: "simplified" }
    ]
  },{
    featureType: "road",
    elementType: "labels",
    stylers: [
      { visibility: "off" }
    ]
  }
];

map.setOptions({styles: styles});