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

杨华杰 yhjhoo at gmail.com
Sun Mar 10 20:41:22 PDT 2013


I have searched google a lot for this issue, I found a lot of people have
the same problem. It's better to have a general solution.


On Mon, Mar 11, 2013 at 9:12 AM, Phil Scadden <p.scadden at gns.cri.nz> wrote:

>
>  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.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/openlayers-users/attachments/20130311/ce202db5/attachment.html>


More information about the Users mailing list