2014-01-28 79 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' } 
    ] 
}