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
b4fcbe2a
Commit
b4fcbe2a
authored
Oct 10, 2022
by
Eric Duminil
Browse files
Allow coordinates copy to clipboard.
parent
3df17d25
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/resources/eu/simstadt/regionchooser/website/script/simstadt_openlayers.js
View file @
b4fcbe2a
...
...
@@ -162,7 +162,7 @@ var regionChooser = (function(){
var
sketch_percentage
=
Math
.
round
(
intersectionArea
/
polygonArea
*
100
);
intersections
.
addFeature
(
intersection
);
var
link
=
'
<li>
'
// TODO: If possible, highlight the corresponding polygon when hovering above a name.
// TODO: If possible, highlight the corresponding polygon when hovering above a name.
link
+=
'
<input type="checkbox" id="citygml_
'
+
feature
.
getId
()
+
'
" class="select_citygml" onclick="regionChooser.isDownloadPossible();"><label for="citygml_
'
+
feature
.
getId
()
+
'
">
'
+
feature
[
'
name
'
]
+
'
</label>
'
;
link
+=
"
(
"
+
citygml_percentage
+
"
%
"
;
...
...
@@ -194,13 +194,13 @@ var regionChooser = (function(){
features_by_project
=
groupBy
(
kml_source
.
getFeatures
(),
"
project
"
);
Object
.
keys
(
features_by_project
).
forEach
(
function
(
project
)
{
features
=
features_by_project
[
project
];
features_and_intersections
=
features
.
map
(
f
=>
[
f
,
findIntersection
(
f
,
polygon
)]).
filter
(
l
=>
l
[
1
]
!==
undefined
);
if
(
features_and_intersections
.
length
>
0
){
intersection_found
=
true
;
features
=
features_by_project
[
project
];
features_and_intersections
=
features
.
map
(
f
=>
[
f
,
findIntersection
(
f
,
polygon
)]).
filter
(
l
=>
l
[
1
]
!==
undefined
);
if
(
features_and_intersections
.
length
>
0
){
intersection_found
=
true
;
dataPanel
.
append
(
"
<h2 class='info'>
"
+
project
);
features_and_intersections
.
forEach
(
l
=>
showLinkToDownload
(
l
[
0
],
l
[
1
],
polygonArea
));
}
features_and_intersections
.
forEach
(
l
=>
showLinkToDownload
(
l
[
0
],
l
[
1
],
polygonArea
));
}
});
if
(
intersection_found
)
{
...
...
@@ -266,24 +266,12 @@ var regionChooser = (function(){
function
displayInfo
()
{
dataPanel
.
empty
();
var
geom
=
/** @type {ol.geom.Polygon} */
(
sketch
.
getGeometry
().
clone
().
transform
(
sourceProj
,
'
EPSG:4326
'
));
var
geom
=
sketch
.
getGeometry
().
clone
().
transform
(
sourceProj
,
'
EPSG:4326
'
);
var
coordinates
=
geom
.
getLinearRing
(
0
).
getCoordinates
();
var
area
=
Math
.
abs
(
wgs84Sphere
.
geodesicArea
(
coordinates
));
var
coords
=
geom
.
getLinearRing
(
0
).
getCoordinates
();
if
(
!
fromJavaFX
)
{
var
wgs84_coords
=
""
;
var
n
=
coords
.
length
;
for
(
var
i
=
0
;
i
<
n
;
i
++
)
{
var
wgs84_coord
=
coords
[
i
];
wgs84_coords
+=
"
(
"
+
wgs84_coord
[
1
]
+
"
,
"
+
wgs84_coord
[
0
]
+
"
)<br/>
"
;
}
dataPanel
.
append
(
"
WGS84 Coordinates<br/>
"
);
dataPanel
.
append
(
wgs84_coords
+
"
<br/>
\n
"
);
}
//NOTE: Could show m², ha or km² depending on magnitude
dataPanel
.
append
(
"
<h3 class='clean'>Area :
"
+
(
area
/
10000
).
toFixed
(
1
)
+
"
ha
\n
"
);
dataPanel
.
append
(
'
<button type="button" onclick="regionChooser.copyCoordinatesToClipboard()" id="get_wgs84">Copy coordinates</button><br/>
\n
'
)
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
'
+
'
<a href="#" onclick="regionChooser.checkCityGMLS(true);">(Select All)</a>
\n
'
+
...
...
@@ -390,6 +378,47 @@ var regionChooser = (function(){
fxapp
.
selectRepository
();
}
publicScope
.
copyCoordinatesToClipboard
=
function
(){
var
geom
=
sketch
.
getGeometry
().
clone
().
transform
(
sourceProj
,
'
EPSG:4326
'
);
var
wgs84Coords
=
geom
.
getLinearRing
(
0
).
getCoordinates
();
var
wktPolygon
=
"
POLYGON((
"
;
wktPolygon
+=
wgs84Coords
.
map
(
lonLat
=>
lonLat
.
join
(
"
"
)).
join
(
"
,
"
);
publicScope
.
copyToClipboard
(
wktPolygon
+
"
))
"
);
}
// Copies a string to the clipboard. Must be called from within an
// event handler such as click. May return false if it failed, but
// this is not always possible. Browser support for Chrome 43+,
// Firefox 42+, Safari 10+, Edge and Internet Explorer 10+.
// Internet Explorer: The clipboard feature may be disabled by
// an administrator. By default a prompt is shown the first
// time the clipboard is used (per session).
// https://stackoverflow.com/a/33928558/6419007
publicScope
.
copyToClipboard
=
function
(
text
)
{
if
(
window
.
clipboardData
&&
window
.
clipboardData
.
setData
)
{
// Internet Explorer-specific code path to prevent textarea being shown while dialog is visible.
return
window
.
clipboardData
.
setData
(
"
Text
"
,
text
);
}
else
if
(
document
.
queryCommandSupported
&&
document
.
queryCommandSupported
(
"
copy
"
))
{
var
textarea
=
document
.
createElement
(
"
textarea
"
);
textarea
.
textContent
=
text
;
textarea
.
style
.
position
=
"
fixed
"
;
// Prevent scrolling to bottom of page in Microsoft Edge.
document
.
body
.
appendChild
(
textarea
);
textarea
.
select
();
try
{
return
document
.
execCommand
(
"
copy
"
);
// Security exception may be thrown by some browsers.
}
catch
(
ex
)
{
console
.
warning
(
"
Copy to clipboard failed.
"
,
ex
);
return
prompt
(
"
Copy to clipboard: Ctrl+C, Enter
"
,
text
);
}
finally
{
document
.
body
.
removeChild
(
textarea
);
}
}
}
publicScope
.
showRepositoryName
=
function
(
path
)
{
document
.
getElementById
(
"
repo_path
"
).
textContent
=
path
;
}
...
...
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