Skip to content

Commit 05da585

Browse files
author
Hendrik Rakemann
committed
Visualisierung der Shapes
1 parent a4f88b2 commit 05da585

4 files changed

Lines changed: 63 additions & 3 deletions

File tree

src/main/webapp/ShapeUpdate.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@
1414
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
1515
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
1616

17+
<link rel="stylesheet" href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css" type="text/css">
18+
<style>
19+
.map {
20+
height: 400px;
21+
width: 100%;
22+
}
23+
</style>
24+
<script src="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js"></script>
25+
1726
<link rel="stylesheet" href="css/main.css">
1827
<script src="js/shapeUpdate.js"></script>
1928
<title>ShapeUpdate</title>

src/main/webapp/java/de/htwb/model/DatabaseRepository.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private ImportedShape getImportedShapeForId(String tableName, int id) throws SQL
122122

123123
private ImportedShape getImportedShapeFromCache(String tableName, int id) throws SQLException
124124
{
125-
final String sql = String.format("SELECT \"name\", \"validSince\", \"validUntil\", \"geom\" FROM \"%s\".\"%s\" WHERE gid = ?", "importedCache", tableName);
125+
final String sql = String.format("SELECT \"name\", \"validSince\", \"validUntil\", \"geom\", ST_ASGEOJSON(geom) FROM \"%s\".\"%s\" WHERE gid = ?", "importedCache", tableName);
126126
PreparedStatement ps = connection.prepareStatement(sql);
127127
ps.setInt(1, id);
128128

@@ -137,7 +137,9 @@ private ImportedShape getImportedShapeFromCache(String tableName, int id) throws
137137
PGgeometry geom = (PGgeometry) rs.getObject(4);
138138
MultiPolygon multiPolygon = new MultiPolygon(geom.getGeometry().getValue());
139139
Polygon[] polygons = multiPolygon.getPolygons();
140-
return new ImportedShape(id, name, validSince, validUntil, polygons);
140+
ImportedShape is = new ImportedShape(id, name, validSince, validUntil, polygons);
141+
is.setGeoJson(rs.getString(5));
142+
return is;
141143
}
142144
}
143145

src/main/webapp/java/de/htwb/model/imported/ImportedShape.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class ImportedShape
1313
private int classificationId;
1414
private String username;
1515
private transient Polygon[] polygons;
16+
private String geoJson;
1617

1718
public ImportedShape(int id, String name, Date validSince, Date validUntil, Polygon[] polygons)
1819
{
@@ -63,4 +64,12 @@ public int getId() {
6364
public void setId(int id) {
6465
this.id = id;
6566
}
67+
68+
public String getGeoJson() {
69+
return geoJson;
70+
}
71+
72+
public void setGeoJson(String geoJson) {
73+
this.geoJson = geoJson;
74+
}
6675
}

src/main/webapp/js/shapeUpdate.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ function displayImportedShapes(importedShapes)
8282
}
8383

8484
let classificationId = importedShapes[i].classificationId;
85+
let geoJson = importedShapes[i].geoJson;
8586

8687
let shapeId = "Shape-" + id;
87-
88+
let mapId = "map-"+shapeId;
8889
classificationDropDown.setAttribute("id", "class" + i);
8990
let importedShapeForm =
9091
$("<form id=\""+ i +"\">" +
@@ -108,13 +109,52 @@ function displayImportedShapes(importedShapes)
108109
"<label>Klassifizierung</label>" +
109110
classificationDropDown.outerHTML +
110111
"</div>" +
112+
"<div id=\""+mapId+"\" class=\"map\">"+
113+
114+
"</div>"+
111115
"<button type=\"button\" class=\"btn btn-primary\" id=\"update"+ shapeId +"\">Update</button>" +
112116
"</form><hr>");
113117

114118
$("#importedShapes").append(importedShapeForm);
115119
$("#update" + shapeId).click(function() {
116120
updateShape(i);
117121
});
122+
123+
var geojsonObject =
124+
{
125+
"type": "FeatureCollection",
126+
"crs": {
127+
"type": "name",
128+
"properties": {
129+
"name": "EPSG:4326"
130+
}
131+
},
132+
"features": [{"type":"Feature", "properties":{}, "geometry": JSON.parse(geoJson) }]
133+
};
134+
135+
var vectorSource = new ol.source.Vector({
136+
features: (new ol.format.GeoJSON()).readFeatures(geojsonObject)
137+
});
138+
139+
140+
var vectorLayer = new ol.layer.Vector({
141+
source: vectorSource
142+
});
143+
144+
var map = new ol.Map({
145+
target: mapId,
146+
layers: [
147+
new ol.layer.Tile({
148+
source: new ol.source.OSM()
149+
}),
150+
vectorLayer
151+
],
152+
view: new ol.View({
153+
projection: 'EPSG:4326',
154+
center: [0,0],
155+
zoom: 2
156+
})
157+
});
118158
}
119159
}
120160

0 commit comments

Comments
 (0)