Repository navigation
Expand file tree
/
Copy pathbundle.js
More file actions
9388 lines (8084 loc) · 310 KB
/
Copy pathbundle.js
File metadata and controls
9388 lines (8084 loc) · 310 KB
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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
/*jshint esversion: 7 */
const { getElementById } = require("./views");
exports.initController = initController;
/*
* Sets up event listeners
*/
function initController(EM) {
//getElementById("new-site").addEventListener("click", () => {EM.emit("site-editor-open", {});});
getElementById("new-site").addEventListener("click", () => {
window.state.panel = "site-editor";
EM.emit("change-panel");
});
const loadButton = getElementById('load-site');
loadButton.addEventListener('change', ()=> {
//loads existing JSON file as a location.
const fileURL = window.URL.createObjectURL(loadButton.files[0]);
console.log(fileURL);
//https://stackoverflow.com/questions/35294633/what-is-the-vanilla-js-version-of-jquerys-getjson#answers
const request = new XMLHttpRequest();
request.open('GET', fileURL, true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
const json = JSON.parse(request.responseText);
window.state.site = json;
window.state.panel = "site-content";
EM.emit("change-panel");
} else {
throw new Error("File did not load properly: " + request.status);
}
};
request.onerror = function() {
throw new Error("File did not load properly: " + request.status);
};
request.send();
});
EM.on("panel-created", () => {
const panel = window.state.panel;
if (panel === "site-editor") {
listenToSiteEditor(EM);
} else if (panel === "site-content") {
listenToSiteContentPanel(EM);
} else if (panel === "scenario-editor") {
listenToScenarioEditor(EM);
} else if (panel === "bubbleplot-editor") {
listenToBubbleplotEditor(EM);
} else {
throw new Error("No panel of the name ", panel);
}
});
}
/*
* Set up places search bar to look up addresses and location names nearby
*/
function setUpPlacesSearch(element) {
const searchBox = new window.googleAPI.maps.places.SearchBox(element);
window.state.placesMarkers = [];
// Listen for the event fired when the user selects a prediction and retrieve
// more details for that place.
searchBox.addListener('places_changed', function() {
// from: https://developers.google.com/maps/documentation/javascript/places-autocomplete
const places = searchBox.getPlaces();
if (places.length == 0) { return; }
// Clear out the old markers.
for (const marker of window.state.placesMarkers) {
marker.setMap(null);
}
window.state.placesMarkers = [];
// For each place, get the icon, name and location.
var bounds = new window.googleAPI.maps.LatLngBounds();
places.forEach(function(place) {
if (!place.geometry) {
throw new Error("Returned place contains no geometry");
}
// Create a marker for each place.
const marker = new window.googleAPI.maps.Marker({
map: window.state.map,
title: place.formatted_address,
position: place.geometry.location,
icon: "assets/searchPin.png"
});
window.googleAPI.maps.event.addListener(marker, "click", latLongListener);
window.state.placesMarkers.push(marker);
if (place.geometry.viewport) {
// Only geocodes have viewport.
bounds.union(place.geometry.viewport);
} else {
bounds.extend(place.geometry.location);
}
if (places.length ==1) {
setLatLongValues(place.geometry.location.lat(), place.geometry.location.lng());
}
});
window.state.map.fitBounds(bounds);
});
}
/*
* Set up Site Editor listeners
*/
function listenToSiteEditor(EM) {
setUpPlacesSearch(getElementById('search-box'));
const eventListeners = placeLatLongListenerOnMap();
getElementById("submit-button").addEventListener("click", () => {
EM.emit("new-site-submitted");
removeLatLongListenerFromMap(eventListeners);
if (window.state.searchMarker) window.state.searchMarker.setMap(null);
removeMarkers();
});
getElementById("site-cancel-button").addEventListener("click", () => {
getElementById("navigator").innerHTML = "";
window.state.panel = null;
removeLatLongListenerFromMap(eventListeners);
if (window.state.searchMarker) window.state.searchMarker.setMap(null);
removeMarkers();
});
addKeyboardFunctionality();
function removeMarkers() {
if(window.state.placesMarkers) {
for (const marker of window.state.placesMarkers) {
marker.setMap(null);
}
window.state.placesMarkers = [];
}
}
}
function runDropdownMenu(event, EM) {
const dropdownIdSplit = event.target.id.split("-");
if (dropdownIdSplit.length === 3) {
const [ type, scenarioNum, menuFunction ] = dropdownIdSplit;
const id = type + "-" + scenarioNum;
if (type === "bubbleplot") {
switch(menuFunction) {
case "delete":
window.state.mapItem = id;
EM.emit("delete-siteItem");
break;
case "edit":
window.state.mapItem = id;
window.state.panel = "bubbleplot-editor";
EM.emit("change-panel");
break;
case "hide":
window.state.site.bubbleplotList[id].hidden = !window.state.site.bubbleplotList[id].hidden;
EM.emit("change-panel");
break;
default:
throw new Error("dropdown-scenario-menu-item menuFunction is not correct", targetId);
}
} else if (type === "scenario") {
switch(menuFunction) {
case "delete":
window.state.mapItem = id;
EM.emit("delete-siteItem");
break;
case "edit":
window.state.mapItem = id;
window.state.panel = "scenario-editor";
EM.emit("change-panel");
break;
case "hide":
window.state.site.scenarioList[id].hidden = !window.state.site.scenarioList[id].hidden;
EM.emit("change-panel");
break;
case "hideRanges":
window.state.site.scenarioList[id].rangesHidden = !window.state.site.scenarioList[id].rangesHidden;
EM.emit("change-panel");
break;
default:
throw new Error("dropdown-scneario-menu-item menuFunction is not correct", targetId);
}
} else{
throw new Error("target Id on dropdown-scneario-menu-item is not correct", targetId);
}
} else {
throw new Error("target Id on dropdown-scneario-menu-item is not correct", targetId);
}
}
/*
* Set up Scenario Editor listeners
*/
function listenToBubbleplotEditor(EM) {
getElementById("submit-button").addEventListener("click", () => {
EM.emit("create-bubbleplot");
});
getElementById("bubbleplot-cancel-button").addEventListener("click", () => {
state.panel = "site-content";
EM.emit("change-panel");
});
}
/*
* Set up Scenario Editor listeners
*/
function listenToScenarioEditor(EM) {
const state = window.state;
const eventListeners = placeLatLongListenerOnMap();
getElementById("submit-button").addEventListener("click", () => {
EM.emit("create-edit-scenario", state.mapItem);
removeLatLongListenerFromMap(eventListeners);
if (state.searchMarker) state.searchMarker.setMap(null);
});
getElementById("scenario-cancel-button").addEventListener("click", () => {
state.panel = "site-content";
EM.emit("change-panel");
removeLatLongListenerFromMap(eventListeners);
if (state.searchMarker) state.searchMarker.setMap(null);
});
getElementById("metric-english-toggle").addEventListener("click", () => {
window.alert("This feature has not been created yet");
});
getElementById("save-model").addEventListener("click", () => {
getModelData("tnoModel");
});
// Make initial scenario marker
if (state.mapItem) {
placeDraggableMarkerOnMap(state.site.scenarioList[state.mapItem].latitude,
state.site.scenarioList[state.mapItem].longitude);
} else {
placeDraggableMarkerOnMap(state.site.latitude, state.site.longitude);
}
addKeyboardFunctionality();
}
function getModelData(modelName) {
if (modelName == "tnoModel") {
const model = {};
model.metricEnglish = getElementById("metric-english-toggle").getAttribute("data");
model.tnoVolume = getElementById("tnoVolume").value;
model.tnoHeat = getElementById("tnoHeat").value;
model.tnoAtmPress = getElementById("tnoAtmPress").value;
model.tnoCurveSelect = getElementById("tnoCurveSelect").value;
model.tnoPressThresh = [
getElementById("tnoPressThresh1").value,
getElementById("tnoPressThresh2").value,
getElementById("tnoPressThresh3").value
];
model.tnoPressThresh.sort((a, b) => {return b-a;});
// TODO: store model in state
const radiusForPs = TNOmodelFromPressArray(model);
getElementById("range-0").value = radiusForPs[0];
getElementById("range-1").value = radiusForPs[1];
getElementById("range-2").value = radiusForPs[2];
}
}
function TNOmodelFromPressArray(model) {
let distances = [];
for (const p of model.tnoPressThresh) {
const scaledP = (p/model.tnoAtmPress);
console.log("scaledP = " + scaledP);
const curve = window.state.tnoTable[model.tnoCurveSelect];
const rbar = tableLookup(curve, scaledP);
console.log("rbar = " + rbar);
if (rbar) {
distances.push(rbar*(model.tnoHeat*1000*model.tnoVolume/(model.tnoAtmPress*100))**(1/3));
}
}
console.log(distances);
return distances;
}
function tableLookup(table, scaledPressure) {
if (scaledPressure > table.overpressure[0]) {
window.alert("Not all thresholds can be reached by the chosen curve");
return false;
} else {
for (let i=0; i < table.overpressure.length; i++) {
if (scaledPressure > table.overpressure[i]) {
let interp = logInterpolateX (
table.distance[i],
table.overpressure[i],
table.distance[i-1],
table.overpressure[i-1],
scaledPressure);
console.log(interp);
return interp;
}
}
}
}
function interpolate(x1, y1, x2, y2, x) { return y1+(y2-y1)*(x-x1)/(x2-x1); }
function logInterpolateX(x1, y1, x2, y2, y) {
// https://math.stackexchange.com/questions/1777303/interpolation-point-fitting-onto-a-logarithmic-line-segment
// https://en.wikipedia.org/wiki/Log%E2%80%93log_plot
const slope = Math.log(y2/y1)/Math.log(x2/x1);
return x1*(y/y1)**(1/slope);
}
/*
* Set up Site Content panel listeners
*/
function listenToSiteContentPanel(EM) {
getElementById("new-scenario").addEventListener("click", () => {
window.state.panel = "scenario-editor";
EM.emit("change-panel");
});
getElementById("new-bubbleplot").addEventListener("click", () => {
window.state.panel = "bubbleplot-editor";
EM.emit("change-panel");
});
getElementById("edit-site").addEventListener("click", () => {
window.state.panel = "site-editor";
EM.emit("change-panel");
});
getElementById("save-site").addEventListener("click", () => {
saveSite(window.state.site);
});
getElementById("hide-scenarios").addEventListener("click", () => {
for (const scenario of Object.values(window.state.site.scenarioList)) { scenario.hidden = true;}
window.state.panel = "site-content";
EM.emit("change-panel");
});
getElementById("hide-bubbleplots").addEventListener("click", () => {
for (const bubbleplot of Object.values(window.state.site.bubbleplotList)) { bubbleplot.hidden = true;}
window.state.panel = "site-content";
EM.emit("change-panel");
});
function dropdownListener (event) {
runDropdownMenu(event, EM);
}
const dropdowns = document.getElementsByClassName("dropdown-button");
if (dropdowns) {
for (const dropdown of dropdowns) {
dropdown.addEventListener("click", dropdownListener);
}
}
}
function saveSite(location) {
//saves myLocation info as a json file.
const name = location.name + ".json";
const file = new Blob([JSON.stringify(location)], {type: "application/json"});
if (window.navigator.msSaveOrOpenBlob) // IE10+
window.navigator.msSaveOrOpenBlob(file, name);
else { // Others
const a = document.createElement("a"),
url = URL.createObjectURL(file);
a.href = url;
a.download = name;
document.body.appendChild(a);
a.click();
setTimeout(function() {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 0);
}
}
function placeLatLongListenerOnMap() {
return [
window.googleAPI.maps.event.addListener(window.state.map, "click", latLongListener),
window.googleAPI.maps.event.addListener(window.state.map, "click", (event) => {
placeDraggableMarkerOnMap(event.latLng.lat(), event.latLng.lng());
})
];
}
function removeLatLongListenerFromMap(eventListeners) {
for (const listener of eventListeners) {
window.googleAPI.maps.event.removeListener(listener);
}
}
function latLongListener(event) {
setLatLongValues(event.latLng.lat(), event.latLng.lng());
}
function setLatLongValues(latitude, longitude) {
getElementById("latitude").value = latitude.toFixed(5);
getElementById("longitude").value = longitude.toFixed(5);
}
function placeDraggableMarkerOnMap(latitude, longitude){
const myLatLng = new window.googleAPI.maps.LatLng(latitude, longitude);
if (window.state.searchMarker) window.state.searchMarker.setMap(null);
const icon = window.state.panel == "scenario-editor" ?
"assets/scenario.png" :
"assets/sitePin.png";
window.state.searchMarker = new window.googleAPI.maps.Marker({
map: window.state.map,
position: myLatLng,
icon: icon,
draggable: true
});
google.maps.event.addListener(window.state.searchMarker, 'dragend', latLongListener);
}
function addKeyboardFunctionality() {
var form = getElementById("form");
form.addEventListener("keyup", function(event) {
// Enter key
if (event.keyCode === 13) {
getElementById("submit-button").click();
}
});
}
},{"./views":4}],2:[function(require,module,exports){
/*jshint esversion: 7 */
const { initController } = require("./controller");
const { initMap, initViews } = require("./views");
const { setupModel } = require("./model");
const events = require("events");
const EM = new events.EventEmitter();
window.initMap = initMap;
window.state = setupModel(EM);
initController(EM);
initViews(EM);
},{"./controller":1,"./model":3,"./views":4,"events":47}],3:[function(require,module,exports){
/*jshint esversion: 7 */
const { getElementById } = require("./views");
exports.setupModel = setupModel;
function setupModel(EM) {
const state = {
panel: "home",
mapFeatures: {},
scenarioCount: 0,
scenarioId: null,
bubbleplotId: null,
site: {
name: "Home",
latitude: 36.15911,
longitude: -95.99374,
zoom: 18
},
tnoTable: {}
};
/**
* Create new site
*/
EM.on("new-site-submitted", () => {
try {
state.site = makeSite({
name: getElementById('name').value,
latitude: Number(getElementById('latitude').value),
longitude: Number(getElementById('longitude').value),
zoom: 18
});
} catch(error) {
window.alert(error);
EM.emit("change-panel");
return;
}
state.panel = "site-content";
EM.emit("change-panel");
});
/**
* Grab info from scenario input panel
*/
EM.on("create-edit-scenario", (scenarioId) => {
if (!scenarioId) {
scenarioId = "scenario-" + state.scenarioCount;
state.scenarioCount += 1;
}
state.mapItem = scenarioId;
try {
state.site.scenarioList[scenarioId] = new Scenario({
name: getElementById('name').value,
scenarioId: scenarioId,
material: getElementById('material').value,
latitude: Number(getElementById('latitude').value),
longitude: Number(getElementById('longitude').value),
range0: getElementById('range-0').value,
frequency0: getElementById('frange-0').value,
range1: getElementById('range-1').value,
frequency1: getElementById('frange-1').value,
range2: getElementById('range-2').value,
frequency2: getElementById('frange-2').value
});
} catch (error) {
window.alert(error);
EM.emit("change-panel");
return;
}
window.state.panel = "site-content";
window.state.mapItem = null;
EM.emit("change-panel");
});
EM.on("create-bubbleplot", (bubbleplotId) => {
if (!bubbleplotId) {
bubbleplotId = "bubbleplot-" + state.scenarioCount;
state.scenarioCount += 1;
}
state.bubbleplotId = bubbleplotId;
let rangelist = {};
for (const scenario of Object.keys(state.site.scenarioList)) {
const range0check = getElementById(scenario + "-range0");
const range1check = getElementById(scenario + "-range1");
const range2check = getElementById(scenario + "-range2");
if (range0check || range1check || range2check) rangelist[scenario] = [];
if (range0check.checked) rangelist[scenario].push("range0");
if (range1check.checked) rangelist[scenario].push("range1");
if (range2check.checked) rangelist[scenario].push("range2");
}
try {
state.site.bubbleplotList[bubbleplotId] = new Bubbleplot({
name: getElementById('name').value,
bubbleplotId: bubbleplotId,
rangelist: rangelist
});
} catch (error) {
window.alert(error);
EM.emit("change-panel");
return;
}
window.state.panel = "site-content";
window.state.mapItem = null;
EM.emit("change-panel");
});
EM.on("delete-siteItem", () => {
if(state.site.scenarioList[state.mapItem]) {
delete state.site.scenarioList[state.mapItem];
window.state.panel = "site-content";
window.state.mapItem = null;
EM.emit("change-panel");
} else if (state.site.bubbleplotList[state.mapItem]) {
delete state.site.bubbleplotList[state.mapItem];
window.state.panel = "site-content";
window.state.mapItem = null;
EM.emit("change-panel");
} else {
throw new Error("No scenarioMarker exists for " + state.mapItem);
}
});
try {
$.getJSON("data/tnoTable.json", function(json) {
state.tnoTable = json;
});
} catch (error) {
throw new Error("Error Loading data: ", error);
}
return state;
}
function Scenario (scenarioInputs) {
if (!scenarioInputs.name) throw new Error("Name is required");
if (!scenarioInputs.latitude) throw new Error("Latitude is required (click to place on map)");
if (!scenarioInputs.longitude) throw new Error("Longitude is required (click to place on map)");
if (!scenarioInputs.scenarioId) throw new Error("ScenarioId is not being assigned");
const defaultValues = {
material: null,
hidden: false,
rangesHidden: false
};
scenarioInputs.latitude = Number(scenarioInputs.latitude).toFixed(5);
scenarioInputs.longitude = Number(scenarioInputs.longitude).toFixed(5);
return Object.assign(this, defaultValues, scenarioInputs);
}
function Bubbleplot (inputs) {
if (!inputs.name) throw new Error("Name is required");
if (!inputs.bubbleplotId) throw new Error("bubbleplotId is not being assigned");
if (inputs.rangelist === []) throw new Error("At least one range must be selected");
const defaultValues = {
hidden: false,
rangesHidden: false,
};
defaultValues.path = [];
for (const scenario of Object.keys(inputs.rangelist)) {
const location = window.state.site.scenarioList[scenario];
const myLatLng = new window.googleAPI.maps.LatLng(location.latitude, location.longitude);
for (const range of inputs.rangelist[scenario]) {
defaultValues.path.push(makeCirclePath(myLatLng, location[range]));
}
}
return Object.assign(this, defaultValues, inputs);
}
Scenario.prototype = {
constructor: Scenario,
update: function (newScenarioInput) { return Object.assign(this, newScenarioInput); }
};
function makeSite (overrides) {
if (!overrides.name) throw new Error("Name is required");
if (!overrides.latitude) throw new Error("Latitude is required (click to place on map)");
if (!overrides.longitude) throw new Error("Longitude is required (click to place on map)");
const defaultValues = {
scenarioList: {},
bubbleplotList: {}
};
overrides.latitude = Number(overrides.latitude).toFixed(5);
overrides.longitude = Number(overrides.longitude).toFixed(5);
return Object.assign(defaultValues, overrides);
}
function makeCirclePath(point, radius) {
// https://stackoverflow.com/questions/23154254/google-map-multiple-overlay-no-cumulative-opacity
const d2r = Math.PI / 180; // degrees to radians
const r2d = 180 / Math.PI; // radians to degrees
const earthsradius = 6371000; // 3963 is the radius of the earth in meters
const points = 32;
// find the raidus in lat/lon
const rlat = (radius / earthsradius) * r2d;
const rlng = rlat / Math.cos(point.lat() * d2r);
const extp = [];
for (let i=0; i < points + 1; i++) {
const theta = Math.PI * (i / (points/2));
const ey = point.lng() + (rlng * Math.cos(theta)); // center a + radius x * cos(theta)
const ex = point.lat() + (rlat * Math.sin(theta)); // center b + radius y * sin(theta)
extp.push(new google.maps.LatLng(ex, ey));
}
return extp;
}
},{"./views":4}],4:[function(require,module,exports){
/*jshint esversion: 7 */
const Handlebars = require("handlebars");
exports.getElementById = getElementById;
exports.initMap = initMap;
exports.initViews = initViews;
const NUMRANGES = 3;
/*
* Sets up event listeners
*/
function initViews(EM) {
EM.on("change-panel", () => {
const panel = window.state.panel;
const site = window.state.site;
if (panel === "site-editor") {
showSiteEditor(site, EM);
mapSiteMarker(site);
} else if (panel === "site-content") {
showSiteContentPanel(site, EM);
mapSiteMarker(site);
mapAll(window.state.site.scenarioList);
mapBubbleplots(window.state.site.bubbleplotList);
} else if (panel === "scenario-editor") {
showScenarioPanel(window.state.mapItem, EM);
mapSiteMarker(site);
} else if (panel === "bubbleplot-editor") {
showBubbleplotPanel(window.state.mapItem, EM);
mapSiteMarker(site);
mapAll(window.state.site.scenarioList);
} else {
console.err("No panel of the name ", panel);
}
});
}
/*
* Utility: Find an element on the page or throw a helpful error.
*/
function getElementById(id) {
const input = document.getElementById(id);
if (!input) {
throw new Error(
'Could not find the element with the id "' + id + '" on the page.'
);
}
return input;
}
/**
* Utility: Generic Function to create a Handlebars panel from a template script id
*/
function createHandlebarsViewFromTemplateId (elementId, templateId, context) {
const templateInfo = getElementById(templateId).innerHTML;
createHandlebarsViewFromTemplate(elementId,templateInfo, context);
}
/*
* Utility: Generic Function to create a Handlebars panel from a template
*/
function createHandlebarsViewFromTemplate (elementId, templateInfo, context) {
const element = getElementById(elementId);
const template = Handlebars.compile(templateInfo);
const templateData = template(context);
element.innerHTML = templateData;
}
/*
* Initializes the google maps map in the approriate div
*/
function initMap() {
//Initialize map to arbitrary location.
window.googleAPI = google;
const myLatLng = new window.googleAPI.maps.LatLng(36.15911, -95.99374);
//Home: 36.15911, -95.99374
window.state.map = new window.googleAPI.maps.Map(getElementById('map'), {
center: myLatLng,
zoom: 18,
mapTypeId: 'satellite'});
window.state.map.setTilt(0);
}
/*
* Utility: Clears the Google Maps map of all markers and other features
*/
function clearMap() {
const mapFeatures = window.state.mapFeatures;
if(mapFeatures.siteMarker) {
mapFeatures.siteMarker.setMap(null);
}
if(mapFeatures.scenarioList) {
for (const scenario of Object.values(mapFeatures.scenarioList)) {
for (const mapFeature of Object.values(scenario)) {
mapFeature.setMap(null);
}
}
}
if(mapFeatures.bubbleplotList) {
for (const mapFeature of Object.values(mapFeatures.bubbleplotList)) {
mapFeature.setMap(null);
}
}
window.state.mapFeatures = {};
}
/*
* Utility: Sets the map back to the set middle location
*/
function returnHome(location) {
const myLatLng = new window.googleAPI.maps.LatLng(location.latitude, location.longitude);
window.state.map.panTo(myLatLng);
window.state.map.setTilt(0);
window.state.map.setZoom(location.zoom);
}
/*
* Clears map and maps the site marker
*/
function mapSiteMarker (location) {
clearMap();
const myLatLng = new window.googleAPI.maps.LatLng(location.latitude, location.longitude);
window.state.map.panTo(myLatLng);
window.state.map.setTilt(0);
window.state.map.setZoom(18);
createHandlebarsViewFromTemplate("title", "<h1>Site: {{name}} </h1>", location);
if (window.state.mapFeatures.siteMarker) window.state.mapFeatures.siteMarker.setMap(null);
window.state.mapFeatures.siteMarker = new window.googleAPI.maps.Marker({
map: window.state.map,
title: location.name,
position: myLatLng,
icon: "assets/sitePin.png"
});
}
/*
* Maps all scenario markers and hazard range circles
*/
function mapAll (scenarioList) {
if (!window.state.mapFeatures) window.state.mapFeatures = {};
if (!window.state.mapFeatures.scenarioList) window.state.mapFeatures.scenarioList = {};
if (scenarioList && scenarioList != {}) {
const scenarios = Object.entries(scenarioList);
for (const [scenarioId, scenario] of scenarios) {
const { hidden, rangesHidden } = scenario;
if (!hidden) {
mapScenario(scenarioId, scenario);
if(!rangesHidden) { mapHazardRanges(scenarioId, scenario); }
}
}
}
}
function mapBubbleplots (bubbleplotList) {
if (!window.state.mapFeatures) window.state.mapFeatures = {};
if (!window.state.mapFeatures.bubbleplotList) window.state.mapFeatures.bubbleplotList = {};
if (bubbleplotList && bubbleplotList != {}) {
const bubbleplots = Object.entries(bubbleplotList);
for (const [ bubbleplotId, bubbleplot ] of bubbleplots) {
const { hidden, name, path } = bubbleplot;
if (!hidden) {
const colors = ["#F0F", "#F00", "#00F"];
window.state.mapFeatures.bubbleplotList[bubbleplotId] = new google.maps.Polygon({
paths: path,
strokeOpacity: 0,
strokeWeight: 0,
fillColor: "#F00",
fillOpacity: 0.35
});
window.state.mapFeatures.bubbleplotList[bubbleplotId].setMap(window.state.map);
}
}
}
}
function mapScenario (scenarioId, scenario) {
const { name, latitude, longitude } = scenario;
const myLatLng = new window.googleAPI.maps.LatLng(latitude, longitude);
window.state.mapFeatures.scenarioList[scenarioId] = {};
window.state.mapFeatures.scenarioList[scenarioId].marker = new window.googleAPI.maps.Marker({
map: window.state.map,
title: name,
position: myLatLng,
icon: "assets/scenario.png"
});
}
function mapHazardRanges(scenarioId, scenario) {
const { name, latitude, longitude } = scenario;
const colors = ["#F0F", "#F00", "#00F"];
for (let i = 0; i < NUMRANGES; i++) {
window.state.mapFeatures.scenarioList[scenarioId]['range'+i] = drawGoogleMapsCircle(latitude, longitude, scenario["range" + i], colors[i]);
}
}
function drawGoogleMapsCircle(latitude, longitude, radius, color) {
//creates Google Maps radius for HazMat
const myLatLng = new google.maps.LatLng(Number(latitude), Number(longitude));
const circle = new google.maps.Circle({
map: window.state.map,
radius: Number(radius),
center: myLatLng,
fillOpacity: 0,
strokeColor: color,
strokeOpacity: 0.8,
strokeWeight: 2,
});
return circle;
}
/*
* Bring up site editor panel
*/
function showSiteEditor(site, EM) {
returnHome(site);
createHandlebarsViewFromTemplateId("navigator", "site-template", site);
getElementById("name").select();
EM.emit("panel-created");
}
/*
* Bring up site content panel
*/
function showSiteContentPanel (site, EM) {
createHandlebarsViewFromTemplateId("navigator", "site-contents-panel", site);
createHandlebarsViewFromTemplateId("edit-save-btn-group", "site-template-buttons", {});
EM.emit("panel-created");
}
/*
* Bring up scenario editor panel
*/
function showScenarioPanel (scenarioId, EM) {
if(!window.state.mapFeatures.scenarioList)
window.state.mapFeatures.scenarioList = {};
const site = window.state.site;
const scenario = setNewOrGetScenario(site);
createHandlebarsViewFromTemplateId("navigator", "scenario-panel", scenario);
createHandlebarsViewFromTemplateId("modalDiv", "model-modal", scenario);
// remove from current scenario from map
if(window.state.mapFeatures.scenarioList[scenarioId]) {
window.state.mapFeatures.scenarioList[scenarioId].marker.setMap(null);
}
const dropdown = getElementById("tnoCurveSelect");
for (const optionText of Object.keys(window.state.tnoTable)) {
const option = document.createElement("option");
option.text = optionText;
dropdown.add(option);
}
getElementById("name").select();
EM.emit("panel-created");
function setNewOrGetScenario(site) {
if (!scenarioId) {
return {
name: "scenario-" + window.state.scenarioCount,
latitude: site.latitude,
longitude: site.longitude
};
} else {
return site.scenarioList[scenarioId];
}
}
}
/*
* Bring up bubbleplot editor panel
*/
function showBubbleplotPanel (scenarioId, EM) {
createHandlebarsViewFromTemplateId("navigator", "bubbleplot-panel", window.state.site);
EM.emit("panel-created");
}
},{"handlebars":34}],5:[function(require,module,exports){
'use strict';
exports.__esModule = true;
// istanbul ignore next
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _handlebarsRuntime = require('./handlebars.runtime');
var _handlebarsRuntime2 = _interopRequireDefault(_handlebarsRuntime);
// Compiler imports
var _handlebarsCompilerAst = require('./handlebars/compiler/ast');
var _handlebarsCompilerAst2 = _interopRequireDefault(_handlebarsCompilerAst);
var _handlebarsCompilerBase = require('./handlebars/compiler/base');
var _handlebarsCompilerCompiler = require('./handlebars/compiler/compiler');
var _handlebarsCompilerJavascriptCompiler = require('./handlebars/compiler/javascript-compiler');
var _handlebarsCompilerJavascriptCompiler2 = _interopRequireDefault(_handlebarsCompilerJavascriptCompiler);
var _handlebarsCompilerVisitor = require('./handlebars/compiler/visitor');
var _handlebarsCompilerVisitor2 = _interopRequireDefault(_handlebarsCompilerVisitor);
var _handlebarsNoConflict = require('./handlebars/no-conflict');
var _handlebarsNoConflict2 = _interopRequireDefault(_handlebarsNoConflict);
var _create = _handlebarsRuntime2['default'].create;
function create() {
var hb = _create();
hb.compile = function (input, options) {
return _handlebarsCompilerCompiler.compile(input, options, hb);
};
hb.precompile = function (input, options) {
return _handlebarsCompilerCompiler.precompile(input, options, hb);
};
hb.AST = _handlebarsCompilerAst2['default'];
hb.Compiler = _handlebarsCompilerCompiler.Compiler;
hb.JavaScriptCompiler = _handlebarsCompilerJavascriptCompiler2['default'];
hb.Parser = _handlebarsCompilerBase.parser;
hb.parse = _handlebarsCompilerBase.parse;
hb.parseWithoutProcessing = _handlebarsCompilerBase.parseWithoutProcessing;
return hb;
}
var inst = create();
inst.create = create;
_handlebarsNoConflict2['default'](inst);
inst.Visitor = _handlebarsCompilerVisitor2['default'];
inst['default'] = inst;
exports['default'] = inst;
module.exports = exports['default'];
},{"./handlebars.runtime":6,"./handlebars/compiler/ast":8,"./handlebars/compiler/base":9,"./handlebars/compiler/compiler":11,"./handlebars/compiler/javascript-compiler":13,"./handlebars/compiler/visitor":16,"./handlebars/no-conflict":30}],6:[function(require,module,exports){
'use strict';
exports.__esModule = true;
// istanbul ignore next
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
// istanbul ignore next