When I use a wrapped world projection the retrival of feature coordinates doesn't get the right "repitition" of the world, if it's not the center one. In detail:
In OpenLayers 3 I have a vectormap which is wrapped around the dateline:
new ol.source.Vector({ ... wrapX: true});
When I fetch the features at an event pixel via
var feature = map.world.forEachFeatureAtPixel(pixel, function(feature, layer) {
return feature;
});
The coordinates I get via
var coords = feature.getGeometry().getCoordinates()
… are always the same no matter in which "repetition" of the wrapped world I hover. Then I position an ol.Overlay
via
overlay.setPosition(coords);
And this positioning also doesn't detect the repitition, which leads to the behaviour, that the overlay is positioned off the view, when the "central world" is panned of the screen.
EDIT: Actually the problem can be seen in this OL3 example:
http://openlayers.org/en/v3.6.0/examples/icon.html?q=overlay … just zoom out until the icon appears again to the left or right and click on it. The popover will appear in the central version.
Best Answer
I know you have found a workaround, but here's a solution that will work for you.
Basically, you want to your offset to the 'central world', or the -180 to 180 range by normalizing:
Then you want to apply the offset to the coordinates where you're showing the popup:
Check the jsfiddle for full working code.