forked from mapzap/mapzap.github.io
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.html
383 lines (370 loc) · 14.4 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
<!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="assets/vendor/bootstrap-3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2-bootstrap-theme/0.1.0-beta.10/select2-bootstrap.min.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 black;
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>
<div class="navbar navbar-inverse navbar-static-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<span class="navbar-brand">Mapzap Builder</span>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-xs-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">
<p class="help-block"><span class="text-danger">*Required* URL to a web accessible GeoJSON or CSV.</span></p>
</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">
<p class="help-block">URL to an image for use as a Navbar icon.</p>
</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">
<p class="help-block">Used for the Navbar and homescreen app title.</p>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="fields">Fields</label>
<select class="form-control" id="fields"></select>
<p class="help-block">Fields to show. If empty, all fields will be shown.</p>
</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">
<p class="help-block">Source attribution added to text in bottom right of map.</p>
</div>
</div>
<div class="col-sm-6">
<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>
<option value="Dark">Dark</option>
<option value="Toner">Stamen Toner</option>
</select>
<p class="help-block">Initial Google map type.</p>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="sortfield">Sort Field</label>
<select class="form-control" id="sortfield">
<option value="" selected disabled>Select a field</option>
</select>
<p class="help-block">Initially sort table by this column.</p>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="sortorder">Sort Order</label>
<select class="form-control" id="sortorder">
<option value="asc" selected>Ascending (asc)</option>
<option value="desc">Descending (desc)</option>
</select>
<p class="help-block">Initial column sort order.</p>
</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>
<p class="help-block">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.</p>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<h5>Single Style (SVG symbols)</h5>
<pre>
{
"fillColor": "blue",
"fillOpacity": 0.2,
"strokeColor": "blue",
"strokeOpacity": 1,
"strokeWeight": 2,
"icon": {
"path": 0,
"scale": 7,
"strokeColor": "white",
"strokeWeight": 1,
"fillColor": "blue",
"fillOpacity": 1
}
}
</pre>
<h5>Single Style (Image marker)</h5>
<pre>
{
"icon": "https://maps.gstatic.com/mapfiles/ms/micons/blue.png"
}
</pre>
</div>
<div class="col-sm-6">
<h5>Categorized Style (SVG symbols)</h5>
<pre>
{
"property": "degree_of_damage",
"values": {
"Destroyed": "#DA0796",
"Major": "#CB0D0C",
"Minor": "#FF8819",
"Affected": "#FFD300",
"Inaccessible": "#B3B3B3",
"No Visible Damage": "#87D30F"
}
}
</pre>
<h5>Categorized Style (Image markers)</h5>
<pre>
{
"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"
}
}
</pre>
</div>
</div>
</form>
</div>
<div class="col-xs-4">
<p><button type="button" class="btn btn-success btn-block hidden" id="preview-btn">Preview Zapmap</button></p>
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">URL</h3>
</div>
<div class="panel-body">
<a href="#" id="link" target="_blank"></a>
</div>
<div class="panel-footer">Shorten your URL with <a href="https://goo.gl/" target="_blank">https://goo.gl/</a></div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="preview-modal" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button class="close" type="button" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title text-primary">Preview</h4>
</div>
<div class="modal-body">
<iframe id="preview" width="100%" height="700"></iframe>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script src="assets/vendor/jquery-3.2.1.min.js"></script>
<script src="assets/vendor/bootstrap-3.3.7/js/bootstrap.min.js"></script>
<script src="assets/vendor/csv2geojson-5.0.2/csv2geojson.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/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").removeClass("hidden");
}
});
$("#src").on("focus", function(e) {
$("#src").popover("hide");
});
$("#src,#icon,#title,#fields,#attribution,#sortorder,#style").on("keyup", function(e) {
buildLink();
});
$("#fields,#map,#sortfield,#sortorder").on("change", function(e) {
buildLink();
});
// workaround to preserve tag ordering - https://github.com/select2/select2/issues/3106#issuecomment-255492815
$("#fields").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() {
$("#fields").find("option").remove();
$("#fields").select2({
data: properties,
placeholder: "Select fields",
closeOnSelect: true,
theme: "bootstrap"
})
$("#sortfield").find("option:gt(0)").remove();
$("#sortfield").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 ($("#attribution").val()) {
link += "&attribution=" + encodeURIComponent($("#attribution").val())
}
if ($("#map").val()) {
link += "&map=" + encodeURIComponent($("#map").val())
}
if ($("#sortfield").val()) {
link += "&sortfield=" + encodeURIComponent($("#sortfield").val())
}
if ($("#sortorder").val()) {
link += "&sortorder=" + encodeURIComponent($("#sortorder").val())
}
if ($("#style").val()) {
link += "&style=" + encodeURIComponent($("#style").val())
}
$("#link").html(link).attr("href", link);
}
$(document).ready(function() {
$("#src").popover("show");
$("#fields").attr("multiple", true);
$("#fields").select2({
data: [],
placeholder: "Select fields",
closeOnSelect: true,
tags: true,
theme: "bootstrap"
})
$("#sortfield").select2({
data: [],
placeholder: "Select a field",
closeOnSelect: true,
allowClear: true,
tags: true,
theme: "bootstrap"
})
});
</script>
</body>
</html>