Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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: 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
up vote 2 down vote accepted

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

Your Answer


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.