从样式化的Google地图中删除室内地图

时间:2014-01-28 20:35:12

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

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

这是我的代码:

<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' }
]

4 个答案:

答案 0 :(得分:3)

我发现实现此目的的唯一方法是禁用所有内容,然后在样式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 */

]

答案 1 :(得分:1)

以下对我有用:

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

答案 2 :(得分:0)

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

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

答案 3 :(得分:0)

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