Tôi đang cố gắng triển khai hoạt ảnh radar lặp trên bản đồ google. Trang web này: http://mesonet.agron.iastate.edu/ogc/ cung cấp hình ảnh ra-đa từ thời điểm hiện tại đến 60 phút trước.Vòng radar thời tiết trên API Google Maps 3
Hiện tại, tôi đang tải những hình ảnh này và sử dụng bộ hẹn giờ để thêm/xóa từng hình ảnh vào bản đồ. Kỹ thuật này hoạt động, nhưng kết quả là rất hay thay đổi. Có thời gian đáng chú ý khi không có hình ảnh ra-đa có thể hiển thị trên bản đồ. Giảm thời gian chờ, chỉ làm trầm trọng thêm hiệu ứng vì hình ảnh ra-đa không có đủ thời gian để tải trước khi bị xóa.
Có kỹ thuật nào để làm nổi bật hoạt ảnh không? Hoặc tôi đang đi về điều này tất cả các sai?
Mã
var map;
var imageArray = [];
function initialize() {
var mapOptions = {
zoom: 5,
center: new google.maps.LatLng(42.5, -95.5),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
//Load Images and add them to imageArray
tileNEX = new google.maps.ImageMapType({
getTileUrl: function(tile, zoom) {
return "http://mesonet.agron.iastate.edu/cache/tile.py/1.0.0/nexrad-n0q-900913/" + zoom + "/" + tile.x + "/" + tile.y +".png?"+ (new Date()).getTime();
},
tileSize: new google.maps.Size(256, 256),
opacity:0.60,
name : 'NEXRAD',
isPng: true,
});
imageArray.push(tileNEX);
tileNEX5 = new google.maps.ImageMapType({
getTileUrl: function(tile, zoom) {
return "http://mesonet.agron.iastate.edu/cache/tile.py/1.0.0/nexrad-n0q-900913-m05m/" + zoom + "/" + tile.x + "/" + tile.y +".png?"+ (new Date()).getTime();
},
tileSize: new google.maps.Size(256, 256),
opacity:0.60,
name : 'NEXRAD5',
isPng: true,
});
imageArray.push(tileNEX5);
tileNEX10 = new google.maps.ImageMapType({
getTileUrl: function(tile, zoom) {
return "http://mesonet.agron.iastate.edu/cache/tile.py/1.0.0/nexrad-n0q-900913-m10m/" + zoom + "/" + tile.x + "/" + tile.y +".png?"+ (new Date()).getTime();
},
tileSize: new google.maps.Size(256, 256),
opacity:0.60,
name : 'NEXRAD10',
isPng: true,
optimized: false
});
imageArray.push(tileNEX10);
tileNEX15 = new google.maps.ImageMapType({
getTileUrl: function(tile, zoom) {
return "http://mesonet.agron.iastate.edu/cache/tile.py/1.0.0/nexrad-n0q-900913-m15m/" + zoom + "/" + tile.x + "/" + tile.y +".png?"+ (new Date()).getTime();
},
tileSize: new google.maps.Size(256, 256),
opacity:0.60,
name : 'NEXRAD15',
isPng: true,
});
imageArray.push(tileNEX15);
tileNEX20 = new google.maps.ImageMapType({
getTileUrl: function(tile, zoom) {
return "http://mesonet.agron.iastate.edu/cache/tile.py/1.0.0/nexrad-n0q-900913-m20m/" + zoom + "/" + tile.x + "/" + tile.y +".png?"+ (new Date()).getTime();
},
tileSize: new google.maps.Size(256, 256),
opacity:0.60,
name : 'NEXRAD20',
isPng: true,
});
imageArray.push(tileNEX20);
animateRadar(imageArray);
}
google.maps.event.addDomListener(window, 'load', initialize);
function animateRadar(images) {
map.overlayMapTypes.push(images[0]);//Add first image
var index = 0;
window.setInterval(function(){
map.overlayMapTypes.pop();//Remove previous image
index++;
if(index >= images.length){
index = 0;
}
map.overlayMapTypes.push(images[index]);//Add new image
}, 1000);
}
Công trình này hoàn hảo! Nó sẽ tự động cập nhật như những ngày trôi qua, hoặc bạn phải đặt trong một khoảng thời gian làm mới trên trang? – Pat
Gạch thời tiết sẽ cần phải được làm mới. – schn0573