我正在尝试在谷歌地图上实现循环雷达动画。此网站:http://mesonet.agron.iastate.edu/ogc/提供从当前时间到60分钟前的雷达图像。
目前,我正在加载这些图像并使用计时器将每个图像添加/删除到地图。这在技术上有效,但结果非常不稳定。有可观的时间地图上没有雷达图像可见。降低超时,只会使效果恶化,因为雷达图像在移除之前没有足够的时间加载。
是否有任何技术可以平滑动画?或者我是不是错了?
代码
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);
}
答案 0 :(得分:9)
希望这有助于其他人,下面是我最终解决问题的方法。我没有添加/删除叠加图像,只是改变了不透明度。这给了我一个更平滑的动画。以下示例将循环显示雷达图像的最后30分钟。
var map;
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.00,
name : 'NEXRAD',
isPng: true,
});
map.overlayMapTypes.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.00,
name : 'NEXRAD5',
isPng: true,
});
map.overlayMapTypes.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.00,
name : 'NEXRAD10',
isPng: true,
optimized: false
});
map.overlayMapTypes.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.00,
name : 'NEXRAD15',
isPng: true,
});
map.overlayMapTypes.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.00,
name : 'NEXRAD20',
isPng: true,
});
map.overlayMapTypes.push(tileNEX20);
tileNEX25 = new google.maps.ImageMapType({
getTileUrl: function(tile, zoom) {
return "http://mesonet.agron.iastate.edu/cache/tile.py/1.0.0/nexrad-n0q-900913-m25m/" + zoom + "/" + tile.x + "/" + tile.y +".png?"+ (new Date()).getTime();
},
tileSize: new google.maps.Size(256, 256),
opacity:0.00,
name : 'NEXRAD25',
isPng: true,
});
map.overlayMapTypes.push(tileNEX25);
tileNEX30 = new google.maps.ImageMapType({
getTileUrl: function(tile, zoom) {
return "http://mesonet.agron.iastate.edu/cache/tile.py/1.0.0/nexrad-n0q-900913-m30m/" + zoom + "/" + tile.x + "/" + tile.y +".png?"+ (new Date()).getTime();
},
tileSize: new google.maps.Size(256, 256),
opacity:0.00,
name : 'NEXRAD30',
isPng: true,
});
map.overlayMapTypes.push(tileNEX30);
animateRadar();
}
google.maps.event.addDomListener(window, 'load', initialize);
function animateRadar() {
var index = map.overlayMapTypes.getLength() - 1;
window.setInterval(function(){
map.overlayMapTypes.getAt(index).setOpacity(0.00);
index--;
if(index < 0){
index = map.overlayMapTypes.getLength() - 1;
}
map.overlayMapTypes.getAt(index).setOpacity(0.60);
}, 400);
}
}
答案 1 :(得分:0)
问题你知道如果缩放是12
,这个网站mesonet是否在较小的级别有某种平滑的层除非我可以用
循环播放动画答案 2 :(得分:0)
不是一个答案,并且对此表示遗憾,但无论如何还要显示其他叠加(比如任何一张GOES图像)而不实际“动画”它们?
基本上我有代码看起来像(然后我用jQuery控制show / hide与选择器):
overlayMaps = [{
//NEXRAD
getTileUrl: function(tile, zoom) {
return "http://mesonet.agron.iastate.edu/cache/tile.py/1.0.0/nexrad-n0r-900913/" + zoom + "/" + tile.x + "/" + tile.y + ".png?" + (new Date()).getTime();
},
tileSize: new google.maps.Size(256, 256),
opacity: 0.60,
name: 'NEXRAD',
isPng: true
}, {
//MRMS Hybrid-Scan Reflectivity Composite
getTileUrl: function(tile, zoom) {
return "http://mesonet.agron.iastate.edu/cache/tile.py/1.0.0/q2-hsr-900913/" + zoom + "/" + tile.x + "/" + tile.y + ".png?" + (new Date()).getTime();
},
tileSize: new google.maps.Size(256, 256),
opacity: 0.60,
name: 'GOES Water Vapor',
isPng: true
}, {
//GOESVIS
getTileUrl: function(tile, zoom) {
return "http://mesonet.agron.iastate.edu/cache/tile.py/1.0.0/goes-vis-1km-900913/" + zoom + "/" + tile.x + "/" + tile.y + ".png?" + (new Date()).getTime();
},
tileSize: new google.maps.Size(256, 256),
opacity: 0.60,
name: 'GOES Visible',
isPng: true
}, {
//GOESIR
getTileUrl: function(tile, zoom) {
return "http://mesonet.agron.iastate.edu/cache/tile.py/1.0.0/goes-ir-4km-900913/" + zoom + "/" + tile.x + "/" + tile.y + ".png?" + (new Date()).getTime();
},
tileSize: new google.maps.Size(256, 256),
opacity: 0.60,
name: 'GOES Infrared',
isPng: true
}, {
//GOESWaterVapor
getTileUrl: function(tile, zoom) {
return "http://mesonet.agron.iastate.edu/cache/tile.py/1.0.0/goes-wv-4km-900913/" + zoom + "/" + tile.x + "/" + tile.y + ".png?" + (new Date()).getTime();
},
tileSize: new google.maps.Size(256, 256),
opacity: 0.9,
name: 'GOES Water Vapor',
isPng: true
}];
$('.overlay_layer').click(function() {
var layerID = parseInt($(this).attr('id'));
if ($(this).hasClass('active')) {
$(this).removeClass('active');
if (map.overlayMapTypes.getLength() > 0) {
map.overlayMapTypes.setAt(layerID, null);
}
} else {
$(this).addClass('active');
var overlayMap = new google.maps.ImageMapType(overlayMaps[layerID]);
map.overlayMapTypes.setAt(layerID, overlayMap);
}
});
for (i = 0; i < overlayMaps.length; i++) {
var overlayMap = new google.maps.ImageMapType(overlayMaps[00]);
map.overlayMapTypes.setAt(00, overlayMap);
//map.overlayMapTypes.push(null);
}
问题来自于这个事实,我似乎无法找到一种方法来只选择某些瓷砖来实际制作动画而不是map.overlayMapTypes.getLength()
中的每个叠加层。