[OpenLayers-Dev] Still a fix needed in OL. getGeodesicArea when crossing the dataline
Phil Scadden
p.scadden at gns.cri.nz
Mon Nov 18 17:52:37 PST 2013
I was updating to 2.13.1 and checking patches I had made to OL code
versus the new version.
Unfortunately, I have never mastered GIT, but correct code (and yes it
is ugly) is this:
(for linearRing.js)
getGeodesicArea: function(projection) {
var ring = this; // so we can work with a clone if needed
if(projection) {
var gg = new OpenLayers.Projection("EPSG:4326");
if(!gg.equals(projection)) {
ring = this.clone().transform(projection, gg);
}
}
var area = 0.0;
var len = ring.components && ring.components.length;
if(len > 2) {
var p1, p2;
for(var i=0; i<len-1; i++) {
p1 = ring.components[i];
p2 = ring.components[i+1];
var d = p2.x - p1.x;
if (Math.abs(d) > 180) {
if (d>0) {
d += -360
} else {
d += 360
}
}
area += OpenLayers.Util.rad(d) *
(2 + Math.sin(OpenLayers.Util.rad(p1.y)) +
Math.sin(OpenLayers.Util.rad(p2.y)));
}
area = area * 6378137.0 * 6378137.0 / 2.0;
}
return area;
},
If you dont have then, then a polygon that crosses the 180 will get the
incorrect area.
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 Dev
mailing list