javascript - Googlemaps v3 地面覆盖循环

标签 javascript arrays google-maps-api-3

我编写了一个脚本,将天气 10 雷达 map 加载到数组中,并希望在 Google map 或最后一个图像上显示动画。 我的想法是显示一张图像并在延迟后清除它,然后转到下一张。 我不明白为什么下面的代码失败......有什么猜测吗?

我的测试页:http://www.egloff.eu/rsmaptest/rsmap.php

我的代码:

function nextRadarMap() {
    // delete overlays
    deleteOverlays();
    // push the new images into an array of overlays
    for (i = 0; i < 10; i++) {
        radarMap = new google.maps.GroundOverlay(images[i], boundaries, {
            clickable: false
        });
        imagesArray.push(radarMap);
    }
    // choose to display fixed or animated image  
    if (animToggle == true) {
        l = imagesArray.length;
        for (i = 0; i < l; i++) {
            imagesArray[i].setMap(map);
            // erase previous image. use of modulus to foolproof when i=0
            //setTimeout( function() {imagesArray[(i+l-1)%l].setMap(null)},500);
            setTimeout(function () {
                clearOverlays()
            }, 500);
        }
    } else {
        // display most recent image
        imagesArray[0].setMap(map);
    }
}

// Removes the overlays from the map, but keeps them in the array
function clearOverlays() {
if (imagesArray) {
//   for (i in imagesArray) {
    for (i=0; i<imagesArray.length; i++) {
      imagesArray[i].setMap(null);
    }
  }
}

最佳答案

由于我的问题缺乏解决方案,我改变了策略,用这组图像构建了一个动画 GIF 图像,并将其显示在 groundOverlay 中。像这样:

radarMap = new google.maps.GroundOverlay( "./images/animatedmap.gif", boundaries,{clickable:false});

现在工作正常,结果就是我想要的!

希望这有帮助?

关于javascript - Googlemaps v3 地面覆盖循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24731435/

相关文章:

javascript - 跟踪 URL 中的 Div 导航路径

javascript - jQuery 破坏其他 javascript

javascript - NodeJS 和谐在导入时给出 SyntaxError

arrays - 如何在类之外使用函数

ios - 在 Swift3 iOS 中使用字符串参数对对象数组进行排序

Javascript:生成和存储随机抽取而无需替换

javascript - 允许用户一次只创建一个 Google map 标记

javascript - 带通配符的姓氏正则表达式

javascript - 使用ajax刷新谷歌地图标记和infoBubbles

google-maps - Google api OVER_QUERY_LIMIT - 多长时间