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?



Current display:

Current display

  • You should use another projection.
    – drnextgis
    Commented Apr 3, 2013 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
    Commented Apr 3, 2013 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
    Commented Apr 15, 2013 at 0:59
  • Hi, i tried the wrapDateLine option, but that only worked for osgeo's WMS server.
    – Christer
    Commented Apr 15, 2013 at 7:28

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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