这似乎是一个愚蠢的问题,但我似乎无法找到答案。如何将图层(如TrafficLayer或KmlLayer)附加到地图的MapTypeControl?
var mapOptions = {
center: new google.maps.LatLng(38.181579, -85.778988),
zoom: 15
mapTypeControlOptions: {
mapTypeIds: [
google.maps.MapTypeId.ROADMAP,
'Traffic'
]
},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var trafLayer = new google.maps.TrafficLayer();
var trafficMapType = // SCIENCE!
map.mapTypes.set('Traffic', trafficMapType);
中间会发生什么?你如何得到trafficMapType
?
答案 0 :(得分:1)
http://code.google.com/apis/maps/documentation/javascript/layers.html#TrafficLayer
流量图层可用作图层而非地图类型。以下Google code网站的示例代码:
var myLatlng = new google.maps.LatLng(34.04924594193164, -118.24104309082031);
var myOptions = {
zoom: 13,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var trafficLayer = new google.maps.TrafficLayer();
trafficLayer.setMap(map);
答案 1 :(得分:1)
查看文档的自定义控件部分: http://code.google.com/apis/maps/documentation/javascript/controls.html#CustomControls
答案 2 :(得分:0)
对于交通图层,我找到了只有交通功能的网址 此URL可用于ImageMapType,以便为主要地图类型提供其他切片。
这就是:
var trafficTile = new google.maps.ImageMapType({
tileSize: new google.maps.Size(256, 256),
name: "Trafico",
getTileUrl: function (coord, zoom){
var s = 'Galileo'.substring(0, (3 * coord.x + coord.y ) & 7 ),
BALANCER = coord.x + coord.y & 1,
path = [
"https://mts" + BALANCER + ".googleapis.com/vt?hl=es-419&src=apiv3&lyrs=m@199000000,traffic|seconds_into_week:-1&style=15",
'z=' + zoom,
'x=' + coord.x,
'y=' + coord.y,
's=' + s
]
;
return path.join('&');
}
});
map.overlayMapTypes.insertAt(0, trafficTile);
您可能想要更改主机语言(hl
param)或设置自定义样式(apistyle
param)