【问题标题】:hide waterways in google maps api在谷歌地图 api 中隐藏水路
【发布时间】:2019-03-15 14:38:39
【问题描述】:

我正在尝试创建一个只有一个国家(在我的例子中是荷兰)可见的地图,并且我想在这张地图上渲染标记。经过一番挖掘,我在这篇文章中找到了解决方案:

Is there a way to display a single country in Google map? It should be only one country, not parts from other countries included

我查看了荷兰的 SVG 地图并为我的目的更改了代码,但我不知道如何从地图中删除水道(如您在此处看到的海中的深蓝色线条: https://www.google.com/maps/@52.4602959,4.5546196,12.92z)

这是我脚本的样式部分:

  var mapOptions = {
    zoom: 8.2,
    center: new google.maps.LatLng(52.043084, 5.0451778),
    mapTypeId: google.maps.MapTypeId.MAP,
    backgroundColor: 'transparent',
    disableDefaultUI: true,
    draggable: true,
    scaleControl: true,
    scrollwheel: true,
    styles: [
      {"featureType": "water", "stylers": [{ "visibility": "off" }]},
      {"featureType": "landscape", "stylers": [{ "visibility": "off" }]},
      {"featureType": "road", "stylers": [{ "visibility": "off" }]},
      {"featureType": "administrative", "stylers": [{ "visibility": "off" }]},
      {"featureType": "poi", "stylers": [{ "visibility": "off" }]},
      {"elementType": "labels", "stylers": [{ "visibility": "off" }]}
    ]
  };
  var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

完整的代码和小提琴可以在这里找到; https://jsfiddle.net/sander_cinnamon/uxejo76b/

谁能告诉我如何删除这些行?

提前非常感谢!

干杯,桑德

【问题讨论】:

    标签: google-maps


    【解决方案1】:

    水路的 featureType 是“transit”,但删除这些也会删除所有的中转站和线路。

    代码如下:

      styles:[
          {
            "featureType": "transit.line",
            "elementType": "geometry",
            "stylers": [
              {
                "visibility": "off"
              }
            ]
          },
          {
            "featureType": "transit.line",
            "elementType": "labels",
            "stylers": [
              {
                "visibility": "off"
              }
            ]
          }
        ]
    

    此外,使用地图样式向导可以帮助设置地图特征的样式:https://mapstyle.withgoogle.com/

    【讨论】:

    • 谢谢你,Waren,它就像一个魅力!我还为样式向导添加了书签以供将来使用;-)
    猜你喜欢
    • 2011-11-15
    • 1970-01-01
    • 1970-01-01
    • 2012-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多