2012-02-21 125 views
7

我已經在谷歌地圖上放置了一個自定義地圖png。我已經從谷歌地圖中刪除了所有內容,只顯示我的自定義地圖。背景顏色是淺藍色,我想將其更改爲白色。這裏是代碼:谷歌地圖api v3背景色

function initialize() { 

    var myLatLng = new google.maps.LatLng(39, -98.5); 
    var myOptions = { 
    maxZoom: 4, 
    minZoom: 4, 
    zoom: 4, 

    panControl: false, 
    draggable: false, 
     center: myLatLng, 
    disableDefaultUI: true, 
     mapTypeId: google.maps.MapTypeId.ROADMAP, 
    backgroundColor: '#FFFFFF' 
    }; 

    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
    var mapStyles = [ 
    { 
    featureType: "all", 
    stylers: [ 
     { visibility: "off" }] 
    }]; 

map.setOptions({styles: mapStyles}); 
} 

它只閃爍白色然後變成淡藍色。我如何將它設置爲白色或透明?

回答

8

儘管您刪除了仍然存在空白圖塊的所有內容。

您可能試圖隱藏這些瓷磚,下面的CSS工作對我來說:

/*the desired background for the map*/ 
#map_canvas{background-color:#fff !important} 

    /*hides the tiles (and maybe more^^)*/ 
#map_canvas div div div div div div img{visibility:hidden} 
+0

感謝那些工作。 – rstewart 2012-02-21 14:05:58

+0

非常好,感謝這 – Gaelen 2014-05-14 17:15:18

11

您可以只設置backgroundColor: 'none'

var map = new google.maps.Map(document.getElementById('map'), { 
    zoom: 11, 
    center: {lat: 41.876, lng: -87.624}, 
    backgroundColor: 'none' 
    }); 
+0

谷歌爲什麼要添加這個愚蠢的bg顏色 – SuperUberDuper 2016-07-20 15:37:20