2013-03-04 72 views
0

我試圖更改此Google地圖實例的飽和度。除飽和風格外,其他所有工作都在進行中。我究竟做錯了什麼 ?似乎無法將樣式應用於Google MAP API

代碼:

$(function() { // when the document is ready to be manipulated. 
    if (GBrowserIsCompatible()) { // if the browser is compatible with Google Map's 
     var map = document.getElementById("myMap"); // Get div element 
     var m = new GMap2(map); // new instance of the GMap2 class and pass in our div location. 

     m.setCenter(new GLatLng(59.334951,18.088598), 13); // pass in latitude, longitude, and zoom level. 
     m.openInfoWindow(m.getCenter(), document.createTextNode("Looking Good")); // displays the text 
     m.setMapType(G_NORMAL_MAP); // sets the default mode. G_NORMAL_MAP, G_HYBRID_MAP 

     // var c = new GMapTypeControl(); // switch map modes 
     // m.addControl(c); 

     // m.addControl(new GLargeMapControl()); // creates the zoom feature 

     var styleArray = [ 
      { 
       featureType: "all", 
       stylers: [ 
        {saturation: -80} 
       ] 
      } 
     ]; 
    } 
    else { 
     alert("Upgrade your browser, man!"); 
    } 
}); 

我一直在尋找了一整天(和失敗),以找到一個解決這個問題。

回答

0

你有這樣一行:

m.setOptions({styles: styleArray}); 

聲明瞭造型後的地方?上面的這一行將把你創建的樣式應用到你的地圖上。

+0

嗨肖娜,沒了,但我想將它添加貝婁風格,在結果 像這樣沒有變化: VAR styleArray = [ { 類型特徵: 「所有」, 造型器:[ {飽和度: -80} ] } ]; m.setOptions({styles:styleArray}); – user2132052 2013-03-04 14:46:44

+0

檢查您的瀏覽器的開發人員工具控制檯,看看是否有任何JS錯誤。 – Shauna 2013-03-04 14:50:07

0

看起來像你的styleArray從未使用過。

0

感謝您的幫助,我終於明白了。感覺有點愚蠢,但「m.setOtions」顯然是V3 API的一個功能,我使用的是V2。

相關問題