【问题标题】:How do I make my OpenLayer 3 map AutoPan together with my animation?如何将我的 OpenLayer 3 地图 AutoPan 与我的动画一起制作?
【发布时间】:2017-01-11 16:09:02
【问题描述】:

我有一个 Flask 应用程序,它使用 OpenLayers3 API 来绘制地图并为路线设置动画。如果我放大船,我希望能够使地图随着我的小船移动,以便在我放大时船永远不会消失。

我尝试使用我找到的一些代码 here(The pan to london 部分):

// ------------------------------------------------
// Tried to use this code - Did not work
// ------------------------------------------------
/*var pan = ol.animation.pan({
  duration: 100,
  source: (map1.view.getCenter())
})
map1.beforeRender(pan);
map1.view.setCenter(currentPoint);*/

我创建了a fiddle 来展示我的其余代码以及上面的代码。

标记移动得很好,但我希望相机与标记一起平移。有谁知道如何做到这一点?

【问题讨论】:

    标签: javascript jquery html flask openlayers-3


    【解决方案1】:

    要访问地图的视图,您应该调用方法getView(),而要设置中心,您必须直接传递坐标,而不是几何对象。

    设置中心的正确方法是:

    map.getView().setCenter([53.44241609, 6.84913974]);
    

    我还编辑了你的jsfiddle

    【讨论】:

    • 谢谢。这就是我正在寻找的东西。
    • @Zeliax 如果您认为正确,请不要忘记给我的答案投票,以便其他人可以看到您的问题已经解决。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-22
    • 1970-01-01
    • 2023-04-04
    • 1970-01-01
    • 2015-07-04
    • 2019-11-06
    相关资源
    最近更新 更多