我有一個點擊事件,遠程抓取座標,將它們放置在地圖上,並將它們與折線連接起來。我還有其他點擊事件可以做同樣的事情,但希望將它們保留爲單獨的圖層,以便用戶可以切換以查看他們完成的每個點擊。有誰知道一個好的方法來分別分組來做這個或另一種方法嗎?如何在Google地圖中切換多個疊加層?
這是到目前爲止我的代碼:
drawPoints: function (points, color) {
$.each(points, function (key, val) {
var location = new google.maps.LatLng(val.Latitude, val.Longitude);
MyTest.addMarker(location, val.Name, val.Description);
MyTest.coordinates.push(location);
});
this.path = new google.maps.Polyline({
path: MyATest.coordinates,
strokeColor: color,
strokeOpacity: 1.0,
strokeWeight: 2
});
this.path.setMap(this.googlemap);
},
addMarker: function (location, title, html) {
var marker = new google.maps.Marker({
position: location,
map: this.googlemap,
title: title,
html: html
});
this.markers.push(marker);
},
// Removes the overlays from the map, but keeps them in the array
clearOverlays: function() {
if (this.markers) {
for (i in this.markers) {
this.markers[i].setMap(null);
}
}
},
// Shows any overlays currently in the array
showOverlays: function() {
if (this.markers) {
for (i in this.markers) {
this.markers[i].setMap(map);
}
}
},
Hiya bruv以這個小提琴爲起點,請複製它在這裏:http://jsfiddle.net/fHsAY/ :))有一個不錯的!麥片! –