javascript - Openlayers on view fit 动画结束
问题描述
我正在使用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();
上面的代码获取县的几何图形并缩放地图,直到县填满地图。如您所见,那里有一个动画设置:duration:1000
.
我需要的是在拟合结束后(动画结束后)调用一个函数。
我可以使用setTimeout
1000
,但我认为这不是正确的方法。
我需要类似promise
...
解决方案
fit 有一个callback
选项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
}
);
推荐阅读
- java - 从 jsonobj 中提取数据的 Java Stream 表示
- r - 使用 stat_summary 在箱线图上标注中线
- google-cloud-platform - 如何让 Google Cloud Build 在 VPC 边界内工作?
- pythonanywhere - 如何使用 Python Flask 上传照片并将其保存到网站中
- python - 在更新中隐藏特定字段,但在创建中不隐藏
- xml - 在 Apache NiFi 的 ExecuteScript 处理器中缓存文件内容
- javascript - 将鼠标图标更改为“等待”,无论它在哪里
- python - 意外的 Python 解释器输出
- c# - ASP.NET 和 Visual Studio 2019:如果 Web.config 中有 configSource,如何设置 Web.Debug 和 Web.Release?
- video-streaming - 有没有办法使用 VLC 从网络摄像头流式传输原始 YUY2?(错误:无法创建分包器输出(YUY2))