我試圖製作一個風格化的谷歌地圖,只有波士頓地鐵線路,土地和水。我把所有東西的可見性都設置爲關閉,但是一些建築物仍然顯示出來,它看起來像是唯一帶有室內地圖的建築物。從風格化的谷歌地圖中刪除室內地圖
這裏是我的代碼:
<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' }
]
如果你找到了解決這個,請張貼的答案,標記爲已解決。 – Gady
我從來沒有找到解決方案。 – shaunutter