Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Eric Duminil
RegionChooser
Commits
138dffec
Commit
138dffec
authored
Dec 14, 2014
by
duminil
Browse files
Calculate PolygonArea for RegionChooser
parent
f998dd51
Changes
1
Hide whitespace changes
Inline
Side-by-side
website/polygon.js
View file @
138dffec
...
@@ -36,9 +36,9 @@ function Pen(map) {
...
@@ -36,9 +36,9 @@ function Pen(map) {
this
.
drawPolygon
(
this
.
listOfDots
);
this
.
drawPolygon
(
this
.
listOfDots
);
$
(
'
#dataPanel
'
).
empty
();
$
(
'
#dataPanel
'
).
empty
();
$
(
'
#dataPanel
'
).
append
(
"
WGS84 Coordinates<br/>
"
);
$
(
'
#dataPanel
'
).
append
(
"
WGS84 Coordinates<br/>
"
);
$
(
'
#dataPanel
'
).
append
(
this
.
get
Data
(
"
WGS84
"
)
);
$
(
'
#dataPanel
'
).
append
(
this
.
get
WGS84Data
()
+
"
<br/>
\n
"
);
$
(
'
#dataPanel
'
).
append
(
"
GSK3 Coordinates<br/>
"
);
$
(
'
#dataPanel
'
).
append
(
"
GSK3 Coordinates<br/>
"
);
$
(
'
#dataPanel
'
).
append
(
this
.
get
Data
(
"
GSK3
"
));
$
(
'
#dataPanel
'
).
append
(
this
.
get
GSK3DataAndArea
(
));
}
else
{
}
else
{
if
(
null
!=
this
.
polyline
)
{
if
(
null
!=
this
.
polyline
)
{
this
.
polyline
.
remove
();
this
.
polyline
.
remove
();
...
@@ -78,19 +78,36 @@ function Pen(map) {
...
@@ -78,19 +78,36 @@ function Pen(map) {
this
.
getListOfDots
=
function
()
{
this
.
getListOfDots
=
function
()
{
return
this
.
listOfDots
;
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
)
{
if
(
this
.
polygon
!=
null
)
{
var
data
=
""
;
var
data
=
""
;
var
paths
=
this
.
polygon
.
getPlots
();
var
paths
=
this
.
polygon
.
getPlots
();
var
fromProjection
=
proj4
(
'
EPSG:4326
'
);
var
fromProjection
=
proj4
(
'
EPSG:4326
'
);
var
toProjection
=
proj4
(
'
EPSG:31467
'
);
var
toProjection
=
proj4
(
'
EPSG:31467
'
);
var
xs
=
[];
var
ys
=
[];
paths
.
getAt
(
0
).
forEach
(
function
(
value
,
index
)
{
paths
.
getAt
(
0
).
forEach
(
function
(
value
,
index
)
{
if
(
referenceSystem
==
"
WGS84
"
)
{
var
gk3_coords
=
proj4
(
fromProjection
,
toProjection
,
[
value
.
lng
(),
value
.
lat
()
]);
data
+=
(
value
.
toString
()
+
"
<br/>
"
);
xs
.
push
(
gk3_coords
[
0
]
-
3500000
);
}
else
if
(
referenceSystem
==
"
GSK3
"
)
{
ys
.
push
(
gk3_coords
[
1
]
-
5000000
);
data
+=
"
(
"
+
(
proj4
(
fromProjection
,
toProjection
,
[
value
.
lng
(),
value
.
lat
()
]).
toString
()
+
"
)<br/>
"
);
data
+=
"
(
"
+
(
gk3_coords
.
toString
()
+
"
)<br/>
"
);
}
});
});
data
+=
"
<br/>
\n
Area :
"
+
(
Math
.
round
(
polygonArea
(
xs
,
ys
)
/
1000
)
/
10
).
toString
()
+
"
ha<br/>
"
;
return
data
;
return
data
;
}
else
{
}
else
{
return
null
;
return
null
;
...
@@ -191,4 +208,15 @@ function Polygon(listOfDots, map, pen, color) {
...
@@ -191,4 +208,15 @@ function Polygon(listOfDots, map, pen, color) {
});
});
}
}
this
.
addListener
();
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
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment