-
Notifications
You must be signed in to change notification settings - Fork 8
/
build.html
416 lines (403 loc) · 15.9 KB
/
build.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1,user-scalable=no,maximum-scale=1,width=device-width">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="author" content="Bryan McBride">
<title name="title">Mapzap Builder</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/css/select2.min.css">
<link rel="stylesheet" href="https://angel-vladov.github.io/select2-bootstrap-theme/css/select2-bootstrap.css">
<link rel="icon" type="image/x-icon" name="icon" href="assets/img/favicon.ico">
<link rel="icon" sizes="196x196" name="icon" href="assets/img/favicon-196.png">
<link rel="apple-touch-icon" sizes="76x76" name="icon" href="assets/img/favicon-76.png">
<link rel="apple-touch-icon" sizes="120x120" name="icon" href="assets/img/favicon-120.png">
<link rel="apple-touch-icon" sizes="152x152" name="icon" href="assets/img/favicon-152.png">
<style>
body {
background: #f8f8f8;
}
iframe {
border: 2px solid #343a40;
border-radius: 6px;
padding-bottom: 2px;
}
.popover-title {
color: #fff;
background-color: #337ab7;
border-color: #337ab7;
}
.navbar .navbar-brand {
font-weight: bold;
font-size: 25px;
color: #ffffff;
}
.select2 .select2-container {
width: 100%;
}
#link {
overflow-wrap: break-word;
word-wrap: break-word;
word-break: break-word;
hyphens: auto;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark bg-dark">
<span class="navbar-brand">Mapzap Builder</span>
</nav>
<div class="container-fluid p-3">
<div class="row">
<div class="col-8">
<form>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="src">Data Source <span class="text-danger">*</span></label>
<input type="text" class="form-control" id="src" placeholder="https://someserver.com/data.geojson" data-title="Get started" data-content="Paste a CSV or GeoJSON URL to load the available fields." data-placement="bottom" data-trigger="focus">
<small class="form-text text-danger">*Required* URL to a web accessible GeoJSON or CSV</small>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="icon">Icon</label>
<input type="text" class="form-control" id="icon" placeholder="https://someserver.com/icon.png">
<small class="form-text text-muted">URL to an image for use as a Navbar icon</small>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" id="title" placeholder="My Awesome App">
<small class="form-text text-muted">Used for the Navbar and homescreen app title</small>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="fields">Fields</label>
<select class="form-control allfields" id="fields"></select>
<small class="form-text text-muted">Fields to include. If empty, all fields will be included</small>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="hidden">Hidden Fields</label>
<select class="form-control allfields" id="hidden"></select>
<small class="form-text text-muted">Columns initially hidden in table</small>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="hover">Hover Fields</label>
<select class="form-control allfields" id="hover"></select>
<small class="form-text text-muted">Fields to when mouse hovers over map feature</small>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="sort">Sort Field</label>
<select class="form-control" id="sort">
<option value="" selected disabled>Select a field</option>
</select>
<small class="form-text text-muted">Initially sort table by this column</small>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="order">Sort Order</label>
<select class="form-control" id="order">
<option value="asc" selected>Ascending (asc)</option>
<option value="desc">Descending (desc)</option>
</select>
<small class="form-text text-muted">Initial column sort order</small>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="attribution">Attribution</label>
<input type="text" class="form-control" id="attribution" placeholder="Data courtesy of data.gov">
<small class="form-text text-muted">Source attribution added to text in bottom right of map</small>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label for="map">Map</label>
<select class="form-control" id="map">
<option value="roadmap" selected>Roadmap</option>
<option value="satellite">Satellite</option>
<option value="hybrid">Hybrid</option>
<option value="terrain">Terrain</option>
</select>
<small class="form-text text-muted">Initial Google map type</small>
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label for="cluster">Clustering</label>
<select class="form-control" id="cluster">
<option value="false" selected>False</option>
<option value="true">True</option>
</select>
<small class="form-text text-muted">Cluster points</small>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="style">Style</label>
<textarea class="form-control" rows="5" id="style" placeholder="See examples below"></textarea>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label>Style Info</label>
<small class="form-text text-muted">Feature styling per the <a href="https://developers.google.com/maps/documentation/javascript/3.exp/reference#Data.StyleOptions" target="_blank">google.maps.Data.StyleOptions</a> object specification. You can also categorically style features by defining an object with <code>property</code> and <code>values</code> properties. Values should be an object of values and corresponding CSS3 colors or URLs to marker images.</small>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<h6>Single Style (SVG symbols)</h6>
<pre>
<code>{
"fillColor": "blue",
"fillOpacity": 0.2,
"strokeColor": "blue",
"strokeOpacity": 1,
"strokeWeight": 2,
"icon": {
"path": 0,
"scale": 7,
"strokeColor": "white",
"strokeWeight": 1,
"fillColor": "blue",
"fillOpacity": 1
}
}</code>
</pre>
<h6>Single Style (Image marker)</h6>
<pre>
<code>{
"icon": "https://maps.gstatic.com/mapfiles/ms/micons/blue.png"
}
</code>
</pre>
</div>
<div class="col-sm-6">
<h6>Categorized Style (SVG symbols)</h6>
<pre>
<code>{
"property": "degree_of_damage",
"values": {
"Destroyed": "#DA0796",
"Major": "#CB0D0C",
"Minor": "#FF8819",
"Affected": "#FFD300",
"Inaccessible": "#B3B3B3",
"No Visible Damage": "#87D30F"
}
}</code>
</pre>
<h6>Categorized Style (Image markers)</h6>
<pre>
<code>{
"property": "degree_of_damage",
"values": {
"Destroyed": "https://maps.gstatic.com/mapfiles/ms/micons/pink.png",
"Major": "https://maps.gstatic.com/mapfiles/ms/micons/red.png",
"Minor": "https://maps.gstatic.com/mapfiles/ms/micons/orange.png",
"Affected": "https://maps.gstatic.com/mapfiles/ms/micons/yellow.png",
"Inaccessible": "https://maps.gstatic.com/mapfiles/ms/micons/grey.png",
"No Visible Damage": "https://maps.gstatic.com/mapfiles/ms/micons/green.png"
}
}</code>
</pre>
</div>
</div>
</form>
</div>
<div class="col-4">
<div class="card">
<div class="card-header">
URL
</div>
<div class="card-body">
<a href="#" id="link" target="_blank"></a>
</div>
<div class="card-footer">
<button type="button" class="btn btn-success btn-block" id="preview-btn" disabled>Preview Zapmap</button>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="preview-modal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title text-primary">Preview</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<iframe id="preview" width="100%" height="650"></iframe>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.2/js/bootstrap.min.js"></script>
<script src="https://npmcdn.com/csv2geojson@latest/csv2geojson.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/js/select2.min.js"></script>
<script>
$("#src").on("paste", function(e) {
var url = e.originalEvent.clipboardData.getData("text");
var pattern = new RegExp(/^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,}))\.?)(?::\d{2,5})?(?:[/?#]\S*)?$/i);
if (pattern.test(url)) {
fetchData(url);
$("#preview-btn").removeAttr("disabled");
}
});
$("#src").on("focus", function(e) {
$("#src").popover("hide");
});
$("#src,#icon,#title,#fields,#attribution,#where,#style").on("keyup", function(e) {
buildLink();
});
$("#fields,#hidden,#hover,#map,#cluster,#sort,#order").on("change", function(e) {
buildLink();
});
// workaround to preserve tag ordering - https://github.com/select2/select2/issues/3106#issuecomment-255492815
$(".allfields").on("select2:select", function(e) {
var element = $(this).find("[value='" + e.params.data.id + "']");
$(this).append(element);
$(this).trigger("change");
});
$("#preview-btn").click(function() {
$("#preview").attr("src", $("#link").attr("href"));
$("#preview-modal").modal("show");
});
function fetchData(url) {
var properties = [];
$.ajax({
type: "GET",
url: url,
success: function(geojson, status, xhr) {
if (typeof geojson == "string") {
// Try to parse GeoJSON returned as text (Gist)
try {
JSON.parse(geojson);
geojson = JSON.parse(geojson);
} catch(e) {
csv2geojson.csv2geojson(geojson, {
delimiter: "auto"
}, function(err, data) {
geojson = data;
});
}
}
$.each(geojson.features, function(index, feature) {
$.each(feature.properties, function(key, value) {
if ($.inArray(key, properties) == -1) {
properties.push(key);
}
});
});
}
}).done(function() {
$(".allfields").select2({
data: properties,
multiple: true,
tags: true,
placeholder: "Select fields",
closeOnSelect: true,
theme: "bootstrap"
})
$("#sort").select2({
data: properties,
placeholder: "Select a field",
closeOnSelect: true,
allowClear: true,
theme: "bootstrap"
})
});
}
function buildLink() {
var link = window.location.href.replace("build.html", "");
if ($("#src").val()) {
link += "?src=" + encodeURIComponent($("#src").val());
}
if ($("#icon").val()) {
link += "&icon=" + encodeURIComponent($("#icon").val())
}
if ($("#title").val()) {
link += "&title=" + encodeURIComponent($("#title").val())
}
if ($("#fields").val() && $("#fields").val().length > 0) {
link += "&fields=" + encodeURIComponent($("#fields").val().join())
}
if ($("#hidden").val() && $("#hidden").val().length > 0) {
link += "&hidden=" + encodeURIComponent($("#hidden").val().join())
}
if ($("#hover").val() && $("#hover").val().length > 0) {
link += "&hover=" + encodeURIComponent($("#hover").val().join())
}
if ($("#attribution").val()) {
link += "&attribution=" + encodeURIComponent($("#attribution").val())
}
if ($("#where").val()) {
link += "&where=" + encodeURIComponent($("#where").val())
}
if ($("#map").val()) {
link += "&map=" + encodeURIComponent($("#map").val())
}
if ($("#cluster").val()) {
link += "&cluster=" + encodeURIComponent($("#cluster").val())
}
if ($("#sort").val()) {
link += "&sort=" + encodeURIComponent($("#sort").val())
}
if ($("#order").val()) {
link += "&order=" + encodeURIComponent($("#order").val())
}
if ($("#style").val()) {
link += "&style=" + encodeURIComponent($("#style").val())
}
$("#link").html(link).attr("href", link);
}
$(document).ready(function() {
$("#src").popover("show");
$(".allfields").select2({
data: [],
placeholder: "Select fields",
closeOnSelect: true,
tags: true,
theme: "bootstrap"
})
$("#sort").select2({
data: [],
placeholder: "Select a field",
closeOnSelect: true,
allowClear: true,
tags: true,
theme: "bootstrap"
})
});
</script>
</body>
</html>