DroneDeploy
Search…
Plans - Get Area of Plan
1
<!DOCTYPE html>
2
<html lang="en">
3
<head>
4
<meta charset="UTF-8">
5
<title>Document</title>
6
</head>
7
<body>
8
9
<div>
10
Area of Map: <span id="plan-area">...</span>
11
</div>
12
13
<script>
14
15
/**
16
* Returns area in square meters
17
*/
18
function geodesicArea(latLngs) {
19
var pointsCount = latLngs.length,
20
area = 0.0,
21
d2r = Math.PI / 180,
22
p1, p2;
23
24
if (pointsCount > 2) {
25
for (var i = 0; i < pointsCount; i += 1) {
26
p1 = latLngs[i];
27
p2 = latLngs[(i + 1) % pointsCount];
28
area += ((p2.lng - p1.lng) * d2r) *
29
(2 + Math.sin(p1.lat * d2r) + Math.sin(p2.lat * d2r));
30
}
31
area = area * 6378137.0 * 6378137.0 / 2.0;
32
}
33
34
return Math.abs(area);
35
}
36
37
new DroneDeploy({version: 1}).then(function(dronedeploy){
38
dronedeploy.Plans.getCurrentlyViewed().then(function(plan){
39
document.querySelector('#plan-area').innerHTML = geodesicArea(plan.geometry)+' meters<sup>2</sup>';
40
});
41
});
42
43
</script>
44
45
</body>
46
</html>
Copied!
Last modified 2yr ago
Copy link