1

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.

  • Is it possible to fork an OL3 jsFiddle to show us the problem? – Dennis Bauszus Jun 17 '15 at 23:11
  • @DennisBauszus there is actually an OL3 example, that illustrates the problem. See edit. – johjoh Jun 18 '15 at 9:39
  • I found a workaround that works for the moment. I'll post it as an answer, later. – johjoh Jun 18 '15 at 9:42
  • You could try the internal coordinates, see here. – Jonatas Walker Jun 18 '15 at 11:36
  • 1
    Internal coordinates won't help since the clicked feature is always bound to the -180-180 coordinate space, even if it is displayed outside that range. – nagytech Jun 18 '15 at 12:28
1

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:

// Inside map.on('click', function (evt) {

/** Find Offset **/
var clickedon = map.getCoordinateFromPixel(evt.pixel)
var offset = Math.floor((clickedon[0] / 40075016.68) + 0.5);

// Popup handling.

Then you want to apply the offset to the coordinates where you're showing the popup:

/** Add offset **/
coord[0] += (offset * 20037508.34 * 2);

Check the jsfiddle for full working code.

  • Great! That's what I did in my "workaround" ... just needed some more lines for the offset computation :-). Still feels a bit like workaround, but it works well. And actually I can't say which function I would expect to behave differently. – johjoh Jun 18 '15 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.