English 中文(简体)
设置一个样式式的映像类型, 将它设置为覆盖版式的映像类型
原标题:set a StyledMapType as an overlayMapType

我创建了一个自定义样式马普图案, 并将其插入 Google.maps.overlayMapType 中, 以便在另一层上绘制此自定义地图 。 不幸的是, 我有一个 javascript 错误信息 :

Uncaught TypeError: Cannot call method apply of undefined main.js:9
(anonymous function) main.js:9
d
L main.js:9
du
H.$
(anonymous function)

这是我在浏览器里执行的代码:

function initialize() {
  var pinkParksStyles = [
  {
    featureType: "all",
    stylers: [
      { saturation: -80 }
    ]
  },
  {
    featureType: "poi.park",
    stylers: [
      { hue: "#ff0023" },
      { saturation: 40 }
    ]
  }
  ];
  var pinkMapType = new google.maps.StyledMapType(pinkParksStyles,
    {name: "Pink Parks"});

  var mapOptions = {
    zoom: 11,
    center: new google.maps.LatLng(55.6468, 37.581),
    mapTypeControlOptions: {
      mapTypeIds: [google.maps.MapTypeId.ROADMAP]
    }
  };
  var map = new google.maps.Map(document.getElementById( map_canvas ),
    mapOptions);

  //Insert styled map in overlayMapTypes.
  map.overlayMapTypes.insertAt(0, pinkMapType);
  map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
}

To see a full example, here is a link on jsfiddle code: http://jsfiddle.net/X5r8r/460/ You can notice in this example that the styled map works as a mapType but not as an overlayMapType.

Thanks, François

问题回答

First, I m not sure why you would want to do this. Wouldn t it be easier to style a base maptype? https://developers.google.com/maps/documentation/javascript/styling#styling_the_default_map

Basically, when you create a maptype to be used in overlayMapTypes it needs to have getTile defined. Check out the documentation here: https://developers.google.com/maps/documentation/javascript/maptypes#OverlayMapTypes a StyledMap doesn t expose that.





相关问题
Why do I get "map.set_center is not a function"?

This code have been working until I updated last night. The code works perfectly on my localhost, but I get an error on my test server. The error message (from Firebug) is "map.set_center is not a ...

The state of GMaps v3

I m about to start a Google map based project and am wondering if the release version of GMaps v3 has most of the features that are available in v2, or if it would be best to stick with v2 for now. Is ...

Bouncy marker in Google Maps v3

In Google Maps API v2 we can set to marker an option bouncy:true. It adds to marker eye-candy ability - after dragging this marker, it is bouncing. Is it possible to do in API v3 ?

GUnload() a single Google Map

I ve got some Javascript/HTML code which displays a variable number of maps dependent on what the user selects. I ve worked how to dynamically create multiple maps on a page - that s well documented. ...

How to change Gmap markers color?

I ve a custom google map with different points: Markers[0] = new Array(new GMarker(new GLatLng(45.0, 9.0)), "Location1", "<strong>Address Line</strong><br/>Some information"); ...

热门标签