Javascript或jQuery png播放器

Javascript或jQuery png播放器,javascript,jquery,map,Javascript,Jquery,Map,我正在使用一个名为传单的绘图应用程序。我使用的一些代码如下: var layer1 =L.tileLayer('http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/7540/256/{z}/{x}/{y}.png', { attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a>

我正在使用一个名为传单的绘图应用程序。我使用的一些代码如下:

var layer1 =L.tileLayer('http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/7540/256/{z}/{x}/{y}.png', {
    attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>',
    maxZoom: 12

}).addTo(map);
createVariables()如下所示:

function createVariables(){
  var radar_images = [];

  for (var i = 0; i <= 99; ++i) {
      radar_images[i] = L.tileLayer('http://tile2.aerisapi.com/QjvmoFnKc1Wj94aDULEX_8Y7R8eagwQKlUusR5WZk6JTBdz6zlCm3KIP15CLG/radar/{z}/{x}/{y}/'+data.files[i].time +'.png', {opacity: 0.6, format: 'image/png',   maxZoom: 12,attribution: "FOSM"}).addTo(map).setZIndex(999);
  }

  return radar_images;
}
函数createVariables(){
var雷达图像=[];

对于(var i=0;i您应该使用set timeout来迭代循环…类似于:

// function for setTimeout
var updateImage = function() {

  //gets the current image & update place
  var img = radar_img_arr[place++] 

  // code to update display here.
  ...

  // call the function again in 1 second 
  setTimeout(updateImage, 1000)

  // reset place to 0 if need be
  if (step == radar_img_arr.length-1) 
    place = 0;

}

// variable to store where we are in the array.
var place = 0

// array of images
var radar_img_arr = createVariables()

//start the process in 1 second:
setTimeout(updateImage, 1000)

// or, start it right away:
updateImage()

我不喜欢使用setInterval,它会自动反复调用函数,不管经过多少毫秒。原因是,如果函数运行的时间比计时器运行的时间长,则会创建一个竞争条件,在您的情况下,这会导致图像奇怪地更新。

您应该使用set timeout来迭代循环。。。比如:

// function for setTimeout
var updateImage = function() {

  //gets the current image & update place
  var img = radar_img_arr[place++] 

  // code to update display here.
  ...

  // call the function again in 1 second 
  setTimeout(updateImage, 1000)

  // reset place to 0 if need be
  if (step == radar_img_arr.length-1) 
    place = 0;

}

// variable to store where we are in the array.
var place = 0

// array of images
var radar_img_arr = createVariables()

//start the process in 1 second:
setTimeout(updateImage, 1000)

// or, start it right away:
updateImage()

我不喜欢使用setInterval,它会自动反复调用你的函数,不管你通过了多少毫秒。原因是,如果你的函数运行的时间比计时器运行的时间长,你就会创建一个竞争条件,在你的情况下,这会导致图像奇怪地更新。

你是如何创建循环的?我想你是c你可以使用setTimeout,在回调中你可以替换层,然后再次调用setTimeout。我无法让setTimeout正常工作。几分钟前我确实发现了这一点,但不确定这是否有帮助。你是如何创建循环来做到这一点的?我想你可以使用setTimeout,在回调中你可以替换层,然后再次调用setTimeout。我不能无法让setTimeout正常工作。几分钟前我确实发现了这一点,但不确定这是否有用。这确实有效。下面是主代码:var I=99;$(“按钮”)。单击(function(){//1秒后启动进程:setTimeout(updateImage,500);});var updateImage=function(){map.removeLayer(radar_img_arr[i]);console.log(i);map.addLayer(radar_img_arr[--i]);console.log(i);//在1秒内再次调用函数setTimeout(updateImage,500);//如果需要,如果(i==0){exit(0);}//但我明白了,你是在预加载图像吗?我创建了,编辑了它,并给了我们一个伪数据数组来处理,我们可以找到它。这确实有效。下面是主要代码:var I=99;$(“按钮”)。单击(function(){//在1秒后启动进程:setTimeout(updateImage,500);};var updateImage=function(){map.removeLayer(radar_img_arr[i]);console.log(i);map.addLayer(radar_img_arr[--i]);console.log(i);//在1秒内再次调用函数setTimeout(updateImage,500);//如果(i==0){exit(0)}//但是我明白了,你是在预加载图像吗?我创建了,编辑了它,给了我们一个假数据数组,我们可以找到它。