[OpenLayers-Users] display a border at the end of the world

Phil Scadden p.scadden at gns.cri.nz
Sun Mar 10 18:12:08 PDT 2013


> Your bet is correct. Any tips on convert the coordinate? It's not just 
> a point when you draw with openlayer, the shape can be line and polygon.
Well no great mystery here. After the user has drawn the object, and 
before posting the data to geoserver, (eg on the featureadded event), 
you just process through the list of coordinates in the geometry 
converting them (eg if ln>180 then ln -=360). Much more
mysterious is management of the topology but this is a function of the 
underlying database, rather than geoserver. I dont think there is a 
general solution to this.

Slightly more general code is:
where geom is the geometry to convert and extent is generally 
baseLayer.maxExtent
function wrapDateline(geom,extent) {
     for (var i=0, len=geom.components.length; i<len; i++) {
         var component = geom.components[i];
         for (var j=0, lenj=component.components.length; j<lenj; j++) {
             var pt = component.components[j];
             while (pt.x < extent.left) {
                 pt.x +=  extent.getWidth();
             }

             //shift left?
             while (pt.x > extent.right) {
                 pt.x -= extent.getWidth();
             }
         }

     }
     geom.bounds = null;
     return geom;
}


Notice: This email and any attachments are confidential.
If received in error please destroy and immediately notify us.
Do not copy or disclose the contents.



More information about the Users mailing list