[英]Hidden labels reappear when switching to satellite view
我已經將自定義樣式應用於Javascript Google Maps API(v3.20)。 我使用的是自定義樣式,該樣式會隱藏除道路和水面以外的所有標簽。 在“地圖”視圖中,標簽會正確隱藏,但是切換到衛星視圖后,標簽會永久顯示(除非您取消選中“衛星視圖”下的復選框)。 這是一個錯誤還是我做錯了什么?
謝謝!
之前 :
http://ss.kobitate.com/images/2015-06-11_1656.png
之后 :
http://ss.kobitate.com/images/2015-06-11_1659.png
碼:
function initialize() {
var mapCanvas = document.getElementById('map-canvas');
var mapOptions = {
zoom: 15,
minZoom: 14,
center: new google.maps.LatLng(32.421205,-81.782044),
mapTypeId: "custom_map"
}
var styleOptions = [
{
featureType: 'all',
elementType: 'labels',
stylers: [
{ visibility: 'off' }
]
},
{
featureType: 'road',
elementType: 'labels',
stylers: [
{ visibility: 'on' }
]
},
{
featureType: 'water',
elementType: 'labels',
stylers: [
{ visibility: 'on' }
]
}
];
var styledMap = {
name: 'Style Customization'
}
map = new google.maps.Map(mapCanvas, mapOptions)
var customMap = new google.maps.StyledMapType(styleOptions, styledMap);
map.mapTypes.set("custom_map", customMap);
}
如果您不希望使用HYBRID映射類型,請將其從可用類型中刪除。
https://developers.google.com/maps/documentation/javascript/maptypes
Google Maps API提供了以下地圖類型:
這將僅使兩個按鈕(周六/您的)並刪除標簽復選框。
var mapOptions = {
zoom: 15,
minZoom: 14,
center: new google.maps.LatLng(32.421205, -81.782044),
mapTypeControlOptions: {
mapTypeIds: [google.maps.MapTypeId.SATELLITE, "custom_map"]
},
mapTypeId: "custom_map"
}
代碼段:
var map; function initialize() { var mapCanvas = document.getElementById('map-canvas'); var mapOptions = { zoom: 15, minZoom: 14, center: new google.maps.LatLng(32.421205, -81.782044), mapTypeControlOptions: { mapTypeIds: [google.maps.MapTypeId.SATELLITE, "custom_map"] }, mapTypeId: "custom_map" } var styleOptions = [{ featureType: 'all', elementType: 'labels', stylers: [{ visibility: 'off' }] }, { featureType: 'road', elementType: 'labels', stylers: [{ visibility: 'on' }] }, { featureType: 'water', elementType: 'labels', stylers: [{ visibility: 'on' }] }]; var styledMap = { name: 'Style Customization' } map = new google.maps.Map(mapCanvas, mapOptions) var customMap = new google.maps.StyledMapType(styleOptions, styledMap); map.mapTypes.set("custom_map", customMap); } google.maps.event.addDomListener(window, "load", initialize);
html, body, #map-canvas { height: 500px; width: 500px; margin: 0px; padding: 0px }
<script src="https://maps.googleapis.com/maps/api/js"></script> <div id="map-canvas" style="border: 2px solid #3872ac;"></div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.