gpt4 book ai didi

javascript - OpenLayers http刷新回调函数

转载 作者:行者123 更新时间:2023-11-29 22:31:15 24 4
gpt4 key购买 nike

这是我的代码的精简版本,每 2 秒重新加载一个 KML 文件。在每次更新时,我想让相机平移到图层要素的范围,但我不知道在哪里设置回调。

//set up ajax    
var protocol = new OpenLayers.Protocol.HTTP({
url: "feed.kml",
format: new OpenLayers.Format.KML(),
callback: function(){
alert("here"); //never called
}
});

//create refresher
var refresh = new OpenLayers.Strategy.Refresh({force: true, active: true});

//create layer for kml
var trackLayer = new OpenLayers.Layer.Vector("KML", {
strategies: [new OpenLayers.Strategy.Fixed(), refresh],
protocol: protocol,
});

//add to map
map.addLayer(trackLayer);

//refresh the kml every 2 seconds
setInterval(function(){
refresh.refresh();
//pan to extent
map.panTo(trackLayer.getDataExtent().getCenterLonLat());
},2000);

问题在于此行:map.panTo(trackLayer.getDataExtent().getCenterLonLat()); 在请求完成之前被调用。

这是文档:

最佳答案

我明白了。我觉得自己很愚蠢,因为没有更快地解决这个问题。

//zoom callback
trackLayer.events.register("featuresadded",trackLayer,function(){
var bounds = trackLayer.getDataExtent();
if(bounds){ map.panTo(bounds.getCenterLonLat()); }
});

关于javascript - OpenLayers http刷新回调函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6846745/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com