【问题标题】:Remove indoor maps from styled Google Maps从风格化的 Google 地图中删除室内地图
【发布时间】:2014-01-28 20:35:11
【问题描述】:

我正在尝试仅使用波士顿地铁线路、土地和水来制作风格化的谷歌地图。我将所有内容的可见性设置为关闭,但仍有一些建筑物出现,而且它看起来像是唯一带有室内地图的建筑物。

这是我的代码:

<html>

<head>
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript">

    var lat = 42.3581;
    var long = -71.0636;
    google.maps.visualRefresh = true;

    function initialize()
    {
        var mapStyle =
        [
            {
                featureType: 'administrative',
                elementType: 'all',
                stylers:
                [
                    { visibility: 'off' }
                ]
            },
            {
                featureType: 'landscape',
                elementType: 'all',
                stylers:
                [
                    { visibility: 'off' }
                ]
            },
            {
                featureType: 'poi',
                elementType: 'all',
                stylers:
                [
                    { visibility: 'off' }
                ]
            },
            {
                featureType: 'road',
                elementType: 'all',
                stylers:
                [
                    { visibility: 'off' }
                ]
            },
            {
                featureType: 'transit',
                elementType: 'all',
                stylers:
                [
                    { visibility: 'off' }
                ]
            },
            {
                featureType: 'water',
                elementType: 'all',
                stylers:
                [
                    { visibility: 'off' }
                ]
            },
            {
                featureType: 'landscape',
                elementType: 'geometry',
                stylers:
                [
                    { color: '#ffffff' },
                    { visibility: 'on' }
                ]
            },
            {
                featureType: 'water',
                elementType: 'geometry',
                stylers:
                [
                    { color: '#e5e5e5' },
                    { visibility: 'on' }
                ]
            }
        ];

        var mapOptions =
        {
            center: new google.maps.LatLng(lat, long),
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            zoom: 16,
            backgroundColor: '#ffffff',
            streetViewControl: false,
            mapTypeControl: false,
            panControl: false,
            zoomControl: false,
            scrollwheel: true,
            draggable: true
        };

        var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
        var transitLayer = new google.maps.TransitLayer();
        transitLayer.setMap(map);
        var styledMapOptions = {name: 'Map'};
        var newMapType = new google.maps.StyledMapType(mapStyle, styledMapOptions);
        map.mapTypes.set('stylized', newMapType);
        map.setMapTypeId('stylized');

        onResize();
    }

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

    function onResize()
    {
        document.getElementById("map-canvas").style.height = window.innerHeight - document.getElementById("map-canvas").getBoundingClientRect().top + 24 +"px";
    }

    </script>

</head>

<body onResize="onResize()">
    <div id="map-canvas"/>
</body>

</html>

我也试过这个,但它也关闭了我的交通层,我需要彩色地铁线路的交通层:

featureType: 'all',
elementType: 'all',
stylers:
[
    { visibility: 'off' }
]

【问题讨论】:

  • 如果您找到了解决此问题的方法,请发布答案并标记为已解决。
  • 我从未找到解决方案。

标签: google-maps google-maps-api-3


【解决方案1】:

我发现实现这一点的唯一方法是禁用所有内容,然后在样式 json 中将每个主要样式部分放回可见。

您可以使用以下作为重置样式的 json 来移除室内地图

[
  {"stylers": [ {"visibility": "off" } ] },
  {"featureType": "water","stylers": [{"visibility": "on"} ] },
  {"featureType": "poi","stylers": [ {"visibility": "on"} ]},
  {"featureType": "transit","stylers": [{ "visibility": "on"}] },
  { "featureType": "landscape","stylers": [ { "visibility": "on" } ] },
  { "featureType": "road", "stylers": [{ "visibility": "on" } ] },
  { "featureType": "administrative",  "stylers": [{ "visibility": "on" } ] },
  /* followed by your style if you have specific styles
    , otherwise remove the last comma */

]

【讨论】:

  • 就像我说的,这行得通,但它也关闭了我的交通层,我需要彩色地铁线路的交通层。
【解决方案2】:

以下内容对我有用:

{
    featureType: 'indoor',
    stylers:
    [
        { visibility: 'off' }
    ]
}

【讨论】:

    【解决方案3】:

    截至本回复,无法禁用室内地图。它尚未添加到样式 API。

    但是,如上所述,禁用所有几何图形也会删除室内地图。

    【讨论】:

      【解决方案4】:

      我遇到了同样的问题,如果我放大太多,interiors of buildings 开始显示与我设置的样式冲突。我能够通过使用 Google 的Style Map Wizard 来解决这个问题并摆脱内饰,并首先添加一个关闭所有功能的图层。然后逐层添加我需要的东西(道路几何、景观等)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多