2014-01-28 75 views
5

我试图制作一个风格化的谷歌地图,只有波士顿地铁线路,土地和水。我把所有东西的可见性都设置为关闭,但是一些建筑物仍然显示出来,它看起来像是唯一带有室内地图的建筑物。从风格化的谷歌地图中删除室内地图

这里是我的代码:

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

如果你找到了解决这个,请张贴的答案,标记为已解决。 – Gady

+0

我从来没有找到解决方案。 – shaunutter

回答

0

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

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

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 */ 

] 
+0

就像我说的,这很有效,但它也使我的过境层变得不受欢迎,而且我需要有色地铁线路的过境层。 – shaunutter

0

我在哪里,如果我放大以几乎相同的问题,interiors of buildings开始显示与样式发生冲突我已经定下了。我能够解决这个问题,并通过使用Google的Style Map Wizard来摆脱内饰,并开始添加一个关闭所有内容的图层。然后逐层添加我需要的东西(道路几何图形,景观等)。

1

以下为我工作:

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