【问题标题】:Can't figure out js for customizing google map.无法弄清楚用于自定义谷歌地图的 js。
【发布时间】:2015-04-09 18:24:57
【问题描述】:

谈到 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" }
    ]
  },{
  }
]

【问题讨论】:

    标签: javascript json google-maps customization


    【解决方案1】:

    你需要设置样式

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

    【讨论】:

    • 它不工作。我认为我没有将代码放在正确的位置。
    猜你喜欢
    • 2015-08-11
    • 2020-11-07
    • 1970-01-01
    • 2020-01-02
    • 2017-09-27
    • 2020-03-26
    • 2011-07-06
    • 1970-01-01
    • 2013-05-19
    相关资源
    最近更新 更多