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
05caa4b2
Commit
05caa4b2
authored
Mar 23, 2023
by
Eric Duminil
Browse files
Check if geometry is multipolygon.
parent
4218fabd
Changes
2
Show whitespace changes
Inline
Side-by-side
src/main/resources/eu/simstadt/regionchooser/website/script/simstadt_openlayers.js
View file @
05caa4b2
...
@@ -294,10 +294,13 @@ const regionChooser = (function(){
...
@@ -294,10 +294,13 @@ const regionChooser = (function(){
function
displayInfo
()
{
function
displayInfo
()
{
dataPanel
.
empty
();
dataPanel
.
empty
();
var
geom
=
sketch
.
getGeometry
().
clone
().
transform
(
sourceProj
,
'
EPSG:4326
'
);
var
geom
=
sketch
.
getGeometry
().
clone
().
transform
(
sourceProj
,
'
EPSG:4326
'
);
if
(
utils
.
is_polygon
(
geom
)){
// It could be a MultiPolygon, for example.
var
coordinates
=
geom
.
getLinearRing
(
0
).
getCoordinates
();
var
coordinates
=
geom
.
getLinearRing
(
0
).
getCoordinates
();
var
area
=
Math
.
abs
(
wgs84Sphere
.
geodesicArea
(
coordinates
));
var
area
=
Math
.
abs
(
wgs84Sphere
.
geodesicArea
(
coordinates
));
//NOTE: Could show m², ha or km² depending on magnitude
//NOTE: Could show m², ha or km² depending on magnitude
dataPanel
.
append
(
"
<h3 class='clean'>Area :
"
+
(
area
/
10000
).
toFixed
(
1
)
+
"
ha
\n
"
);
dataPanel
.
append
(
"
<h3 class='clean'>Area :
"
+
(
area
/
10000
).
toFixed
(
1
)
+
"
ha
\n
"
);
}
dataPanel
.
append
(
'
<div style="visibility:hidden" id="download_region">
'
+
dataPanel
.
append
(
'
<div style="visibility:hidden" id="download_region">
'
+
'
<button type="button" onclick="regionChooser.downloadFromSelectedCityGMLs()" id="download_region_button" disabled>Download Region</button><br/>
\n
'
+
'
<button type="button" onclick="regionChooser.downloadFromSelectedCityGMLs()" id="download_region_button" disabled>Download Region</button><br/>
\n
'
+
'
<a href="#" onclick="regionChooser.selectAllOrNone(true);">(Select All)</a>
\n
'
+
'
<a href="#" onclick="regionChooser.selectAllOrNone(true);">(Select All)</a>
\n
'
+
...
@@ -381,7 +384,7 @@ const regionChooser = (function(){
...
@@ -381,7 +384,7 @@ const regionChooser = (function(){
//TODO: Show tooltip above.
//TODO: Show tooltip above.
dataPanel
.
append
(
"
<form id='importWKT'>
\n
"
+
dataPanel
.
append
(
"
<form id='importWKT'>
\n
"
+
"
<input id='wktPolygon' type='text' placeholder='WKT Polygon'
"
+
"
<input id='wktPolygon' type='text' placeholder='WKT Polygon'
"
+
"
required pattern=' *POLYGON *
\\
( *
\\
([
\\
-0-9
\
.,
\
)
\
()]+
\\
) *
\\
) *'
"
+
"
required pattern=' *
(MULTI)?
POLYGON *
\\
( *
\\
([
\\
-0-9
\
.,
\
)
\
()]+
\\
) *
\\
) *'
"
+
"
title='Please input a valid WKT Polygon. Example : POLYGON((9.961675 49.807053, 9.951375 49.798521, 9.969486 49.797746, 9.961675 49.807053)) '/>
\n
"
+
"
title='Please input a valid WKT Polygon. Example : POLYGON((9.961675 49.807053, 9.951375 49.798521, 9.969486 49.797746, 9.961675 49.807053)) '/>
\n
"
+
"
<input type='submit' value='Import Polygon'/>
\n
"
+
"
<input type='submit' value='Import Polygon'/>
\n
"
+
"
</form>
\n
"
);
"
</form>
\n
"
);
...
@@ -411,14 +414,19 @@ const regionChooser = (function(){
...
@@ -411,14 +414,19 @@ const regionChooser = (function(){
return
false
;
return
false
;
}
}
// Assuming the linear ring is closed
// Assuming the linear ring is closed
var
coordinatesCount
=
feature
.
getGeometry
().
getLinearRing
(
0
).
getCoordinates
().
length
-
1
;
var
geom
=
feature
.
getGeometry
();
if
(
utils
.
is_polygon
(
geom
)){
var
coordinatesCount
=
geom
.
getLinearRing
(
0
).
getCoordinates
().
length
-
1
;
if
(
coordinatesCount
<
2
){
if
(
coordinatesCount
<
2
){
console
.
warn
(
"
Too few points!
"
);
console
.
warn
(
"
Too few points!
"
);
dataPanel
.
prepend
(
"
<h2 class='error'>There should be at least 2 points in WKT polygon</h2><br/>
\n
"
);
dataPanel
.
prepend
(
"
<h2 class='error'>There should be at least 2 points in WKT polygon</h2><br/>
\n
"
);
return
false
;
return
false
;
}
}
}
sketch
=
feature
;
sketch
=
feature
;
updateGMLPolygons
();
updateGMLPolygons
();
...
@@ -426,7 +434,7 @@ const regionChooser = (function(){
...
@@ -426,7 +434,7 @@ const regionChooser = (function(){
drawnLayer
.
getFeatures
().
clear
();
drawnLayer
.
getFeatures
().
clear
();
intersections
.
clear
();
intersections
.
clear
();
drawnLayer
.
addFeature
(
feature
);
drawnLayer
.
addFeature
(
feature
);
map
.
getView
().
fitExtent
(
feature
.
getGeometry
()
.
getExtent
(),
map
.
getSize
());
map
.
getView
().
fitExtent
(
geom
.
getExtent
(),
map
.
getSize
());
displayInfo
();
displayInfo
();
draw
.
setActive
(
false
);
draw
.
setActive
(
false
);
...
@@ -460,6 +468,10 @@ const regionChooser = (function(){
...
@@ -460,6 +468,10 @@ const regionChooser = (function(){
publicScope
.
copyCoordinatesToClipboard
=
function
(){
publicScope
.
copyCoordinatesToClipboard
=
function
(){
var
geom
=
sketch
.
getGeometry
().
clone
().
transform
(
sourceProj
,
'
EPSG:4326
'
);
var
geom
=
sketch
.
getGeometry
().
clone
().
transform
(
sourceProj
,
'
EPSG:4326
'
);
if
(
!
utils
.
is_polygon
(
geom
)){
console
.
warn
(
"
Sorry, can only export single polygons.
"
);
return
false
;
}
var
wgs84Coords
=
geom
.
getLinearRing
(
0
).
getCoordinates
();
var
wgs84Coords
=
geom
.
getLinearRing
(
0
).
getCoordinates
();
var
wktPolygon
=
"
POLYGON((
"
;
var
wktPolygon
=
"
POLYGON((
"
;
var
precision
=
6
;
// ~ 10 cm precision
var
precision
=
6
;
// ~ 10 cm precision
...
...
src/main/resources/eu/simstadt/regionchooser/website/script/utils.js
View file @
05caa4b2
var
utils
=
{};
var
utils
=
{};
utils
.
groupBy
=
function
(
xs
,
key
)
{
utils
.
groupBy
=
function
(
xs
,
key
)
{
return
xs
.
reduce
(
function
(
rv
,
x
)
{
return
xs
.
reduce
(
function
(
rv
,
x
)
{
(
rv
[
x
[
key
]]
=
rv
[
x
[
key
]]
||
[]).
push
(
x
);
(
rv
[
x
[
key
]]
=
rv
[
x
[
key
]]
||
[]).
push
(
x
);
return
rv
;
return
rv
;
},
{});
},
{});
...
@@ -15,7 +15,7 @@ utils.groupBy = function(xs, key) {
...
@@ -15,7 +15,7 @@ utils.groupBy = function(xs, key) {
// an administrator. By default a prompt is shown the first
// an administrator. By default a prompt is shown the first
// time the clipboard is used (per session).
// time the clipboard is used (per session).
// https://stackoverflow.com/a/33928558/6419007
// https://stackoverflow.com/a/33928558/6419007
utils
.
copyToClipboard
=
function
(
text
,
log
)
{
utils
.
copyToClipboard
=
function
(
text
,
log
)
{
if
(
window
.
clipboardData
&&
window
.
clipboardData
.
setData
)
{
if
(
window
.
clipboardData
&&
window
.
clipboardData
.
setData
)
{
// Internet Explorer-specific code path to prevent textarea being shown while dialog is visible.
// Internet Explorer-specific code path to prevent textarea being shown while dialog is visible.
return
window
.
clipboardData
.
setData
(
"
Text
"
,
text
);
return
window
.
clipboardData
.
setData
(
"
Text
"
,
text
);
...
@@ -41,24 +41,28 @@ utils.copyToClipboard = function(text, log) {
...
@@ -41,24 +41,28 @@ utils.copyToClipboard = function(text, log) {
}
}
}
}
utils
.
read_kml
=
function
(
url
){
utils
.
read_kml
=
function
(
url
)
{
return
new
ol
.
source
.
KML
({
return
new
ol
.
source
.
KML
({
projection
:
ol
.
proj
.
get
(
'
EPSG:3857
'
),
projection
:
ol
.
proj
.
get
(
'
EPSG:3857
'
),
url
:
url
,
url
:
url
,
extractAttributes
:
false
,
extractAttributes
:
false
,
extractStyles
:
false
extractStyles
:
false
});
});
}
}
utils
.
polygon_style
=
function
(
color
,
alpha
)
{
utils
.
is_polygon
=
function
(
geom
)
{
return
(
'
getType
'
in
geom
)
&&
(
geom
.
getType
()
===
'
Polygon
'
);
}
utils
.
polygon_style
=
function
(
color
,
alpha
)
{
return
new
ol
.
style
.
Style
({
return
new
ol
.
style
.
Style
({
fill
:
new
ol
.
style
.
Fill
({
fill
:
new
ol
.
style
.
Fill
({
color
:
'
rgba(255, 255, 255,
'
+
alpha
+
'
)
'
color
:
'
rgba(255, 255, 255,
'
+
alpha
+
'
)
'
}),
}),
stroke
:
new
ol
.
style
.
Stroke
({
stroke
:
new
ol
.
style
.
Stroke
({
color
:
color
,
color
:
color
,
width
:
2
,
width
:
2
,
lineDash
:
[
5
,
10
]
lineDash
:
[
5
,
10
]
}),
}),
});
});
}
}
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