Commit af9b4503 authored by Eric Duminil's avatar Eric Duminil
Browse files

Adding WKT validation.

Only valid polygons will be imported
parent 8d32adbe
No related merge requests found
Showing with 72 additions and 54 deletions
+72 -54
......@@ -14,7 +14,7 @@
-->
<script type="text/javascript" src="script/proj4.js"></script>
<script type="text/javascript" src="script/jquery-1.4.2.min.js"></script>
<!-- OpenLayers v3.4.0. API doc : http://openlayers.org/en/v3.4.0/apidoc/ -->
<!-- OpenLayers v3.4.0. API doc : https://geoadmin.github.io/ol3/apidoc/ -->
<script src="script/ol.js" type="text/javascript"></script>
<link rel="stylesheet" href="style/ol.css" type="text/css" />
<script src="script/turf.js" type="text/javascript"></script>
......
......@@ -301,7 +301,7 @@ const regionChooser = (function(){
'<a href="#" onclick="regionChooser.selectAllOrNone(false);">(Select None)</a>\n'+
'</div>\n');
findIntersections();
dataPanel.append('<button type="button" onclick="regionChooser.copyCoordinatesToClipboard()" id="get_wgs84">Copy coordinates</button><br/>\n')
dataPanel.append('<button type="button" onclick="regionChooser.copyCoordinatesToClipboard()" id="get_wgs84" style="position:fixed; bottom:0;">Copy coordinates</button><br/>\n')
}
draw.on('drawend', function() {
......@@ -375,27 +375,45 @@ const regionChooser = (function(){
dataPanel.append("<br>\n");
dataPanel.append("More info is available in the ");
dataPanel.append("<a href='http://simstadt.hft-stuttgart.de/related-softwares/region-chooser/'>SimStadt documentation</a><br>\n");
dataPanel.append("<form id='importWKT'>\n" +
"<input id='wktPolygon' type='text' placeholder='WKT Polygon' value='POLYGON ((30 10, 40 40, 20 40, 10 20, 30 10))'></input>\n" +
"<input type='submit' value='Import Polygon'></input>\n" +
dataPanel.append("<form id='importWKT' style='position:fixed; bottom:0;'>\n" +
"<input id='wktPolygon' type='text' placeholder='WKT Polygon' " +
"required pattern=' *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" +
"<input type='submit' value='Import Polygon'/>\n" +
"</form>\n");
document.getElementById('importWKT').addEventListener('submit', importWKT);
}
importWKT = function(e){
e.preventDefault(); // to avoid refresh
//TODO: DRY, possibly with other events
//TODO: Allow WKT as parameter for GUI?
console.log("Let's import WKT Polygon : " + wktPolygon);
var wktPolygon = document.getElementById("wktPolygon").value;
console.log("Try to import WKT geometry : " + wktPolygon);
var wktFormat = new ol.format.WKT();
try{
var feature = wktFormat.readFeature(wktPolygon, {
dataProjection : ol.proj.get('EPSG:4326'),
featureProjection : ol.proj.get('EPSG:3857')
});
} catch (e){
console.error("Couldn't import geometry!");
dataPanel.prepend("<h2 class='error'>Couldn't import geometry!</h2><br/>\n");
return false;
}
//TODO: Check if import was succesful
// Assuming the linear ring is closed
var coordinatesCount = feature.getGeometry().getLinearRing(0).getCoordinates().length - 1;
if (coordinatesCount < 2){
dataPanel.prepend("<h2 class='error'>There should be at least 2 points in WKT polygon</h2><br/>\n");
return false;
}
sketch = feature;
updateGMLPolygons();
......@@ -408,7 +426,7 @@ const regionChooser = (function(){
displayInfo();
draw.setActive(false);
e.preventDefault(); // to avoid refresh
dataPanel.prepend("<h2 class='ok'>WKT Polygon succesfully imported!</h2><br/>");
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment