以下是代码。代码导入json lat / lng并从飞机跟踪然后将其显示在带有移动标记的谷歌地图上。我想要做的是添加一个trail / poly line onlick函数,这样当用户点击标记时它会显示它后面的跟踪类似于:(除非它是可行的,否则现在不需要所有颜色:) )fr24.com。提前谢谢。
var infoWindows = {};
var markers = {};
function getIconForPlane(value) {
var r = 255, g = 255, b = 0;
return {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
scale: 5,
fillColor: 'rgb('+r+','+g+','+b+')',
fillOpacity: 0.9,
rotation: value.track
};
}
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(-36.363, 175.044),
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
window.setInterval(readData, 1000);
}
function text(value) {
return '<b>Speed: </b> ' + value.speed + ' <br><b>Flight: </b>' +
value.flight
+
'<br><b>Vertical Rate: </b>' + value.vert_rate +'<br><b>Last radar contact:
</b>' +value.seen +'<b>s</b>';
window.setInterval(text, 1000);
}
function createInfoWindow(value, marker, map) {
var iw = new google.maps.InfoWindow({
content: text(value)
});
google.maps.event.addListener(marker, 'click', function() {
iw.open(map, marker);
});
return iw;
}
function readData() {
$.getJSON
('https://crossorigin.me/http://radar1.ddns.net:3080/data/aircraft.json
', function(data) {
$.each(data.aircraft, function(i, value) {
var myLatlng = new google.maps.LatLng(value.lat, value.lon, value.flight,
value.altitude);
if (markers[value.hex]) {
markers[value.hex].setPosition(myLatlng);
console.log("moving marker for " + value.hex);
infoWindows[value.hex].setContent(text(value));
} else {
// create new
markers[value.hex] = new google.maps.Marker({
position: myLatlng,
icon: getIconForPlane(value),
map: map,
title: "Callsign: " + value.flight + ", Altitude: " + value.altitude
});
console.log("creating marker for " + value.hex);
infoWindows[value.hex] = createInfoWindow(value, markers[value.hex]
,map)
}
});
});
}