gpt4 book ai didi

javascript - View 适合动画结束时的 Openlayers

转载 作者:行者123 更新时间:2023-12-05 04:52:46 26 4
gpt4 key购买 nike

我正在使用 openlayers 6.5。

我有:

/* Set the features to fill the map */
var extent = ol.extent.createEmpty();
for(var county_id in map['map_internal_data'])
{
ol.extent.extend(
extent,
map['openlayers_features']['counties'][county_id].getGeometry().getExtent()
);
}
map['openlayers'].getView().fit(
extent,
{
size: map['openlayers'].getSize(),
padding: [25, 10, 25, 10],
duration:1000
}
);

/* I need to call a function here, but only after above animation ends */
function_after_above_animation_ends();

以上代码采用县的几何图形并缩放 map ,直到县填满 map 。如您所见,那里有一个动画设置:duration:1000

我需要的是在拟合结束后(动画结束后)调用一个函数。

我可以使用 setTimeout 1000,但我认为这不是正确的方法。

我需要类似promise的东西...

最佳答案

fit 有一个回调 选项https://openlayers.org/en/latest/apidoc/module-ol_View-View.html#fit

map['openlayers'].getView().fit(
extent,
{
size: map['openlayers'].getSize(),
padding: [25, 10, 25, 10],
duration:1000,
callback: myFunction
}
);

关于javascript - View 适合动画结束时的 Openlayers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66396641/

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