Reputation: 437
I have an OpenLayers map with a Polygon
in every world. I have added an animation on view which pan's to the polygon on button click.
The problem is if the user is in other world than the one in which polygon's geometry lies, the animation takes user to the polygon's original world.
I don't want that to happen, if the user is in nth world to left or right, the pan to polygon should happen in that specific world only.
I am using polygon.getGeometry().getInteriorPoint().getCoordinates()
to get the mid of the polygon and then set it as the center
of the ol.View()
.
Now since the polygons geometry is in 0th world, view's center always gets settled to that world and hence map pan's that specific world.
Is there any way to calculate the coordinate in current world from the polygon's
midpoint in another world ? I think that will solve the issue.
Here is what I am trying : current output
Upvotes: 1
Views: 187
Reputation: 17962
This will work for the current world (as defined by the date line). Since your geometry is relatively close to the dateline it might not be the shortest route.
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
});
Upvotes: 2