谷歌地图动画ImageMapType叠加



我一直在阅读和研究如何动画叠加。我没有找到任何与我要找的有关的东西。它主要与标记有关。我有一个像这样的叠加,效果很好。

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
});

数据来源还提供了其他10个过去的图像。所以我想用这些提要创建一个动画循环。这个选项在V3中可用吗?因为我读到过这样做的一些冲突。我的意思是,这肯定是可能的,因为我见过其他人也有这种情况。我该如何加载多个图层然后制作动画呢?

-谢谢!

我知道这是旧的,但我希望这有助于其他人寻找同样的东西。这可能不是最优雅的解决方案,但它完成了任务。我简单地映射到预定义的图像url上,创建我的ImageMapTypes,然后将其传递到动画循环中,动画循环检查地图上是否有图层,如果有则清除,然后根据循环计数设置新图层。希望对你有帮助。

var map;
// Weather tile url from Iowa Environmental Mesonet (IEM): http://mesonet.agron.iastate.edu/ogc/
var urlTemplate = 'http://mesonet.agron.iastate.edu/cache/tile.py/1.0.0/nexrad-n0q-{timestamp}/{zoom}/{x}/{y}.png';
// The time stamps values for the IEM service for the last 50 minutes broken up into 5 minute increments.
var timestamps = ['900913-m50m', '900913-m45m', '900913-m40m', '900913-m35m', '900913-m30m', '900913-m25m', '900913-m20m', '900913-m15m', '900913-m10m', '900913-m05m', '900913'];
function initMap() {
  map = new google.maps.Map(document.getElementById('map'), {
    center: {lat: 38.0781, lng: -97.7030},
    zoom: 5
  });
  let tileSources = timestamps.map((timestamp) => {
    return new google.maps.ImageMapType({
      getTileUrl: function(tile, zoom) {
          const { x, y} = tile;
          return `https://mesonet.agron.iastate.edu/cache/tile.py/1.0.0/nexrad-n0q-${timestamp}/${zoom}/${x}/${y}.png?`+ (new Date()).getTime();
      },
      tileSize: new google.maps.Size(256, 256),
      opacity:0.60,
      name : 'NEXRAD',
      isPng: true
    });
  });
  startAnimation(map, tileSources);
}
function startAnimation(map, layers) {
  // create empty overlay entry
  map.overlayMapTypes.push(null);
  var count = 0;
  window.setInterval(() => {
    if(map.overlayMapTypes.getLength() > 0)
      map.overlayMapTypes.clear();
    map.overlayMapTypes.setAt("0",layers[count]);
    count = (count + 1) % layers.length;          
  },800);
}

最新更新