Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

im trying to create a route displayer for ships. But im struggling with the edges of the map. When going from ie. 179* to 2* it displays a line across the entire map, instead of displaying it on the continuation of the map. (Map repeats)

I do see why it would do that. But i was hoping there was some support in openlayers for making this more or less automatic instead of breaking up the route.

Any ideas on how to fix this?

Expecation:

Expectation

Current display:

Current display

share|improve this question
    
You should use another projection. –  drnextgis Apr 3 '13 at 5:27
    
Any idea on which projection ? I am currently using it like this: projection: "EPSG:900913", displayProjection: new OpenLayers.Projection("EPSG:4326") –  Christer Apr 3 '13 at 9:37
    
You haven't told us much about your situation, but perhaps you can use the wrapDateLine option: openlayers.org/dev/examples/wrapDateLine.html. That will only work for certain classes of course, perhaps one of the ones you are using. –  BradHards Apr 15 '13 at 0:59
    
Hi, i tried the wrapDateLine option, but that only worked for osgeo's WMS server. –  Christer Apr 15 '13 at 7:28
add comment

1 Answer

I managed to fix this issue by checking if the line crosses the meridian, if it does. i draw a "artificial" line between the last point before the crossing, and tie it up to the border (180) - And then create a second "fake" line from -180 and up to the point where the original point should have ended. After that it continues as normal until it hits the meridian again.

Some key code from my script.

        var startPoint = new OpenLayers.Geometry.Point(points[temp_index].x,points[temp_index].y);
        if (typeof points[index] === 'undefined') { continue;}
        var endPoint = new OpenLayers.Geometry.Point(points[index].x,points[index].y);



        if (Math.abs(startPoint.x-endPoint.x) > 180) {

            //Line crosses the meridian.
            //Find the middle Y so that we dont get to much of a gap in the middle
            var midY = (startPoint.y + endPoint.y) / 2


            var temp_endpoint = new OpenLayers.Geometry.Point(startPoint.x,midY);
            var temp_startpoint = new OpenLayers.Geometry.Point(startPoint.x,midY);

            if (startPoint.x < endPoint.x) {
                temp_endpoint.x = -180;
                temp_startpoint.x = 180;
            } else {
                temp_endpoint.x = 180;
                temp_startpoint.x = -180;
            }

And then after transforming the points e.e add it to a vector layer.

features.push(new OpenLayers.Feature.Vector(new OpenLayers.Geometry.LineString([startPoint,temp_endpoint])));
                features.push(new OpenLayers.Feature.Vector(new OpenLayers.Geometry.LineString([temp_startpoint,endPoint])));

Note: My function recieves a list of points which i tie up to a linestring.

I hope this helps anyone else that are experiencing this issue.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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