-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
110 lines (89 loc) · 3.47 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<title>SVP validator</title>
</head>
<body>
<div class="container mt-5">
<h1>SVP Validator</h1>
<div class="row my-5">
<div class="col">
<div class="form-group py-4 border-bottom">
<label>Paste geoJSON as text</label>
<textarea id="textarea" class="form-control" placeholder="Paste here GeoJSON to validate" onchange="validateText(event)"></textarea>
</div>
<div class="form-group py-4 border-bottom">
<label>or insert here the absolute URL of the GeoJSON file</label>
<input type="url" id="url" class="form-control" placeholder="URL of GeoJSON file to validate" onchange="validateUrl(event)"/>
</div>
<div class="form-group py-4 border-bottom">
<label>or upload here a GeoJSON file (it will be not saved in any server)</label>
<input type="file" id="file" accept='text/json' placeholder="Upload GeoJSON file to validate" onchange="validateFile(event)">
</div>
</div>
<div class="col">
<div id="result" class="border p-5 text-white"></div>
<pre id="debug" class="border m-5"></pre>
</div>
</div>
</div>
<hr>
<div class="text-center">
© PAThs
</div>
<script src="./SVPValidate.js"></script>
<script>
const validateUrl = event => {
const url = event.target.value;
fetch(url)
.then(response => response.text())
.then(response => {
validate(response);
})
.catch( error => {
console.log(error);
}
);
};
const validateText = event => {
validate(event.target.value);
}
var validateFile = function(event) {
var input = event.target;
var reader = new FileReader();
reader.onload = function(){
const gj = reader.result;
validate(gj);
};
reader.readAsText(input.files[0]);
};
const validate = (text) => {
document.getElementById('result').classList.remove('bg-success');
document.getElementById('result').classList.remove('bg-danger');
document.getElementById('debug').innerText = '';
try {
const gj = JSON.parse(text);
const ret = SVPValidate(gj);
if (ret.status === 'success') {
document.getElementById('result').classList.add('bg-success');
} else {
document.getElementById('result').classList.add('bg-danger');
}
document.getElementById('result').innerText = ret.text;
if(ret.debug){
document.getElementById('debug').innerText = JSON.stringify(ret.debug, null, 2);
}
} catch (error) {
document.getElementById('result').classList.add('bg-danger');
document.getElementById('result').innerText = "Not valid JSON";
document.getElementById('debug').innerText = JSON.stringify(error, null, 2);
}
}
</script>
</body>
</html>