如何在没有鼠标事件的情况下在openlayers中从其他世界找到当前世界中的等效坐标

How to find equivalent coordinates in current world from other world in openlayers without mouse event

我在每个世界都有一个 Polygon 的 OpenLayers 地图。我在视图中添加了一个动画,单击按钮时平移到多边形。

问题是如果用户在其他世界而不是多边形几何体所在的世界,动画会将用户带到多边形的原始世界。

我不希望发生这种情况,如果用户在左侧或右侧的第 n 个世界中,平移到多边形应该只发生在该特定世界中。

我正在使用 polygon.getGeometry().getInteriorPoint().getCoordinates() 获取多边形的中点,然后将其设置为 ol.View()center。 现在,由于多边形几何体位于第 0 个世界,视图的中心总是落在那个世界,因此地图平移是那个特定的世界。

有什么方法可以计算出当前世界的坐标与另一个世界的polygon's中点的坐标吗?我认为这将解决问题。

这是我正在尝试的:current output

这将适用于当前世界(如日期变更线所定义)。由于您的几何位置相对接近日期变更线,因此它可能不是最短路线。

    var point = t.getGeometry().getInteriorPoint().clone();
    var worldWidth = ol.extent.getWidth(view.getProjection().getExtent());
    var currentWorld = Math.round(view.getCenter()[0]/worldWidth);
    point.translate(currentWorld * worldWidth, 0);
    view.animate({
      center: point.getCoordinates(),
      duration: 1200
    });