-
Notifications
You must be signed in to change notification settings - Fork 3
/
safemap.js
6391 lines (5130 loc) · 220 KB
/
safemap.js
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
//
// Copyright (C) 2011 Lionel Bergeret
//
// ----------------------------------------------------------------
// The contents of this file are distributed under the CC0 license.
// See http://creativecommons.org/publicdomain/zero/1.0/
// ----------------------------------------------------------------
//
// Modifications - 2014, 2015, 2016, 2017 - Nick Dolezal
// safemap.js is the primary code-behind for the Safecast webmap and loads all other components
// asynchronously as needed.
// ===============================================================================================
// =========================================== GLOBALS ===========================================
// ===============================================================================================
// ========== GOOGLE MAPS OBJECTS =============
var map = null;
var geocoder = null;
// ========== RETAINED INSTANCES =============
var _bitsProxy = null; // retained proxy instance for bitmap indices
var _bvProxy = null; // retained proxy instance for bGeigie Log Viewer
var _hudProxy = null; // retained proxy instance for HUD / reticle value lookup
var _rtvm = null; // retained RT sensor viewer instance
var _mapPolysProxy = null; // retained proxy instance for map polygons
var _flyToExtentProxy = null; // retained proxy instance for map pans/zooms/stylized text display
var _locStringsProxy = null; // retained proxy instance for localized UI strings
var slideout = null; // retained slideout menu
var _userloc = null; // retained user location marker / loc callback
var _igProxy = null;
var _igProxyAir = null;
// ========== INTERNAL STATES =============
var _cached_ext = { baseurl:null, urlyxz:null, lidx:-1, cd:false, cd_y:0.0, cd_x:0.0, cd_z:0, midx:-1, mt:null };
var _lastLayerIdx = 0;
var _disable_alpha = false; // hack for media request regarding layer opacity
var _cm_hidden = true; // state of menu visibility - cached to reduce CPU hit on map pans
var _ui_layer_idx = 0;
var _ui_menu_layers_more_visible = false;
var _ui_menu_basemap_more_visible = false;
var _system_os_ios = navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPhone/i);
var _last_history_push_ms = -1;
var _img_tile_shadow_idx = -1;
var _rt_ptcast_enabled = true;
var _rt_ingest_enabled = true;
// ========== USER PREFS =============
var _no_hdpi_tiles = false;
var _img_scaler_idx = 1;
var _use_jp_region = false;
var _use_https = window.location.href.substring(0,5) == "https";
var _meta_content_idx = 0; // radiation = 0, air = 1
// ============ LEGACY SUPPORT =============
var _bs_ready = true; // HACK for legacy "show bitstores"
var _layerBitstores = null; // HACK for legacy "show bitstores"
var useBitmapIdx = true; // HACK for legacy "show bitstores"
var _cached_baseURL = null; // 2015-08-22 ND: fix for legacy "show bitstores"
// ========== GOOGLE MAPS LAYERS =============
var overlayMaps = null;
var basemapMapTypes = null;
// ============= TEST ================
var _test_client_render = false; // should be off here by default
var LOCAL_TEST_MODE = false; // likely does *not* work anymore.
// ===============================================================================================
// ============================================= INIT ============================================
// ===============================================================================================
var SafemapInit = (function()
{
function SafemapInit()
{
}
var _InitUseJpRegion = function()
{
var jstmi = -540;
var tzmi = (new Date()).getTimezoneOffset(); // JST = -540
_use_jp_region = (jstmi - 180) <= tzmi && tzmi <= (jstmi + 180); // get +/- 3 TZs from Japan... central asia - NZ
};
var _InitAboutMenu = function()
{
AListId("aMenuAbout", "click", SafemapPopupHelper.ToggleAboutPopup);
AListId("about_content", "click", SafemapPopupHelper.ToggleAboutPopup);
};
var _InitLogIdsFromQuerystring = function()
{
var logIds = SafemapUI.GetParam("logids");
if (logIds != null && logIds.length > 0)
{
_bvProxy.AddLogsCSV(logIds, false);
}//if
};
var _GetDefaultBasemapOrOverrideFromQuerystring = function()
{
var midx = SafemapUI.QueryString_GetParamAsInt("m");
if (midx == -1) midx = SafemapUI.QueryString_GetParamAsInt("midx");
if (midx == -1) midx = PrefHelper.GetBasemapUiIndexPref();
return BasemapHelper.GetMapTypeIdForBasemapIdx(midx);
};
var _InitDefaultRasterLayerOrOverrideFromQuerystring = function()
{
var lidx = SafemapUI.QueryString_GetParamAsInt("l");
if (lidx == -1) lidx = SafemapUI.QueryString_GetParamAsInt("lidx");
if (lidx == -1)
{
lidx = PrefHelper.GetLayerUiIndexPref();
// 2016-11-21 ND: Fix for proxy value being stored as pref
if (lidx == 12) lidx = 13;
}//if
LayersHelper.SetSelectedIdxAndSync(lidx);
if (LayersHelper.IsIdxTimeSlice(lidx))
{
TimeSliceUI.SetPanelHidden(false);
TimeSliceUI.UpdateLabelsForIdx(lidx);
}//if
};
// The more complete version of IsDefaultLocation().
// This accomodates the location preference. Previously, it could be
// safely assumed that if a link with the location wasn't followed,
// it was the default location and the text should be displayed.
// However, this should not be used for the case of determining whether
// or not to autozoom to logids in the querystring. Rather, the
// old IsDefaultLocation() should be checked for that.
var _IsDefaultLocationOrPrefLocation = function()
{
var d = SafemapUI.IsDefaultLocation();
if (d)
{
var yx = SafemapUtil.GetNormalizedMapCentroid();
var z = map.getZoom();
d = z == 9 && Math.abs(yx.x - 140.515516) < 0.000001
&& Math.abs(yx.y - 37.316113) < 0.000001;
}//if
return d;
};
var _InitShowLocationIfDefault = function()
{
if (_IsDefaultLocationOrPrefLocation() && SafemapUI.GetParam("logids").length == 0 && "requestAnimationFrame" in window)
{
_flyToExtentProxy.ShowLocationText("Honshu, Japan");
}//if
};
var _InitContextMenu = function()
{
if (SafemapUI.IsBrowserOldIE() || map == null || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPhone/i)) return;
// Original from http://justgizzmo.com/2010/12/07/google-maps-api-v3-context-menu/
var cm = document.createElement("ul");
cm.id = "contextMenu";
cm.style.display = "none";
cm.innerHTML = '<li><a href="#apiQuery" class="FuturaFont">Query Safecast API Here</a></li>'
+ '<li class="separator"></li>'
+ '<li><a href="#zoomIn" class="FuturaFont">Zoom In</a></li>'
+ '<li><a href="#zoomOut" class="FuturaFont">Zoom Out</a></li>'
+ '<li><a href="#centerHere" class="FuturaFont">Center Map Here</a></li>';
document.getElementById("map_canvas").appendChild(cm);
var clickLL;
var fxClickRight = function(e)
{
_cm_hidden = false;
SafemapUI.AnimateElementFadeIn(cm, -1.0, 0.166666666667);
var mapDiv = document.getElementById("map_canvas");
var x = e.pixel.x;
var y = e.pixel.y;
clickLL = e.latLng;
if (x > mapDiv.offsetWidth - cm.offsetWidth) x -= cm.offsetWidth;
if (y > mapDiv.offsetHeight - cm.offsetHeight) y -= cm.offsetHeight;
cm.style.top = ""+y+"px";
cm.style.left = ""+x+"px";
};
google.maps.event.addListener(map, "rightclick", fxClickRight);
var fxClickLeft = function(e)
{
var action = this.getAttribute("href").substr(1);
var retVal = false;
switch (action)
{
case "zoomIn":
map.setZoom(map.getZoom() + 3);
map.panTo(clickLL);
break;
case "zoomOut":
map.setZoom(map.getZoom() - 3);
map.panTo(clickLL);
break;
case "centerHere":
map.panTo(clickLL);
break;
case "null":
break;
case "showIndices1":
ShowBitmapIndexVisualization(true, 4);
break;
case "showIndices2":
ShowBitmapIndexVisualization(false, 4);
break;
case "apiQuery":
SafemapUI.QuerySafecastApiAsync(clickLL.lat(), clickLL.lng(), map.getZoom());
break;
default:
retVal = true;
break;
}//switch
_cm_hidden = true;
cm.style.display = "none";
return retVal;
};
var as = cm.getElementsByTagName("a");
for (var i=0; i<as.length; i++)
{
as[i].addEventListener("click", fxClickLeft, false);
as[i].addEventListener("mouseover", function() { this.parentNode.className = "hover"; }.bind(as[i]), false);
as[i].addEventListener("mouseout", function() { this.parentNode.className = null; }.bind(as[i]), false);
}//for
var events = [ "click" ]; //"dragstart", "zoom_changed", "maptypeid_changed"
var hide_cb = function(e)
{
if (!_cm_hidden)
{
_cm_hidden = true;
cm.style.display = "none";
}//if
};
for (var i=0; i<events.length; i++)
{
google.maps.event.addListener(map, events[i], hide_cb);
}//for
};
// supports showing the bitmap indices, which is contained in legacy code
// with nasty deps that i haven't had time to rewrite.
var _ShowBitmapIndexVisualization = function(isShowAll, rendererId)
{
if (!_bitsProxy.GetIsReady()) // bad way of handling deps... but this is just a legacy hack anyway.
{
_setTimeout(function() { _ShowBitmapIndexVisualization(isShowAll, rendererId); }.bind(this), 500);
return;
}//if
_cached_baseURL = _cached_ext.baseurl; // 2015-08-22 ND: fix for legacy bitmap viewer support
_layerBitstores = new Array();
_bitsProxy.InitLayerIds([2,3,6,8,9,16]);
for (var i=0; i<_bitsProxy._layerBitstores.length; i++)
{
_layerBitstores.push(_bitsProxy._layerBitstores[i]);
}
if (_rtvm != null) _rtvm.RemoveAllMarkersFromMapAndPurgeData();
SafemapUI.RequireJS("bmp_lib_min.js", false, null, null); // ugly bad legacy feature hack, but not worth rewriting this at the moment
SafemapUI.RequireJS("png_zlib_min.js", false, null, null);
SafemapUI.RequireJS("gbGIS_min.js", false, null, null);
TestDump(isShowAll, rendererId);
};
var _InitGMapsStyleHack = function()
{
var ff = "Futura,Futura-Medium,'Futura Medium','Futura ND Medium','Futura Std Medium','Futura Md BT','Century Gothic',Roboto,'Segoe UI',Helvetica,Arial,sans-serif";
var fr = function(el_name) {
var ds = ElGet("map_canvas").getElementsByTagName(el_name);
if (ds == null) return;
for (var i=0; i<ds.length; i++)
{
var s = ds[i].style;
if (s != null && s.fontFamily != null && s.fontFamily.indexOf("Roboto") > -1 && s.fontFamily.indexOf("Futura") == -1) {
ds[i].style.fontFamily = ff;
}
}
};
setTimeout(fr("div"), 500);
};
var _InjectSafariPerfFix = function()
{
if ( navigator.platform != null && navigator.platform == "MacIntel"
&& navigator.vendor != null && navigator.vendor == "Apple Computer, Inc."
&& (_nua("Version/8.") || _nua("Version/9.") || _nua("Version/1"))
&& !_nua("Mobile"))
{
var s = ElCr("style");
s.type = "text/css";
s.innerHTML = "#map_canvas div { -webkit-transform:translateZ(0px); -webkit-backface-visibility:hidden; }";
document.head.appendChild(s);
}
};
var _ApplyFirefoxNoDragHack = function()
{
if (!("MozUserSelect" in document.body.style)) return;
var a = ["imgMenuSafecastIcon", "imgMenuReticle"];
var f = function(e) { e.preventDefault(); return false; };
for (var i=0; i<a.length; i++) { AListId(a[i],"dragstart",f); }
};
SafemapInit.InitRtViewer = function()
{
if (_rtvm == null && !SafemapUI.IsBrowserOldIE() && "ArrayBuffer" in window)
{
var cb = function() {
_rtvm = new RTVM(map, null);
}.bind(this);
SafemapUI.RequireJS(SafemapUI.GetContentBaseUrl() + "rt_viewer_min.js", true, cb, null);
}//if
};
var _Legend_CreateEntryNode = function(entry)
{
var d = ElCr("div");
var i = ElCr("img");
var t = ElCr("div");
t.id = entry.t;
i.src = entry.i;
if (entry.c != null)
{
i.style = entry.c;
}//if
d.className = "map_legend_fs_entry";
i.className = "map_legend_fs_entry_img";
t.className = "map_legend_fs_entry_txt";
d.appendChild(i);
d.appendChild(t);
return d;
};
var _Legend_CreateSectionNode =function(pnlId, pnlLblId, entries)
{
var pnl_div = ElCr("div");
var pnl_fs = ElCr("fieldset");
var pnl_txt = ElCr("legend");
var pnl_det = ElCr("div");
pnl_div.id = pnlId;
pnl_txt.id = pnlLblId;
pnl_fs.className = "map_legend_fs";
pnl_det.className = "map_legend_fs_pnl";
pnl_div.appendChild(pnl_fs);
pnl_fs.appendChild(pnl_txt);
pnl_fs.appendChild(pnl_det);
for (var i=0; i<entries.length; i++)
{
var e = _Legend_CreateEntryNode(entries[i]);
pnl_det.appendChild(e);
}//for
return pnl_div;
}//Legend_CreateSectionNode
var _InitMapLegend = function()
{
var a = [ { i:"legend/air-online_154x154.png", t:"lblAirOn", c:null },
{ i:"legend/air-max_154x154.png", t:"lblAirMax", c:null },
{ i:"legend/air-online_154x154.png", t:"lblAirInc", c:"transform: rotate(45deg);" },
{ i:"legend/air-offline_154x154.png", t:"lblAirOff", c:null },
{ i:"legend/air-cur_154x154.png", t:"lblAirCur", c:null },
{ i:"legend/air-online_154x154.png", t:"lblAirNoc", c:"transform: rotate(90deg);" },
{ i:"legend/lut-20_256x1.png", t:"lblAirLut", c:null },
{ i:"legend/air-min_154x154.png", t:"lblAirMin", c:null },
{ i:"legend/air-online_154x154.png", t:"lblAirDec", c:"transform: rotate(135deg);" } ];
var r = [ { i:"legend/rad-online_77x77.png", t:"lblRadOn", c:null },
{ i:"legend/rad-offline_77x77.png", t:"lblRadOff", c:null },
{ i:"legend/lut-30_256x1.png", t:"lblRadLut", c:null } ];
var n = ElGet("map_legend");
var an = _Legend_CreateSectionNode("pnlLegendAir", "lblPnlAir", a);
var rn = _Legend_CreateSectionNode("pnlLegendRad", "lblPnlRad", r);
n.appendChild(an);
n.appendChild(rn);
var e = ElCr("div");
e.style = "cursor:pointer; position:absolute; top:3px; right:3px; font-size:9px;";
var i = ElCr("img");
i.id = "btnLegendClose";
i.style.width = "13px";
i.style.height = "13px";
i.src = "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2224px%22%20height%3D%2224px%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22%23000000%22%3E%0A%20%20%20%20%3Cpath%20d%3D%22M19%206.41L17.59%205%2012%2010.59%206.41%205%205%206.41%2010.59%2012%205%2017.59%206.41%2019%2012%2013.41%2017.59%2019%2019%2017.59%2013.41%2012z%22%2F%3E%0A%20%20%20%20%3Cpath%20d%3D%22M0%200h24v24H0z%22%20fill%3D%22none%22%2F%3E%0A%3C%2Fsvg%3E%0A";
e.appendChild(i);
n.appendChild(e);
};
SafemapInit.Init = function()
{
if (document == null || document.body == null) return; // real old browsers that are going to break on everything
_cached_ext.baseurl = SafemapUI.GetBaseWindowURL();
PrefHelper.MakeFx(); // must happen before MenuHelperStub.Init();
MenuHelperStub.Init(); // must happen before basemaps or layers are init
_bitsProxy = new BitsProxy("layers"); // mandatory, never disable
_bvProxy = new BvProxy(); // mandatory, never disable
_hudProxy = new HudProxy(); // mandatory, never disable
_mapPolysProxy = new MapPolysProxy(); // mandatory, never disable
_flyToExtentProxy = new FlyToExtentProxy(); // mandatory, never disable
_locStringsProxy = new LocalizedStringsProxy(); // mandatory, never disable
_InitUseJpRegion();
if (_bitsProxy.GetUseBitstores()) // *** bitmap index dependents ***
{
var showIndicesParam = SafemapUI.QueryString_GetParamAsInt("showIndices");
if (showIndicesParam != -1)
{
var rendererIdParam = SafemapUI.QueryString_GetParamAsInt("rendererId");
setTimeout(function() { _ShowBitmapIndexVisualization(showIndicesParam == 1, rendererIdParam == -1 ? 4 : rendererIdParam); }.bind(this), 500);
return; // this is a destructive action, no need for rest of init.
}//if
}//if
// ************************** GMAPS **************************
var yxz = SafemapUI.GetUserLocationFromQuerystring();
var yx = yxz.yx != null ? yxz.yx : new google.maps.LatLng(PrefHelper.GetVisibleExtentYPref(), PrefHelper.GetVisibleExtentXPref());
var z = yxz.z != -1 ? yxz.z : PrefHelper.GetVisibleExtentZPref();
var map_options =
{
zoom: z,
maxZoom: 21,
center: yx,
scrollwheel: true,
zoomControl: PrefHelper.GetZoomButtonsEnabledPref(),
panControl: false,
scaleControl: true,
mapTypeControl: false,
streetViewControl: true,
navigationControl: true,
overviewMapControl: false,
gestureHandling: "greedy",
streetViewControlOptions: { position: google.maps.ControlPosition.RIGHT_BOTTOM },
zoomControlOptions: { position: google.maps.ControlPosition.RIGHT_BOTTOM },
rotateControlOptions: { position: google.maps.ControlPosition.RIGHT_BOTTOM },
navigationControlOptions: { style: google.maps.NavigationControlStyle.DEFAULT },
mapTypeControlOptions: {
position: google.maps.ControlPosition.TOP_RIGHT,
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
mapTypeIds: BasemapHelper.basemaps
},
mapTypeId: _GetDefaultBasemapOrOverrideFromQuerystring()
};
if (PrefHelper.GetMenuThemePref() == 1)
{
map_options.backgroundColor = "#444";
}//if
map = new google.maps.Map(document.getElementById("map_canvas"), map_options);
BasemapHelper.InitBasemaps(); // must occur after "map" ivar is set
ClientZoomHelper.InitGmapsLayers();
TimeSliceUI.Init();
_InitDefaultRasterLayerOrOverrideFromQuerystring();
SafemapExtent.OnChange(SafemapExtent.Event.ZoomChanged); //fire on init for client zoom
// arbitrarily space out some loads / init that don't need to happen right now, so as not to block on the main thread here.
setTimeout(function() {
SafemapExtent.InitEvents();
_locStringsProxy.Init();
}, 250);
setTimeout(function() {
_InitLogIdsFromQuerystring();
_InitGMapsStyleHack;
var cb = function() { SafemapExtent.OnChange(SafemapExtent.Event.DragEnd); SafemapExtent.OnChange(SafemapExtent.Event.ZoomChanged); };
_flyToExtentProxy.Init(map, cb);
}, 500);
setTimeout(function() {
//_InitRtViewer();
var rp = function(gs,eps) { MenuHelper.RegisterGroupsAndPolys(gs,eps); };
var gl = function() { return PrefHelper.GetEffectiveLanguagePref(); };
var gs = function(s,cb) { _locStringsProxy.GetMenuStrings(s, cb); };
_mapPolysProxy.Init(map, rp, gl, gs);
}, 1000);
setTimeout(function() {
_InitShowLocationIfDefault();
}, 1500);
setTimeout(function() {
//_igProxy = new IgProxy(map);
_InitAboutMenu();
_InitContextMenu();
(map.getStreetView()).setOptions({ zoomControlOptions: { position: google.maps.ControlPosition.RIGHT_BOTTOM }, panControlOptions: { position: google.maps.ControlPosition.RIGHT_BOTTOM }, enableCloseButton:true, imageDateControl:true, addressControlOptions:{ position: google.maps.ControlPosition.TOP_RIGHT } });
}, 2000);
//setTimeout(function() {
// SafemapPopupHelper.WhatsNewShowIfNeeded();
//}, 3000);
_InitMapLegend();
MenuHelper.Init(); // contains its own delayed loads; should be at end of initialize()
_InjectSafariPerfFix();
_ApplyFirefoxNoDragHack();
};
return SafemapInit;
})();
// ===============================================================================================
// ======================================= BASEMAP HELPER ========================================
// ===============================================================================================
//
// BasemapHelper: 1. Initializes an array of Google Maps ImageMapTypes
// 2. Adds them to the Gmaps registry
// 3. Defines how the tile URLs are returned
//
// nb: When adding new basemaps, they must be added to:
// 1. BasemapHelper.basemaps
// 2. BasemapHelper.InitBasemaps
// 3. MenuHelperStub.GetBasemapIdxsWithUiVisibility
// 4. GetMenuStringsEn(), GetMenuStringsJa()
// 5. The end of the current menu tooltip spritesheet (thus changing the filename)
// 6. MenuHelper.InitTooltips
//
var BasemapHelper = (function()
{
function BasemapHelper()
{
}
BasemapHelper.basemaps =
[
// 2016-11-19 ND: The Google refs create a race condition in Safari due to differences
// in when this object is eval'd. Replacing with strings for now,
// eventually this should be moved to an instanced object and set
// at runtime.
//google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.SATELLITE,
//google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.TERRAIN,
"roadmap", "satellite",
"hybrid", "terrain",
"gray", "dark", "toner", "tlite", "wcolor",
"mapnik", "black", "white", "stamen_terrain",
"gsi_jp", "retro"
];
BasemapHelper.GetCurrentInstanceBasemapIdx = function()
{
var mapType = map.getMapTypeId();
var idx = 0;
for (var i=0; i<BasemapHelper.basemaps.length; i++)
{
if (mapType == BasemapHelper.basemaps[i])
{
idx = i;
break;
}
}
return idx;
};
BasemapHelper.GetMapTypeIdForBasemapIdx = function(idx)
{
if (idx < 0 || idx >= BasemapHelper.basemaps.length) idx = 0;
return BasemapHelper.basemaps[idx];
};
var _GetUrlFromTemplate = function(template, x, y, z, r, s)
{
var url = "" + template;
if (x != null) url = url.replace(/{x}/g, ""+x);
if (y != null) url = url.replace(/{y}/g, ""+y);
if (z != null) url = url.replace(/{z}/g, ""+z);
if (r != null) url = url.replace(/{r}/g, ""+r);
if (s != null) url = url.replace(/{s}/g, ""+s[(z + x + y) % s.length]);
return url;
};
var _fxGetNormalizedCoord = function(xy, z) { return SafemapUtil.GetNormalizedCoord(xy, z); };
var _GetGmapsMapStyled_Dark = function()
{
return [ {"stylers": [ { "invert_lightness": true }, { "saturation": -100 } ] },
{ "featureType": "water", "stylers": [ { "lightness": -100 } ] },
{ "elementType": "labels", "stylers": [ { "lightness": -57 }, { "visibility": "on" } ] },
{ "featureType": "administrative", "elementType": "geometry", "stylers": [ { "lightness": -57 } ] } ];
};
var _GetGmapsMapStyled_Gray = function()
{
return [ { "featureType": "water", "stylers": [ { "saturation": -100 }, { "lightness": -30 } ] },
{ "stylers": [ { "saturation": -100 }, { "lightness": 50 } ] },
{ "elementType": "labels.icon", "stylers": [ { "invert_lightness": true }, { "gamma": 9.99 }, { "lightness": 79 } ] } ];
};
var _GetGmapsMapStyled_Retro = function()
{
return [{"featureType":"administrative","stylers":[{"visibility":"off"}]},{"featureType":"poi","stylers":[{"visibility":"simplified"}]},{"featureType":"road","elementType":"labels","stylers":[{"visibility":"simplified"}]},{"featureType":"water","stylers":[{"visibility":"simplified"}]},{"featureType":"transit","stylers":[{"visibility":"simplified"}]},{"featureType":"landscape","stylers":[{"visibility":"simplified"}]},{"featureType":"road.highway","stylers":[{"visibility":"off"}]},{"featureType":"road.local","stylers":[{"visibility":"on"}]},{"featureType":"road.highway","elementType":"geometry","stylers":[{"visibility":"on"}]},{"featureType":"water","stylers":[{"color":"#84afa3"},{"lightness":52}]},{"stylers":[{"saturation":-17},{"gamma":0.36}]},{"featureType":"transit.line","elementType":"geometry","stylers":[{"color":"#3f518c"}]}];
};
var _NewGmapsBasemap = function(min_z, max_z, tile_size, url_template, name, r, subs)
{
var o =
{
getTileUrl: function(xy, z)
{
var nXY = _fxGetNormalizedCoord(xy, z);
return _GetUrlFromTemplate(url_template, nXY.x, nXY.y, z, r, subs);
},
tileSize: new google.maps.Size(tile_size, tile_size),
minZoom: min_z,
maxZoom: max_z,
name: name,
alt: name
};
return new google.maps.ImageMapType(o);
};
var _NewGmapsBasemapConst = function(tile_size, alt, name, tile_url) // single tile for all requests
{
var o =
{
getTileUrl: function(xy, z) { return tile_url; },
tileSize: new google.maps.Size(tile_size, tile_size),
minZoom: 0,
maxZoom: 23,
name: name,
alt: alt != null ? alt : name
};
return new google.maps.ImageMapType(o);
};
BasemapHelper.InitBasemaps = function()
{
var stam_r = window.devicePixelRatio > 1.5 ? "@2x" : "";
var stam_z = window.devicePixelRatio > 1.5 ? 18 : 19;
var stam_subs = ["a", "b", "c", "d"];
var osm_subs = ["a", "b", "c"];
var stam_pre = !_use_https ? "http://{s}.tile.stamen.com" : "https://stamen-tiles-{s}.a.ssl.fastly.net";
var o = { };
o.b0 = _NewGmapsBasemap(0, stam_z, 256, stam_pre + "/terrain/{z}/{x}/{y}{r}.png", "Stamen Terrain", stam_r, stam_subs);
o.b1 = _NewGmapsBasemap(0, stam_z, 256, stam_pre + "/toner/{z}/{x}/{y}{r}.png", "Stamen Toner", stam_r, stam_subs);
o.b2 = _NewGmapsBasemap(0, stam_z, 256, stam_pre + "/toner-lite/{z}/{x}/{y}{r}.png", "Stamen Toner Lite", stam_r, stam_subs);
o.b3 = _NewGmapsBasemap(0, 19, 256, stam_pre + "/watercolor/{z}/{x}/{y}.jpg", "Stamen Watercolor", null, stam_subs);
o.b4 = _NewGmapsBasemap(0, 19, 256, "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", "OpenStreetMap", null, osm_subs);
o.b9 = _NewGmapsBasemap(0, 18, 256, "https://cyberjapandata.gsi.go.jp/xyz/std/{z}/{x}/{y}.png", "GSI Japan", null, null);
o.b5 = _NewGmapsBasemapConst(256, "Pure Black World Tendency", "None (Black)", "data:image/gif;base64,R0lGODdhAQABAPAAAAAAAAAAACwAAAAAAQABAAACAkQBADs=");
o.b6 = _NewGmapsBasemapConst(256, "Pure White World Tendency", "None (White)", "data:image/gif;base64,R0lGODdhAQABAPAAAP///wAAACwAAAAAAQABAAACAkQBADs=");
o.b7 = new google.maps.StyledMapType(_GetGmapsMapStyled_Gray(), {name: "Map (Gray)" });
o.b8 = new google.maps.StyledMapType(_GetGmapsMapStyled_Dark(), {name: "Map (Dark)" });
o.b10 = new google.maps.StyledMapType(_GetGmapsMapStyled_Retro(), {name: "Map (Retro)"});
map.mapTypes.set( "stamen_terrain", o.b0);
map.mapTypes.set( "toner", o.b1);
map.mapTypes.set( "tlite", o.b2);
map.mapTypes.set("wcolor", o.b3);
map.mapTypes.set("mapnik", o.b4);
map.mapTypes.set( "black", o.b5);
map.mapTypes.set( "white", o.b6);
map.mapTypes.set( "gray", o.b7);
map.mapTypes.set( "dark", o.b8);
map.mapTypes.set("gsi_jp", o.b9);
map.mapTypes.set( "retro", o.b10);
basemapMapTypes = o;
};
return BasemapHelper;
})();
// ===============================================================================================
// ===================================== SAFECAST DATE HELPER ====================================
// ===============================================================================================
//
// SafecastDateHelper: Misc date conversion/helper functions, especially pertaining to the
// time series Safecast layers, which are defined here.
//
// nb: eventually, SafecastDateHelper, ClientZoomHelper, and LayersHelper
// should be combined into a single instanced class.
var SafecastDateHelper = (function()
{
function SafecastDateHelper()
{
}
var _JST_OFFSET_MS = 32400000.0; // 9 * 60 * 60 * 1000
// For a date 2011-03-10T15:00:00Z, returns 20110310, or YY+MM+DD
var _TrimIsoDateToFilenamePart = function(d)
{
return d.substring(0, 4) + d.substring(5, 7) + d.substring(8, 10);
};
var _GetShortIsoDate = function(d)
{
return d.substring(0, 10);
};
SafecastDateHelper.GetTimeSliceLayerDateRangesUTC = function()
{
// Format: ISO dates. Start date is inclusive, end date is exclusive
// eg: end date "15:00:00Z" means < 15:00:00Z, or <= 14:59:59.999Z
// nb: The base format is not used directly, but necessary for all others.
// Thus, a new mutable copy is returned.
var ds = [ { i:13, s:"2011-03-10T15:00:00Z", e:"2011-09-10T15:00:00Z" },
{ i:14, s:"2011-09-10T15:00:00Z", e:"2012-03-10T15:00:00Z" },
{ i:15, s:"2012-03-10T15:00:00Z", e:"2012-09-10T15:00:00Z" },
{ i:16, s:"2012-09-10T15:00:00Z", e:"2013-03-10T15:00:00Z" },
{ i:17, s:"2013-03-10T15:00:00Z", e:"2013-09-10T15:00:00Z" },
{ i:18, s:"2013-09-10T15:00:00Z", e:"2014-03-10T15:00:00Z" },
{ i:19, s:"2014-03-10T15:00:00Z", e:"2014-09-10T15:00:00Z" },
{ i:20, s:"2014-09-10T15:00:00Z", e:"2015-03-10T15:00:00Z" },
{ i:21, s:"2015-03-10T15:00:00Z", e:"2015-09-10T15:00:00Z" },
{ i:22, s:"2015-09-10T15:00:00Z", e:"2016-03-10T15:00:00Z" },
{ i:23, s:"2016-03-10T15:00:00Z", e:"2016-09-10T15:00:00Z" },
{ i:24, s:"2016-09-10T15:00:00Z", e:"2017-03-10T15:00:00Z" },
{ i:25, s:"2017-03-10T15:00:00Z", e:"2017-09-10T15:00:00Z" },
{ i:26, s:"2017-09-10T15:00:00Z", e:"2018-03-10T15:00:00Z" },
{ i:27, s:"2018-03-10T15:00:00Z", e:"2018-09-10T15:00:00Z" },
{ i:28, s:"2018-09-10T15:00:00Z", e:"2019-03-10T15:00:00Z" },
{ i:29, s:"2019-03-10T15:00:00Z", e:"2019-09-10T15:00:00Z" },
{ i:30, s:"2019-09-10T15:00:00Z", e:"2020-03-10T15:00:00Z" } ];
return ds;
};
SafecastDateHelper.IsLayerIdxTimeSliceLayerDateRangeIdx = function(idx)
{
var src = SafecastDateHelper.GetTimeSliceLayerDateRangesUTC();
var is_ts = false;
for (var i=0; i<src.length; i++)
{
if (src[i].i == idx)
{
is_ts = true;
break;
}//if
}//for
return is_ts;
};
var _GetIsoDateForIsoDateAndTimeIntervalMs = function(d, ti)
{
var d0 = new Date(d);
var t0 = d0.getTime() + ti;
d0.setTime(t0);
return d0.toISOString();
};
var _GetTimeSliceLayerDateRangeForIdxUTC = function(idx)
{
var ds = SafecastDateHelper.GetTimeSliceLayerDateRangesUTC();
var d = null;
for (var i=0; i<ds.length; i++)
{
if (ds[i].i == idx)
{
d = ds[i];
break;
}//if
}//for
if (d == null)
{
d = { i:0, s:"1970-01-01T00:00:00Z", e:"1970-01-01T00:00:00Z" };
}//if
return d;
};
// By default the dates are exclusive of the end date as noted.
// This subtracts one second from the end dates to make them work with
// a BETWEEN query.
SafecastDateHelper.GetTimeSliceLayerDateRangeInclusiveForIdxUTC = function(idx)
{
var d = _GetTimeSliceLayerDateRangeForIdxUTC(idx);
d.e = _GetIsoDateForIsoDateAndTimeIntervalMs(d.e, -1000.0);
return d;
};
// Converts { s:"2011-03-10T15:00:00Z", e:"2011-09-10T15:00:00Z" }
// to "2011031020110910" for consistent filename references.
SafecastDateHelper.GetTimeSliceDateRangesFilenames = function()
{
var src = SafecastDateHelper.GetTimeSliceLayerDateRangesUTC();
var dest = new Array();
for (var i=0; i<src.length; i++)
{
var d0 = _TrimIsoDateToFilenamePart(src[i].s);
var d1 = _TrimIsoDateToFilenamePart(src[i].e);
dest.push( { i:src[i].i, d:(d0 + d1) } );
}//for
return dest;
};
// Converts ISO date string into JST-offset date with the end date
// having 1 second subtracted, then truncates them into "YYYY-MM-DD"
SafecastDateHelper.GetTimeSliceDateRangeLabelsForIdxJST = function(idx)
{
var d = SafecastDateHelper.GetTimeSliceLayerDateRangeInclusiveForIdxUTC(idx);
d.s = _GetIsoDateForIsoDateAndTimeIntervalMs(d.s, _JST_OFFSET_MS);
d.e = _GetIsoDateForIsoDateAndTimeIntervalMs(d.e, _JST_OFFSET_MS);
d.s = _GetShortIsoDate(d.s);
d.e = _GetShortIsoDate(d.e);
return d;
};
return SafecastDateHelper;
})();
// ===============================================================================================
// ===================================== CLIENT ZOOM HELPER ======================================
// ===============================================================================================
//
// ClientZoomHelper: The actual interface to return raster layer tile URLs to Google Maps, this
// also does some tricks to scale layers on the client past their maximum zoom
// level.
//
// The Google Maps API accepts tiles of any size. To facilitate client zoom, the following is done:
//
// 1. Is the zoom level past the layer's max?
// 2. If no: function normally.
// 3. If yes:
// 1. Remove the layer from the map.
// 2. Change the tile size to: NORMAL_SIZE << (CURRENT_ZOOM_LEVEL - LAYER_MAX_ZOOM_LEVEL)
// 3. Add the layer back to the map.
// 4. When constructing the URL for a tile added in this manner, make sure to set the zoom level
// to the layer's max.
//
// Example: Normally, this is how things work for a Web Mercator tile system:
//
// World Width or Height
// Zoom Level | Tiles | Pixels | Tile Size, px |
// -----------|-----------|-----------|---------------|
// 0 | 1 | 256 | 256 |
// 1 | 2 | 512 | 256 |
// 2 | 4 | 1024 | 256 |
// 3 | 8 | 2048 | 256 |
// 4 | 16 | 4096 | 256 |
// ... etc ...
//
// So, for a tile set with a maximum zoom level of 2, the following could be reported to Google Maps:
//
// World Width or Height
// Zoom Level | Tiles | Pixels | Tile Size, px |
// -----------|-----------|-----------|---------------|
// 0 | 1 | 256 | 256 |
// 1 | 2 | 512 | 256 |
// (MAX) 2 | 4 | 1024 | 256 |
// 3 | 4 | 2048 | 512 |
// 4 | 4 | 4096 | 1024 |
//
// In the Google Maps API, all tiles are HTML <img> elements wrapped in <divs>. So regardless of
// the tile's actual size, it is scaled by the browser to the indicated size.
//
// This is of course, quite lucrative. The native resolution for Safecast tiles is zoom level 13.
// Everything at a higher zoom level is an interpolation of that.
//
// Potentially, it is a tremendous logistical advantage to scale tiles on the client past zoom
// level 13 rather than the server. However, in practice it is somewhat more problematic; the
// scaling of the final RGBA output image is inferior for a number of reasons, and worse still,
// can cause crashing on relatively common iOS devices with 1GB of RAM.
//
// Thus, as partial workarounds, some scaling is still performed by the server, and CSS styles to
// force nearest neighbor scaling for the tiles on the client are used.
//
// Things that could be done to improve this in the future:
// 1. Eventually, drop support for 1GB RAM devices.
// 2. Do not discretize the LUT on the server; use full-color RGBA tiles. Smooth RGB contours
// scale better with bilinear/bicubic than a limited color palette.
// 3. For "points"-style tiles, do not render the shadow effect on the server. Instead, use
// CSS styles. Unfortunately, this is problematic; it requires a top-tier GPU (as of 2016)
// to not be janky, and uses a lot of additional energy to do so. Further, recent changes to
// Gmaps squash all layers for a tile x/y/z within a single <div>, meaning a CSS solution
// now produces lots of artifacts.
// 4. Instead of PNGs, load the raw floating point data from the server as the native apps do,
// and render the tile locally. Unfortunately, the last time this was attempted, it was
// quite slow.
//
var ClientZoomHelper = (function()
{
function ClientZoomHelper()
{
}
var _fxGetNormalizedCoord = function(xy, z) { return SafemapUtil.GetNormalizedCoord(xy, z); }; // static
var _fxShouldLoadTile = function(l,x,y,z) { return _bitsProxy.ShouldLoadTile(l, x, y, z); };
var _fxGetIsRetina = function() { return SafemapUI.GetIsRetina(); };
var _fxGetSelectedLayerIdx = function() { return LayersHelper.GetSelectedIdx(); };
var _fxClearMapLayers = function() { map.overlayMapTypes.clear(); };
var _fxSyncMapLayers = function() { LayersHelper.SyncSelectedWithMap(); };
var _fxGetLayers = function() { return overlayMaps; };