Commit 138dffec authored by duminil's avatar duminil
Browse files

Calculate PolygonArea for RegionChooser

parent f998dd51
......@@ -36,9 +36,9 @@ function Pen(map) {
this.drawPolygon(this.listOfDots);
$('#dataPanel').empty();
$('#dataPanel').append("WGS84 Coordinates<br/>");
$('#dataPanel').append(this.getData("WGS84"));
$('#dataPanel').append(this.getWGS84Data() + "<br/>\n");
$('#dataPanel').append("GSK3 Coordinates<br/>");
$('#dataPanel').append(this.getData("GSK3"));
$('#dataPanel').append(this.getGSK3DataAndArea());
} else {
if (null != this.polyline) {
this.polyline.remove();
......@@ -78,19 +78,36 @@ function Pen(map) {
this.getListOfDots = function() {
return this.listOfDots;
}
this.getData = function(referenceSystem) {
this.getWGS84Data = function() {
if (this.polygon != null) {
var data = "";
var paths = this.polygon.getPlots();
var xs = [];
var ys = [];
paths.getAt(0).forEach(function(value, index) {
data += (value.toString() + "<br/>");
});
return data;
} else {
return null;
}
}
this.getGSK3DataAndArea = function(referenceSystem) {
if (this.polygon != null) {
var data = "";
var paths = this.polygon.getPlots();
var fromProjection = proj4('EPSG:4326');
var toProjection = proj4('EPSG:31467');
var xs = [];
var ys = [];
paths.getAt(0).forEach(function(value, index) {
if (referenceSystem == "WGS84") {
data += (value.toString() + "<br/>");
} else if (referenceSystem == "GSK3") {
data += "(" + (proj4(fromProjection, toProjection, [ value.lng(), value.lat() ]).toString() + ")<br/>");
}
var gk3_coords = proj4(fromProjection, toProjection, [ value.lng(), value.lat() ]);
xs.push(gk3_coords[0] - 3500000);
ys.push(gk3_coords[1] - 5000000);
data += "(" + (gk3_coords.toString() + ")<br/>");
});
data += "<br/>\nArea : " + (Math.round(polygonArea(xs, ys) / 1000) / 10).toString() + " ha<br/>";
return data;
} else {
return null;
......@@ -191,4 +208,15 @@ function Polygon(listOfDots, map, pen, color) {
});
}
this.addListener();
}
\ No newline at end of file
}
function polygonArea(X, Y, numPoints) {
area = 0; // Accumulates area in the loop
j = X.length - 1; // The last vertex is the 'previous' one to the first
for (i = 0; i < X.length; i++) {
area = area + (X[j] + X[i]) * (Y[j] - Y[i]);
j = i; // j is previous vertex to i
}
return Math.abs(area / 2);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment