Wrap 2D Map Projection

classic Classic list List threaded Threaded
5 messages Options
David David
Reply | Threaded
Open this post in threaded view
|

Wrap 2D Map Projection

I would like to have a 2D (Mercator) projection that seamlessly wraps at the International Date Line so that you can go from Hawaii to Japan, for example, by scrolling West without having to scroll East all the way across the map.

I'm hoping I'll get lucky and someone will say "just enable property 'X'" and this is something supported out of the box.  If not, I'd appreciate some pointers on how to make it happen.  Could I just add the same root node to the scene but translated by 180° longitude in each direction so that there are basically 3 maps, and then when the camera crosses the IDL automatically snap it to the other side?
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Wrap 2D Map Projection

David,

The "osgearth_infinitescroll" example essentially does what you are describing. Just be aware that it's only a proof of concept and not an actual feature -- that is, not all features are expected to work in this type of configuration.
Glenn Waldron / Pelican Mapping
David David
Reply | Threaded
Open this post in threaded view
|

Re: Wrap 2D Map Projection

It looks like that example basically does what I had in mind; adding the same map node to three different scene nodes, two of which are translated left and right.  I'll dig into it some more.  Thank you!!
David David
Reply | Threaded
Open this post in threaded view
|

Re: Wrap 2D Map Projection

FYI, I was able to successfully adapt the infinite scroll example into my application with a few changes.

First, rather than translating each map node each frame based on the camera's position, I instead move the camera to the opposite side of the map if it crosses the edge to keep it over the center map.  For some reason this seemed more intuitive to me; keeping the map in place and just move the camera.

Second, I noticed that mouse picking the terrain (i.e., getting the lat/lon under the cursor) didn't work for the side maps.  The call to Terrain::getWorldCoordsUnderMouse() failed because the cursor wasn't over the map, which was the one in the center.  I ended up having to copy the code from this method and translate the matrix it used to account for the left and right maps, thus doing the intersection check three times.

There's also an issue that even with a reasonable max zoom range, if you resize the window to make it really wide and short, the aspect ratio of the camera is sufficient to break the illusion, allowing you to see past the edges of the outer maps.  This isn't that big a deal to me and can probably be solved by updating the max zoom range based on the aspect ratio when the window resize.

Overall, the infinite scroll example got me about 80% to what I needed and really helped.  Thanks!
Josiah425 Josiah425
Reply | Threaded
Open this post in threaded view
|

Re: Wrap 2D Map Projection

This post was updated on .
Hey David,

We did something similar with our map, we also set the viewpoint to center on the center map and not transform the map any further.  We extended our MapExtent to be larger to account for both side maps.  Then we reimplemented the function getWorldCoordsUnderMouse function and just replaced

osg::Matrix terrainRefFrame = osg::computeLocalToWorld(_graph->getParentalNodePaths()[0]);

with

osg::Matrix terrainRefFrame = osg::computeLocalToWorld(mapSceneGraph->getRoot()->getParentalNodePaths()[0]);

getRoot returns the node that holds the matrix transform nodes

This prevented us from having to do the translation intersection multiple times

Edit: we set a max zoom out range so that there is no "breaking" of the illusion