Javascript 小叶层以某种方式相互干扰

Javascript 小叶层以某种方式相互干扰,javascript,animation,leaflet,Javascript,Animation,Leaflet,我有一个javascript函数,可以创建一个传单层组,将其添加到地图中,删除它,然后重复。每次,它都会通过一个json数组,该数组包含放置在层组中的数据。效果是地图上数据点的动画 有两个数据集已格式化为使用此功能设置动画。让我们称之为现在广播和预测。在我的应用程序中,如果我按以下顺序运行动画: 预报,预报,预报,预报,预报 在第三次临近预报运行时,来自预测的一些数据似乎与临近预报数据一起显示。并不是所有的数据,并且只进行了几次迭代,但它只是停留在那里,并且在动画结束时不会消失。获取这些奇怪的剩

我有一个javascript函数,可以创建一个传单层组,将其添加到地图中,删除它,然后重复。每次,它都会通过一个json数组,该数组包含放置在层组中的数据。效果是地图上数据点的动画

有两个数据集已格式化为使用此功能设置动画。让我们称之为现在广播和预测。在我的应用程序中,如果我按以下顺序运行动画:

预报,预报,预报,预报,预报

在第三次临近预报运行时,来自预测的一些数据似乎与临近预报数据一起显示。并不是所有的数据,并且只进行了几次迭代,但它只是停留在那里,并且在动画结束时不会消失。获取这些奇怪的剩余数据的唯一方法是再次运行预测动画。(再次运行Nowcast不会将其删除)

无论如何,函数如下:

function animateAshData(inputData,dataLayer) {
    var currentTime = inputData.ashData[t];
    var currentAshData = currentTime.concentrations;
    window.Android.toLogCat("t = " + currentTime.date + " " + t);
    window.Android.toLogCat("Current set size= " + currentAshData.length);
    if (dataLayer != undefined) { //The map has a data layer already been created from previous time step, so remove it
        removeDataLayer(dataLayer);
    }

    var currentAshLayerGroup = new L.LayerGroup();
    for (j = 0; j<currentAshData.length; j++) {
        L.marker([currentAshData[j].lat, currentAshData[j].lon],{icon: ashIcon}).addTo(currentAshLayerGroup);
        map.addLayer(currentAshLayerGroup);
        };
    t = t+1;
    // Queue up the animation to the next time step
    tid = setTimeout(function(){
      if (t > finalt) {
        //end of animation
        window.Android.toLogCat("Done with animation");
        removeDataLayer(currentAshLayerGroup);
        window.clearTimeout(tid);
      } else {
     //     delete currentTime.concentrations; 
        clearMap();
        animateAshData(inputData,currentAshLayerGroup);
        }
    }, 100);
function removeDataLayer(layer){
    map.removeLayer(layer);
    layer.clearLayers();
    clearMap();
};

 function clearMap(){
    for(i in map._layers){
        if(map._layers[i]._path != undefined)
        {
             try{
                map.removeLayer(map._layers[i]);
            }
        catch(e){
                console.log("problem with " + e + map._layers[i]);
            }
        }
    }
};
无论如何,我无法想象我是唯一一个存在传单层相互干扰和/或完全移除问题的人。提前谢谢