2013-03-04 56 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。