我有一个OpenLayers地图,每个世界都有一个Polygon
。我在视图上添加了一个动画,在单击按钮时将其平移到多边形上。
问题是,如果用户不在多边形几何所在的其他世界中,则动画会将用户带到多边形的原始世界。
我不希望发生这种情况,如果用户位于第n个世界(左或右),则平移到多边形应该只在该特定世界中发生。
我正在使用polygon.getGeometry().getInteriorPoint().getCoordinates()
来获取多边形的中间,然后将其设置为center
的{{1}}。
现在,由于多边形几何位于第0个世界中,因此视图的中心总是固定在该世界上,因此地图平移就是该特定世界。
是否可以通过另一世界的ol.View()
中点来计算当前世界的坐标?我认为这将解决问题。
这就是我要尝试的:current output
答案 0 :(得分:2)
这将适用于当前世界(由日期行定义)。由于您的几何形状相对接近日期线,因此它可能不是最短的路线。
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
});