-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinspect_topojson.html
174 lines (151 loc) · 5.4 KB
/
inspect_topojson.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title></title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<style type="text/css">
input[type="file"] {
display: none;
}
.custom-file-upload {
border: hidden;
display: inline-block;
padding: 6px 12px;
cursor: pointer;
}
label {
cursor: pointer;
}
</style>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-125265547-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-125265547-1');
</script>
</head>
<body>
<!-- Just an image -->
<nav class="navbar navbar-dark" style="background-color: #2196F3">
<a class="navbar-brand" href="index.html">
<span class="navbar-toggler-icon"></span>
</a>
</nav>
<div class="container">
<div class="px-3 py-3 pt-md-5 pb-md-4 mx-auto text-center">
<h1 class="display-6">Inspect TopoJSON<span> <a href="https://www.github.com/brechtv/easylife"><img src="https://github.com/favicon.ico"\></a></span></h1>
<p class="lead">Quickly inspect TopoJSON attributes and values</p>
</div>
<form id="topojson_upload">
<div class="form-group custom-file-upload">
<label for="myfile">
<div class="btn" style="background-color: #007bff; color: #FFFFFF;">
<i class="material-icons">cloud_upload</i> Click to upload TopoJSON
</label>
</div>
<input type="file" class="form-control-file" id="myfile">
</div>
</form>
<br>
<table class="table table-hover attributes_table">
<thead>
<tr>
<th scope="col">Attribute</th>
<th scope="col">Example value</th>
</tr>
</thead>
<tbody>
<tr>
<td scope="row"><i>attribute</i></td>
<td style="font-style:italic;"><i>"example value"</i></td>
</tr>
</tbody>
</table>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.7.1/clipboard.min.js"></script>
<script src="testjson.js"></script>
<script type="text/javascript">
$("#myfile").on("change", function (changeEvent) {
for (var i = 0; i < changeEvent.target.files.length; ++i) {
(function (file) { // Wrap current file in a closure.
var loader = new FileReader();
loader.onload = function (loadEvent) {
if (loadEvent.target.readyState != 2)
return;
if (loadEvent.target.error) {
alert("Error while reading file " + file.name + ": " + loadEvent.target.error);
return;
}
try {
topojson_file = JSON.parse(loadEvent.target.result)
generateTopoJSON(topojson_file)
} catch(err) {
alert("Could not read file!")
}
};
loader.readAsText(file);
})(changeEvent.target.files[i]);
}
});
function generateTopoJSON(filecontent) {
var properties = {},
property_keys = [],
property_values = [];
// extract the keys
$.each(filecontent.objects, function(i, v) {
if (v.type = "GeometryCollection") {
// loop through the keys
$.each(v.geometries, function(j, geometry) {
$.each(geometry.properties, function(property) {
property_keys.push(property)
})
})
}
// only unique
property_keys = property_keys.filter((v, i, a) => a.indexOf(v) === i);
// create a json object for it
for (var key of property_keys) {
properties[key] = [];
}
})
// add values
$.each(filecontent.objects, function(i, v) {
if (v.type = "GeometryCollection") {
// loop through the keys
$.each(v.geometries, function(j, geometry) {
$.each(geometry.properties, function(property, property_value) {
for(key in properties) {
if(key == property) {
properties[key] = property_value
}
}
})
})
}
})
// add buttons
for (key in properties) {
$(".attributes_table tbody").append(
`<tr>
<td scope="row">` + key + `</td>
<td style="font-style:italic;">"` + properties[key] + `"</td>
</tr>`
)
}
}
function clearAll() {
$(".ll_remove").remove()
}
</script>
</body>
</html>