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
6013b2a9
Commit
6013b2a9
authored
Mar 19, 2018
by
Eric Duminil
Browse files
RegionChooser: Some JS refactoring.
parent
213236e1
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/eu/simstadt/regionchooser/RegionChooserBrowser.java
View file @
6013b2a9
...
...
@@ -54,7 +54,7 @@ public JavaScriptFXBridge() {
Preferences
userPrefs
=
Preferences
.
userRoot
().
node
(
"/eu/simstadt/desktop"
);
String
repoString
=
userPrefs
.
get
(
"RECENT_REPOSITORY"
,
null
);
if
(
repoString
==
null
)
{
//TODO: Add a FileDialog?
//TODO: Add a FileDialog?
Possibly next to RegionChooserTitle
repo
=
Paths
.
get
(
"../TestRepository"
);
}
else
{
repo
=
Paths
.
get
(
repoString
);
...
...
src/eu/simstadt/regionchooser/website/script/simstadt_openlayers.js
View file @
6013b2a9
...
...
@@ -188,56 +188,57 @@ proj4.defs("EPSG:28992", "+proj=sterea +lat_0=52.15616055555555 +lon_0=5.3876388
updateGMLPolygons
();
});
var
sourceProj
=
map
.
getView
().
getProjection
();
function
showLinkToDownload
(
feature
,
jsonIntersection
,
polygonArea
){
var
intersection
=
geoJsonFormat
.
readFeature
(
jsonIntersection
);
var
intersectionArea
=
intersection
.
getGeometry
().
getArea
();
var
citygml_percentage
=
Math
.
round
(
intersectionArea
/
feature
[
"
area
"
]
*
100
);
var
sketch_percentage
=
Math
.
round
(
intersectionArea
/
polygonArea
*
100
);
intersections
.
addFeature
(
intersection
);
var
link
=
'
<li>
'
if
(
fromJavaFX
)
{
link
+=
"
<a href=
\"
#
\"
onclick=
\"
regionChooser.downloadRegionFrom
"
+
feature
[
"
source
"
]
+
"
(
"
+
feature
.
getId
()
+
"
);return false;
\"
>
"
+
feature
[
"
name
"
]
+
"
</a>
"
;
}
else
{
link
+=
feature
[
'
name
'
];
}
link
+=
"
(
"
+
citygml_percentage
+
"
%
"
;
if
(
sketch_percentage
==
100
)
{
link
+=
"
, all inside
"
;
}
dataPanel
.
append
(
link
+
"
)
\n
"
);
}
function
findIntersection
(
feature
,
polygon
,
polygonArea
)
{
try
{
var
jsonIntersection
=
turf
.
intersect
(
polygon
,
feature
[
"
geoJSON
"
]);
if
(
undefined
!==
jsonIntersection
)
{
showLinkToDownload
(
feature
,
jsonIntersection
,
polygonArea
);
}
}
catch
(
err
)
{
console
.
log
(
feature
.
get
(
'
name
'
)
+
"
-
"
+
err
);
}
}
function
findIntersections
()
{
var
sketch_area
=
sketch
.
getGeometry
().
getArea
(
);
var
poly
1
=
geoJsonFormat
.
writeFeatureObject
(
sketch
);
var
polygon
=
geoJsonFormat
.
writeFeatureObject
(
sketch
);
var
poly
gonArea
=
sketch
.
getGeometry
().
getArea
(
);
var
intersection_found
=
false
;
intersections
.
clear
();
//TODO: Refactor. Smaller functions
function
findIntersection
(
feature
)
{
try
{
var
jsonIntersection
=
turf
.
intersect
(
poly1
,
feature
[
"
geoJSON
"
]);
if
(
undefined
!==
jsonIntersection
)
{
if
(
!
intersection_found
)
{
//dataPanel.append("Intersection found with :<br/>\n");
intersection_found
=
true
;
}
var
intersection
=
geoJsonFormat
.
readFeature
(
jsonIntersection
);
var
intersectionArea
=
intersection
.
getGeometry
().
getArea
();
var
citygml_percentage
=
Math
.
round
(
intersectionArea
/
feature
[
"
area
"
]
*
100
);
var
sketch_percentage
=
Math
.
round
(
intersectionArea
/
sketch_area
*
100
);
intersections
.
addFeature
(
intersection
);
var
link
=
'
<li>
'
if
(
fromJavaFX
)
{
link
+=
"
<a href=
\"
#
\"
onclick=
\"
regionChooser.downloadRegionFrom
"
+
feature
[
"
source
"
]
+
"
(
"
+
feature
.
getId
()
+
"
);return false;
\"
>
"
+
feature
[
"
name
"
]
+
"
</a>
"
;
}
else
{
link
+=
feature
[
'
name
'
];
}
link
+=
"
(
"
+
citygml_percentage
+
"
%
"
;
if
(
sketch_percentage
==
100
)
{
link
+=
"
, all inside
"
;
}
dataPanel
.
append
(
link
+
"
)
\n
"
);
}
}
catch
(
err
)
{
console
.
log
(
feature
.
get
(
'
name
'
)
+
"
-
"
+
err
);
}
}
features_by_project
=
groupBy
(
kml_source
.
getFeatures
(),
"
project
"
);
features_by_project
[
"
NovaFactory
"
]
=
novafactory_vectors
.
getFeatures
();
Object
.
keys
(
features_by_project
).
forEach
(
function
(
project
)
{
dataPanel
.
append
(
"
<h2>
"
+
project
);
features
=
features_by_project
[
project
];
dataPanel
.
append
(
"
<h2>
"
+
project
);
// features_and_intersections = features.map(f=> [findIntersection(f,polygon)])
for
(
var
i
=
0
;
i
<
features
.
length
;
i
++
)
{
findIntersection
(
features
[
i
]);
findIntersection
(
features
[
i
]
,
polygon
,
polygonArea
);
}
});
dataPanel
.
append
(
"
<h2>
"
+
"
NovaFactory
"
);
novafactory_vectors
.
forEachFeature
(
findIntersection
);
// kml_source.forEachFeature(findIntersection);
if
(
!
intersection_found
)
{
dataPanel
.
append
(
"
No intersection found with any CityGML or NovaFactory product<br/>
\n
"
);
}
...
...
src/eu/simstadt/regionchooser/website/style/style.css
View file @
6013b2a9
...
...
@@ -122,6 +122,7 @@ div#dataPanel h2 {
}
div
#dataPanel
li
{
list-style-type
:
none
;
padding
:
2px
0
0
0
;
margin
:
5px
0
;
line-height
:
1
;
...
...
test/eu/simstadt/regionchooser/RegionExtractorTests.java
View file @
6013b2a9
...
...
@@ -124,4 +124,5 @@ public void testExtract0BuildingsFromWeirdGML() throws Throwable {
assertTrue
(
emptyGMLString
.
contains
(
"<core:CityModel"
));
// Header
assertTrue
(
emptyGMLString
.
contains
(
"</core:CityModel"
));
// Footer
}
//TODO: Add BuildingParts tests with StuttgartAroundCampus.
}
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