-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathindex.php
1683 lines (1535 loc) · 82.8 KB
/
index.php
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
<?php
include("classes/Translation.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>OpenSeaMap - <?php echo $t->tr("dieFreieSeekarte")?></title>
<meta name="AUTHOR" content="Olaf Hannemann"/>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta http-equiv="content-language" content="<?= $t->getCurrentLanguage()?>"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no, user-scalable=no" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<meta name="date" content="2012-06-02">
<link rel="SHORTCUT ICON" href="resources/icons/OpenSeaMapLogo_16.png">
<link rel="stylesheet" href="./javascript/[email protected]/ol.css">
<link rel="stylesheet" type="text/css" href="index.css">
<script src="./javascript/[email protected]/ol.js"></script>
<script type="text/javascript" src="./javascript/translation-<?=$t->getCurrentLanguageSafe()?>.js"></script>
<script type="text/javascript" src="./javascript/permalink.js"></script>
<script type="text/javascript" src="./javascript/utilities.js"></script>
<script type="text/javascript" src="./javascript/countries.js"></script>
<script type="text/javascript" src="./javascript/map_utils.js"></script>
<script type="text/javascript" src="./javascript/harbours.js"></script>
<script type="text/javascript" src="./javascript/nominatim.js"></script>
<script type="text/javascript" src="./javascript/tidal_scale.js"></script>
<script type="text/javascript" src="./javascript/NauticalRoute.js"></script>
<script type="text/javascript" src="./javascript/geomagjs/cof2Obj.js"></script>
<script type="text/javascript" src="./javascript/geomagjs/geomag.js"></script>
<script type="text/javascript" src="./javascript/mag_deviation.js"></script>
<script type="text/javascript">
<?php
$tempval = parse_ini_file("/var/lib/online-chart/online_chart.ini");
$osm_server = $tempval['osmserver'];
echo "var OsmTileServer = ", "\"", $osm_server, "\""
?>
var map;
// popup
var popup;
var content;
var closer;
var overlay;
// Position and zoomlevel of the map (will be overriden with permalink parameters or cookies)
var lon = 11.6540;
var lat = 54.1530;
var zoom = 10;
//last zoomlevel of the map
var oldZoom = 0;
var downloadName;
var downloadLink;
var wikipediaThumbs = false;
// FIXME: Work around for accessing translations from harbour.js
var linkTextSkipperGuide = "<?=$t->tr('descrSkipperGuide')?>";
var linkTextWeatherHarbour = "<?=$t->tr('descrOpenPortGuide')?>";
// FIXME: Work around for accessing translations from tidal_scale.js
var linkTextHydrographCurve = "<?=$t->tr('hydrographCurve')?>";
var linkTextMeasuringValue = "<?=$t->tr('measuringValue')?>";
var linkTextTendency = "<?=$t->tr('tendency')?>";
// FIXME: Work around for accessing translations from NauticalRoute.js
var tableTextNauticalRouteCoordinate = "<?=$t->tr('coordinate')?>";
var tableTextNauticalRouteCourse = "<?=$t->tr('course')?>";
var tableTextNauticalRouteDistance = "<?=$t->tr('distance')?>";
// Set language
var language = "<?=$t->getCurrentLanguage()?>";
// Layers
var layer_mapnik; // 1
var layer_marker; // 2
var layer_seamark; // 3
var layer_sport; // 4
// var layer_gebco_deepshade; // 5
var layer_gebco_deeps_gwc; // 6
var layer_harbours; // 7
var layer_download; // 8
var layer_nautical_route; // 9
var layer_grid; // 10
var layer_wikipedia; // 11
var layer_bing_aerial; // 12
var layer_ais; // 13
var layer_satpro; // 14
// var layer_disaster // 15
var layer_tidalscale; // 16
var layer_permalink; // 17
var layer_waterdepth_trackpoints_100m; // 18
// elevation layers are not available
// see layer's definiton in old commit:
// https://github.com/OpenSeaMap/online_chart/commit/32378f1c8655593e2e6701cd4ba2eb8fd10352b1
// var layer_elevation_profile_contours; // 19
// var layer_elevation_profile_hillshade; //20
var layer_waterdepth_trackpoints_10m; // 21
var layer_waterdepth_contours; // 22
// To not change the permalink layer order, every removed
// layer keeps its number. The ArgParser compares the
// count of layers with the layers argument length. So we
// have to let him know, how many layers are removed.
var ignoredLayers = 4;
// Marker that is pinned at the last location the user searched for and selected.
var searchedLocationMarker = null;
// Load map for the first time
function init() {
initMap();
readPermalinkOrCookies();
initLayerCheckboxes();
initMenuTools();
}
// Apply the url parameters or cookies or default values
function readPermalinkOrCookies() {
// Read zoom, lat, lon
var cookieZoom = parseFloat(getCookie("zoom"));
var cookieLat = parseFloat(getCookie("lat"));
var cookieLon = parseFloat(getCookie("lon"));
var permalinkLat = parseFloat(getArgument("lat"));
var permalinkLon = parseFloat(getArgument("lon"));
var permalinkZoom = parseFloat(getArgument("zoom"));
var markerLat = parseFloat(getArgument("mlat"));
var markerLon = parseFloat(getArgument("mlon"));
zoom = permalinkZoom || cookieZoom || zoom;
lat = markerLat || permalinkLat || cookieLat || lat;
lon = markerLon || permalinkLon || cookieLon || lon;
// Zoom to coordinates from marker/permalink/cookie or default values.
jumpTo(lon, lat, zoom);
// Add marker from permalink
if (markerLat && markerLon) {
try{
var mtext = decodeURIComponent(getArgument("mtext"))
.replace(/\n/g, '<br/>').replace('<b>', '<b>')
.replace('<%2Fb>', '</b>')
.replace('</b>', '</b>');
const feature = addMarker(layer_marker, markerLon, markerLat, mtext);
openPopup(feature);
} catch(err) {
console.log(err)
}
}
// Apply layers visiblity from permalink
const permalinkLayers = getArgument("layers");
if (permalinkLayers) {
const layers = map.getLayers().getArray();
[...permalinkLayers].forEach((visibility, index) => {
const layer = layers.find((l) => {
return l.get('layerId') === index + 1;
});
if (layer) {
layer.setVisible(/^(B|T)$/.test(visibility));
}
});
} else {
map.getLayers().forEach((layer)=> {
const cookieKey = layer.get('cookieKey');
const cookieValue = getCookie(cookieKey);
if (cookieKey && cookieValue) {
layer.setVisible((cookieValue === 'true'));
}
});
}
if (layer_wikipedia && getCookie("WikipediaLayerThumbs") === "true") {
wikipediaThumbs = true;
layer_wikipedia?.setVisible(true);
}
const compass = document.getElementById("checkCompassrose");
if (compass && getCookie("CompassroseVisible") === "true") {
compass.checked = true
toggleCompassrose();
}
}
// Initialize the layers checkboxes on page load
function initLayerCheckboxes()
{
map.getLayers().forEach((layer)=> {
const checkboxId = layer.get('checkboxId');
const checkbox = document.getElementById(checkboxId);
if (checkbox) {
checkbox.checked = layer.getVisible();
}
})
document.getElementById("checkCompassrose").checked = (document.getElementById("compassRose").style.visibility === 'visible');
}
function refreshWeatherAppLink() {
const view = map.getView();
const zoom = view.getZoom();
const [lon, lat] = ol.proj.toLonLat(view.getCenter());
const link = document.getElementById('weatherAppLink');
link.href = "weather.php?zoom=" + zoom.toFixed(2) + "&lon=" + lon.toFixed(5) + "&lat=" + lat.toFixed(5);
}
// Show popup window for help
function showMapKey(item) {
legendWindow = window.open("legend.php?lang=" + language + "&page=" + item, "MapKey", "width=760, height=680, status=no, scrollbars=yes, resizable=yes");
legendWindow.focus();
}
function toggleCompassrose() {
if (document.getElementById("checkCompassrose").checked) {
refreshMagdev();
document.getElementById("compassRose").style.visibility = 'visible';
setCookie("CompassroseVisible", "true");
} else {
document.getElementById("compassRose").style.visibility = 'hidden';
setCookie("CompassroseVisible", "false");
}
}
function toggleLayer(layer) {
layer.setVisible(!layer.getVisible());
}
function toggleNauticalRoute(show) {
if (show) {
addNauticalRoute();
} else {
closeNauticalRoute();
}
}
function togglePermalink(show) {
if (show) {
openPermalinkDialog();
} else {
closePermalinkDialog();
}
}
function toggleMapDownload(show) {
if (show) {
openMapDownloadDialog();
} else {
closeMapDownloadDialog();
}
}
function showBingAerial() {
if (layer_bing_aerial.getVisible()) {
layer_bing_aerial.setVisible(false);
layer_mapnik.setVisible(true);
} else {
layer_mapnik.setVisible(false);
layer_bing_aerial.setVisible(true);
}
}
function toggleWaterDepthTrackPoints(checked) {
if(!checked){
layer_waterdepth_trackpoints_10m.setVisible(false);
layer_waterdepth_trackpoints_100m.setVisible(false);
} else if (
!layer_waterdepth_trackpoints_10m.getVisible() &&
!layer_waterdepth_trackpoints_100m.getVisible()
) {
layer_waterdepth_trackpoints_10m.setVisible(true);
}
}
// Show Wikipedia layer with thumbnails or not.
function toggleWikipediaThumbnails(visible) {
if (visible && !layer_wikipedia.getVisible()) {
layer_wikipedia.setVisible(true);
}
wikipediaThumbs = visible;
layer_wikipedia.getSource().refresh();
}
// Show dialog window
function showActionDialog(htmlText) {
document.getElementById("actionDialog").style.visibility = 'visible';
document.getElementById("actionDialog").innerHTML=""+ htmlText +"";
}
// Hide dialog window
function closeActionDialog() {
document.getElementById("actionDialog").style.visibility = 'hidden';
}
function openMapDownloadDialog() {
selectControl.hover = false;
addDownloadlayer();
layer_download.setVisible(true);
var htmlText = "<div style=\"position:absolute; top:5px; right:5px; cursor:pointer;\"><img src=\"./resources/action/close.gif\" onClick=\"closeMapDownloadDialog();\"/></div>";
htmlText += "<h3><?=$t->tr("downloadChart")?>:</h3><br/>";
htmlText += "<table border=\"0\" width=\"240px\">";
htmlText += "<tr><td>Name:</td><td><div id=\"info_dialog\"><?=$t->tr("pleaseSelect")?><br/></div></td></tr>";
htmlText += "<tr><td><?=$t->tr("format")?>:</td><td><select id=\"mapFormat\"><option value=\"unknown\"/><?=$t->tr("unknown")?><option value=\"png\"/>png<option value=\"cal\"/>cal<option value=\"kap\"/>kap<option value=\"WCI\"/>WCI<option value=\"kmz\"/>kmz<option value=\"jpr\"/>jpr</select></td></tr>";
htmlText += "<tr><td><br/><input type=\"button\" id=\"buttonMapDownload\" value=\"<?=$t->tr("download")?>\" onclick=\"downloadMap()\" disabled=\"true\"></td><td align=\"right\"><br/><input type=\"button\" id=\"buttonMapClose\" value=\"<?=$t->tr("close")?>\" onclick=\"closeMapDownloadDialog()\"></td></tr>";
htmlText += "</table>";
showActionDialog(htmlText);
}
function closeMapDownloadDialog() {
selectControl.hover = true;
layer_download.setVisible(false);
layer_download.getSource().clear();
closeActionDialog();
}
function downloadMap() {
var format = document.getElementById("mapFormat").value;
if (format == "unknown") {
alert("Bitte wählen sie ein Format.");
return;
} else if (format == "cal") {
format = "_png." + format
} else {
format = "." + format
}
var url = "https://sourceforge.net/projects/opennautical/files/Maps" + downloadLink + "ONC-" + downloadName + format + "/download";
downloadWindow = window.open(url);
}
function selectedMap(event) {
var feature = event.feature;
downloadName = feature.get('name');
downloadLink = feature.get('link');
var mapName = downloadName;
document.getElementById('info_dialog').innerHTML=""+ mapName +"";
document.getElementById('buttonMapDownload').disabled=false;
}
function addNauticalRoute() {
layer_nautical_route.setVisible(true);
var htmlText = "<div style=\"position:absolute; top:5px; right:5px; cursor:pointer;\">";
htmlText += "<img src=\"./resources/action/delete.png\" width=\"17\" height=\"17\" onclick=\"if (!routeChanged || confirm('<?=$t->tr("confirmDeleteRoute")?>')) {closeNauticalRoute();addNauticalRoute();}\"/>";
htmlText += "<img src=\"./resources/action/info.png\" width=\"17\" height=\"17\" onClick=\"showMapKey('help-trip-planner');\"/>";
htmlText += "<img src=\"./resources/action/close.gif\" onClick=\"if (!routeChanged || confirm('<?=$t->tr("confirmCloseRoute")?>')) {closeNauticalRoute();}\"/></div>";
htmlText += "<h3><?=$t->tr("tripPlanner")?>: <input type=\"text\" id=\"tripName\" size=\"20\"></h3><br/>";
htmlText += "<table border=\"0\" width=\"370px\">";
htmlText += "<tr><td><?=$t->tr("start")?></td><td id=\"routeStart\">- - -</td></tr>";
htmlText += "<tr><td><?=$t->tr("finish")?></td><td id=\"routeEnd\">- - -</td></tr>";
htmlText += "<tr><td><?=$t->tr("distance")?></td><td id=\"routeDistance\">- - -</td></tr>";
htmlText += "<tr><td id=\"routePoints\" colspan = 2> </td></tr>";
htmlText += "</table>";
htmlText += "<input type=\"button\" id=\"buttonRouteDownloadTrack\" value=\"<?=$t->tr("download")?>\" onclick=\"NauticalRoute_DownloadTrack();\" disabled=\"true\">";
htmlText += "<select id=\"routeFormat\"><option value=\"CSV\"/>CSV<option value=\"GML\"/>GML<option value=\"KML\"/>KML<option value=\"GPX\"/>GPX</select>";
htmlText += "<select id=\"coordFormat\" onchange=\"NauticalRoute_getPoints(routeTrack);\"><option value=\"coordFormatdms\"/>ggg°mm.mmm'<option value=\"coordFormatd_dec\"/>ggg.gggggg</select>";
htmlText += "<select id=\"distUnits\" onchange=\"NauticalRoute_getPoints(routeTrack);\"><option value=\"nm\"/>[nm]<option value=\"km\"/>[km]</select>";
showActionDialog(htmlText);
NauticalRoute_startEditMode();
}
function closeNauticalRoute() {
layer_nautical_route.setVisible(false);
closeActionDialog();
NauticalRoute_stopEditMode();
}
function addPermalinkMarker(coordinate) {
layer_permalink.getSource().clear(); // clear all markers to only keep one marker at a time on the map
const feature = new ol.Feature(new ol.geom.Point(coordinate));
layer_permalink.getSource().addFeature(feature);
const [lon, lat] = ol.proj.toLonLat(coordinate);
// Code from mousepostion_dm.js - redundant, try to reuse
var ns = lat >= 0 ? 'N' : 'S';
var we = lon >= 0 ? 'E' : 'W';
var lon_m = Math.abs(lon*60).toFixed(3);
var lat_m = Math.abs(lat*60).toFixed(3);
var lon_d = Math.floor(lon_m/60);
var lat_d = Math.floor(lat_m/60);
lon_m -= lon_d*60;
lat_m -= lat_d*60;
// Write the specified content inside
const markerpos = document.getElementById('markerpos');
markerpos.innerHTML = ns + lat_d + "°" + format2FixedLenght(lat_m,6,3) + "'" + " " + we + lon_d + "°" + format2FixedLenght(lon_m,6,3) + "'";
markerpos.lat = lat.toFixed(5);
markerpos.lon = lon.toFixed(5);
updatePermaLinkInDialog();
}
function updatePermaLinkInDialog(){
if(!layer_permalink.getVisible() || !document.getElementById("permalinkDialog")) {
return;
}
const params = {};
const markerpos = document.getElementById('markerpos');
var lat = markerpos.lat;
if(lat)
params.mlat = lat; // add latitude
var lon = markerpos.lon;
if(lon) {
params.mlon = lon; // add longitude
}
var mText = document.getElementById("markerText").value;
if(mText != "") {
params.mtext = mText; // add marker text; if empty OSM-permalink JS will ignore the '&mtext'
}
document.getElementById("userURL").innerHTML = getPermalink(params); // write contents of userURL to textarea
}
function openPermalinkDialog() {
layer_permalink.setVisible(true);
document.getElementById('checkPermalink').checked = true;
var htmlText = "<div id='permalinkDialog' style=\"position:absolute; top:5px; right:5px; cursor:pointer;\">";
htmlText += "<img src=\"./resources/action/close.gif\" onClick=\"closePermalinkDialog();\"/></div>";
htmlText += "<h3><?=$t->tr("permalinks")?>:</h3><br/>"; // reference to translation.php
htmlText += "<p><?=$t->tr("markset")?></p>"
htmlText += "<br /><hr /><br />"
// Übersetzungen in die PHP-Files reinschreiben; kein Text sollte ohne die Möglichkeit der Bearbeitung hier drin stehen
htmlText += "<table border=\"0\" width=\"370px\">";
htmlText += "<tr><td><?=$t->tr("position")?>:</td><td id=\"markerpos\">- - -</td></tr>"; // Lat/Lon of the user's click
htmlText += "<tr><td><?=$t->tr("description")?>:</td><td><textarea cols=\"25\" rows=\"5\" id=\"markerText\"></textarea></td></tr>"; // userInput
htmlText += "</td></tr></table>";
htmlText += "<br /><hr /><br />"
htmlText += "<?=$t->tr("copynpaste")?>:<br /><textarea onclick=\"this.select();\" cols=\"50\" rows=\"3\" id=\"userURL\"></textarea>"; // secure & convient onlick-solution for copy and paste
showActionDialog(htmlText);
document.getElementById('markerText').addEventListener("keyup",function(evt) {
updatePermaLinkInDialog()
});
updatePermaLinkInDialog();
}
function closePermalinkDialog() {
layer_permalink.setVisible(false);
document.getElementById('checkPermalink').checked = false;
closeActionDialog();
}
function addSearchResults(xmlHttp) {
var items = xmlHttp.responseXML.getElementsByTagName("place");
var placeName, description, placeLat, placeLon;
var buff, pos;
var htmlText = "<div style=\"position:absolute; top:5px; right:5px; cursor:pointer;\"><img src=\"./resources/action/close.gif\" onClick=\"closeActionDialog();\"/></div>";
htmlText += "<h3><?=$t->tr("searchResults")?>:</h3><br/>"
htmlText += "<table border=\"0\" width=\"370px\">"
for(i = 0; i < items.length; i++) {
buff = xmlHttp.responseXML.getElementsByTagName('place')[i].getAttribute('display_name');
placeLat = xmlHttp.responseXML.getElementsByTagName('place')[i].getAttribute('lat');
placeLon = xmlHttp.responseXML.getElementsByTagName('place')[i].getAttribute('lon');
pos = buff.indexOf(",");
placeName = buff.substring(0, pos);
description = buff.substring(pos +1).trim();
htmlText += "<tr style=\"cursor:pointer;\" onmouseover=\"this.style.backgroundColor = '#ADD8E6';\"onmouseout=\"this.style.backgroundColor = '#FFF';\" onclick=\"jumpToSearchedLocation(" + placeLon + ", " + placeLat + ");\"><td valign=\"top\"><b>" + placeName + "</b></td><td>" + description + "</td></tr>";
}
htmlText += "<tr><td></td><td align=\"right\"><br/><input type=\"button\" id=\"buttonMapClose\" value=\"<?=$t->tr("close")?>\" onclick=\"closeActionDialog();\"></td></tr></table>";
showActionDialog(htmlText);
}
function initMap() {
popup = document.getElementById('popup');
content = document.getElementById('popup-content');
closer = document.getElementById('popup-closer');
overlay = new ol.Overlay({
element: popup,
autoPan: {
animation: {
duration: 250,
},
},
});
// close the popup
closer.onclick = function () {
overlay.setPosition(undefined);
closer.blur();
return false;
};
map = new ol.Map({
target: 'map',
overlays: [overlay],
view: new ol.View({
maxZoom : 19,
// displayProjection : proj4326,
// eventListeners: {
// moveend : mapEventMove,
// zoomend : mapEventZoom,
// click : mapEventClick,
// changelayer : mapChangeLayer
// },
// controls: [
// permalinkControl,
// new OpenLayers.Control.Navigation(),
// //new OpenLayers.Control.LayerSwitcher(), //only for debugging
// new OpenLayers.Control.ScaleLine({
// topOutUnits : "nmi",
// bottomOutUnits: "km",
// topInUnits: 'nmi',
// bottomInUnits: 'km',
// maxWidth: Math.max(0.2*$(window).width(),0.2*$(window).height()).toFixed(0),
// geodesic: true
// }),
// new OpenLayers.Control.MousePositionDM(),
// new OpenLayers.Control.OverviewMap(),
// ZoomBar
// ]
}),
});
map.addControl(new Permalink());
map.addControl(new ol.control.ScaleLine({
className: 'ol-scale-line-metric'
}));
map.addControl(new ol.control.ScaleLine({
className: 'ol-scale-line-nautical',
units: "nautical",
}));
map.addControl(new ol.control.ZoomSlider());
map.addControl(new ol.control.MousePosition({
coordinateFormat: (coordinate) => {
const [lon, lat] = ol.proj.toLonLat(coordinate);
var ns = lat >= 0 ? 'N' : 'S';
var we = lon >= 0 ? 'E' : 'W';
var lon_m = Math.abs(lon*60).toFixed(3);
var lat_m = Math.abs(lat*60).toFixed(3);
var lon_d = Math.floor (lon_m/60);
var lat_d = Math.floor (lat_m/60);
lon_m -= lon_d*60;
lat_m -= lat_d*60;
return "Zoom:" + map.getView().getZoom().toFixed(0) + " " + ns + lat_d + "°" + format2FixedLenght(lat_m,6,3) + "'" + " " +
we + lon_d + "°" + format2FixedLenght(lon_m,6,3) + "'" ;
},
}));
map.on('moveend', mapEventMove);
map.on('moveend', mapEventZoom);
map.on('pointermove', mapEventPointerMove);
map.on('singleclick', mapEventClick);
selectControl = new ol.interaction.Select();
function updateCheckboxAndCookie(layer) {
const checkboxId = layer.get("checkboxId");
const cookieKey = layer.get("cookieKey");
const checkbox = document.getElementById(checkboxId);
if (checkbox) {
checkbox.checked = layer.getVisible();
}
if (cookieKey) {
setCookie(cookieKey, layer.getVisible());
}
}
// Use a 512*5212 tile grid for some layers
const projExtent = ol.proj.get('EPSG:3857').getExtent();
const startResolution = ol.extent.getWidth(projExtent) / 256;
const resolutions = new Array(22);
for (let i = 0, ii = resolutions.length; i < ii; ++i) {
resolutions[i] = startResolution / Math.pow(2, i);
}
const tileGrid512 = new ol.tilegrid.TileGrid({
extent: projExtent,
resolutions: resolutions,
tileSize: [512, 512],
});
// Add Layers to map-------------------------------------------------------------------------------------------------------
// Mapnik (Base map)
// old definition
// layer_mapnik = new OpenLayers.Layer.XYZ('Mapnik',
// GetOsmServer(),
// { layerId : 1,
// wrapDateLine : true
// });
const osmUrl =
OsmTileServer === "BRAVO" ?
'https://t2.openseamap.org/tile/{z}/{x}/{y}.png' :
'https://tile.openstreetmap.org/{z}/{x}/{y}.png';
layer_mapnik = new ol.layer.Tile({
source: new ol.source.OSM({
url: osmUrl,
crossOrigin: null,
}),
properties: {
name: 'Mapnik',
layerId: 1,
wrapDateLine:true
}
});
// Seamark
// old definition
// layer_seamark = new OpenLayers.Layer.TMS("seamarks",
// "https://tiles.openseamap.org/seamark/",
// { layerId: 3, numZoomLevels: 19, type: 'png', getURL:getTileURL, isBaseLayer:false, displayOutsideMaxExtent:true});
layer_seamark = new ol.layer.Tile({
visible: true,
maxZom: 19,
source: new ol.source.XYZ({
// url: "https://tiles.openseamap.org/seamark/{z}/{x}/{y}.png"
tileUrlFunction: function(coordinate) {
return getTileUrlFunction("https://tiles.openseamap.org/seamark/", 'png', coordinate);
// return "https://tiles.openseamap.org/seamark/" + coordinate[0] + '/' +
// coordinate[1] + '/' + (-coordinate[2] - 1) + '.png';
}
}),
properties: {
name: "seamarks",
layerId: 3,
cookieKey: "SeamarkLayerVisible",
checkboxId: "checkLayerSeamark",
}
});
layer_seamark.on("change:visible", (evt) => {
updateCheckboxAndCookie(evt.target);
});
// Sport
// old definition
// layer_sport = new OpenLayers.Layer.TMS("Sport", "https://tiles.openseamap.org/sport/",
// { layerId: 4, numZoomLevels: 19, type: 'png', getURL:getTileURL, isBaseLayer:false, visibility: false, displayOutsideMaxExtent:true});
layer_sport = new ol.layer.Tile({
visible: false,
maxZom: 19,
properties: {
name: 'Sport',
layerId: 4,
checkboxId: "checkLayerSport",
cookieKey: "SportLayerVisible",
},
source: new ol.source.XYZ({
url: "https://tiles.openseamap.org/sport/{z}/{x}/{y}.png",
tileUrlFunction: function(coordinate) {
return getTileUrlFunction("https://tiles.openseamap.org/sport/", 'png', coordinate);
// return "https://tiles.openseamap.org/seamark/" + coordinate[0] + '/' +
// coordinate[1] + '/' + (-coordinate[2] - 1) + '.png';
}
}),
});
layer_sport.on("change:visible", (evt) => {
updateCheckboxAndCookie(evt.target);
});
//GebcoDepth
// old definition
// layer_gebco_deeps_gwc = new OpenLayers.Layer.WMS("gebco_2021", "https://geoserver.openseamap.org/geoserver/gwc/service/wms",
// {layers: "gebco2021:gebco_2021", format:"image/png"},
// { layerId: 6, isBaseLayer: false, visibility: false, opacity: 0.8});
layer_gebco_deeps_gwc = new ol.layer.Tile({
visible: false,
opacity: 0.8,
properties: {
name:"gebco_2021",
layerId: 6,
isBaseLayer: false,
checkboxId: "checkLayerGebcoDepth",
cookieKey: "GebcoDepthLayerVisible",
},
source: new ol.source.TileWMS({
url: 'https://geoserver.openseamap.org/geoserver/gwc/service/wms',
params: {'LAYERS': 'gebco2021:gebco_2021', 'VERSION':'1.1.1'},
ratio: 1,
serverType: 'geoserver',
hidpi: false,
}),
}),
layer_gebco_deeps_gwc.on("change:visible", (evt) => {
updateCheckboxAndCookie(evt.target);
});
// POI-Layer for harbours
// old definition
// layer_harbours = new OpenLayers.Layer.Vector("pois", {
// layerId: 7,
// visibility: true,
// projection: proj4326,
// displayOutsideMaxExtent:true
// });
layer_harbours = new ol.layer.Vector({
visible: true,
properties: {
name: "pois",
layerId: 7,
checkboxId: "checkLayerHarbour",
cookieKey: "HarbourLayerVisible",
},
style: harbourStyleFunction,
source: new ol.source.Vector({
strategy: ol.loadingstrategy.bbox,
loader: harbourSourceLoader,
}),
});
layer_harbours.on("change:visible", (evt) => {
updateCheckboxAndCookie(evt.target);
});
// Bing
// old definition
// layer_bing_aerial = new Bing({
// layerId: 12,
// name: 'Aerial photo',
// key: 'AuA1b41REXrEohfokJjbHgCSp1EmwTcW8PEx_miJUvZERC0kbRnpotPTzGsPjGqa',
// type: 'Aerial',
// isBaseLayer: true,
// displayOutsideMaxExtent: true,
// wrapDateLine: true
// });
layer_bing_aerial = new ol.layer.Tile({
visible: false,
preload: Infinity,
properties: {
name: 'Aerial photo',
layerId: 12,
isBaseLayer: true,
checkboxId: "checkLayerBingAerial",
cookieKey: "BingAerialLayerVisible",
},
source: new ol.source.BingMaps({
key: 'AuA1b41REXrEohfokJjbHgCSp1EmwTcW8PEx_miJUvZERC0kbRnpotPTzGsPjGqa',
imagerySet: 'Aerial',
// use maxZoom 19 to see stretched tiles instead of the BingMaps
// "no photos at this zoom level" tiles
maxZoom: 19
}),
});
layer_bing_aerial.on('change:visible', (evt) => {
document.getElementById("license_bing").style.display = layer_bing_aerial.getVisible() ? 'inline' : 'none';
updateCheckboxAndCookie(evt.target);
});
// Map download
// old definition
// layer_download = new OpenLayers.Layer.Vector("Map Download", {
// layerId: 8,
// visibility: false
// });
layer_download = new ol.layer.Vector({
visible: false,
properties: {
name: 'Map Download',
layerId: 8,
},
source: new ol.source.Vector({features:[]}),
});
// Trip planner
// old definition
// layer_nautical_route = new OpenLayers.Layer.Vector("Trip Planner",
// { layerId: 9, styleMap: routeStyle, visibility: false, eventListeners: {"featuresadded": NauticalRoute_routeAdded, "featuremodified": NauticalRoute_routeModified}});
layer_nautical_route = new ol.layer.Vector({
visible: false,
properties: {
name: 'Trip Planner',
layerId: 9,
checkboxId: "checkNauticalRoute",
cookieKey: "NauticalRouteLayerVisible",
},
source: new ol.source.Vector({features:[]}),
});
layer_nautical_route.on("change:visible", (evt) => {
updateCheckboxAndCookie(evt.target);
});
// Grid WGS
// old definition
// layer_grid = new OpenLayers.Layer.GridWGS("coordinateGrid", {
// layerId: 10,
// visibility: true,
// zoomUnits: zoomUnits
// });
layer_grid = new ol.layer.Graticule({
visible: true,
properties: {
name: "coordinateGrid",
layerId: 10,
checkboxId: "checkLayerGridWGS",
cookieKey: "GridWGSLayerVisible",
},
// the style to use for the lines, optional.
strokeStyle: new ol.style.Stroke({
color: 'rgba(0,0,0,1)',
width: 1,
// lineDash: [0.5, 4],
}),
showLabels: true,
wrapX: true,
});
layer_grid.on("change:visible", (evt) => {
updateCheckboxAndCookie(evt.target);
});
// old definition
// var poiLayerWikipediaHttp = new OpenLayers.Protocol.HTTP({
// url: 'api/proxy-wikipedia.php?',
// params: {
// 'LANG' : language,
// 'thumbs' : 'no'
// },
// format: new OpenLayers.Format.KML({
// extractStyles: true,
// extractAttributes: true
// })
// });
// layer_wikipedia = new OpenLayers.Layer.Vector("Wikipedia World", {
// layerId: 11,
// visibility: false,
// projection: proj4326,
// strategies: [bboxStrategyWikipedia],
// protocol: poiLayerWikipediaHttp
// });
layer_wikipedia = new ol.layer.Vector({
visible: false,
properties: {
name: "Wikipedia World",
layerId: 11,
checkboxId: "checkLayerWikipedia",
cookieKey: "WikipediaLayerVisible",
},
source: new ol.source.Vector({
features: [],
strategy: ol.loadingstrategy.bbox,
format: new ol.format.KML({
extractStyles: true,
}),
loader: function(extent, resolution, projection, success, failure) {
document.getElementById("checkLayerWikipediaThumbnails").checked = wikipediaThumbs;
setCookie("WikipediaLayerThumbs", wikipediaThumbs);
const proj = projection.getCode();
const bbox = ol.proj.transformExtent(extent, map.getView().getProjection(), 'EPSG:4326');
// Beforee it used the api/prox-wikipedia.php but i seems to work without the proxy
const url = 'https://wp-world.toolforge.org/marks.php?' + 'LANG=' + language + '&thumbs=' + (wikipediaThumbs ? 'yes' : 'no') +'&bbox=' + bbox.join(',');
const xhr = new XMLHttpRequest();
xhr.open('GET', url);
const vectorSource = this;
const onError = function() {
vectorSource.removeLoadedExtent(extent);
failure();
};
xhr.onerror = onError;
xhr.onload = function() {
if (xhr.status == 200) {
const features = vectorSource.getFormat().readFeatures(xhr.responseText, {featureProjection: "EPSG:3857"});
// Dont' display poi name.
features.forEach((feature) => {
const style = feature.getStyle()(feature);
style.getText().setText(null);
feature.setStyle(style);
});
vectorSource.addFeatures(features);
success(features);
} else {
onError();
}
}
xhr.send();
},
}),
});
layer_wikipedia.on("change:visible", (evt) => {
updateCheckboxAndCookie(evt.target);
if (!evt.target.getVisible()) {
document.getElementById("checkLayerWikipediaThumbnails").checked = false;
setCookie("WikipediaLayerThumbs", false);
selectControl?.getFeatures().clear();
layer_wikipedia.getSource().refresh();
}
});
// old definition
// layer_ais = new OpenLayers.Layer.TMS("Marinetraffic", "https://tiles.marinetraffic.com/ais_helpers/shiptilesingle.aspx?output=png&sat=1&grouping=shiptype&tile_size=512&legends=1&zoom=${z}&X=${x}&Y=${y}",
// { layerId: 13, numZoomLevels: 19, type: 'png', getURL:getTileURLMarine, isBaseLayer:false, displayOutsideMaxExtent:true, tileSize : new OpenLayers.Size(512,512)
// });
let aisRefreshInterval = null;
layer_ais = new ol.layer.Tile({
visible: false,
maxZom: 19,
properties: {
name: 'Marinetraffic',
layerId: 13,
checkboxId: "checkLayerAis",
cookieKey: "AisLayerVisible",
},
source: new ol.source.XYZ({
tileUrlFunction: function(coordinate) {
return getTileURLMarine("https://tiles.marinetraffic.com/ais_helpers/shiptilesingle.aspx?output=png&sat=1&grouping=shiptype&tile_size=512&legends=1&zoom=${z}&X=${x}&Y=${y}", coordinate);
},
tileGrid: tileGrid512
}),
});
layer_ais.on("change:visible", (evt) => {
updateCheckboxAndCookie(evt.target);
document.getElementById("license_marine_traffic").style.display = evt.target.getVisible() ? 'inline' : 'none';
// Refresh position every 1 minute. marine traffic requests are cached for 2 minutes.
// See http cache-control header.
window.clearInterval(aisRefreshInterval);
if (evt.target.getVisible()) {
aisRefreshInterval = window.setInterval(()=> {
layer_ais.getSource().refresh();
}, 60000);
}
});
// SatPro
// old definition
// satPro = new SatPro(map, selectControl, {
// layerId: 14
// });
// layer_satpro = satPro.getLayer();
// Disaster (15)
layer_satpro = new ol.layer.Vector({
visible: false,
properties: {
name: "SatPro",
layerId: 14,
checkboxId: "checkLayerSatPro",
cookieKey: "SatProLayerVisible",
},
source: new ol.source.Vector({
features: [],
strategy: ol.loadingstrategy.bbox,
loader: function(extent, resolution, projection, success, failure) {
const proj = projection.getCode();
const bbox = ol.proj.transformExtent(extent, map.getView().getProjection(), 'EPSG:4326');
const url = 'api/getSatPro.php?' + 'bbox=' + bbox.join(',');
const xhr = new XMLHttpRequest();
xhr.open('GET', url);
const vectorSource = this;
const onError = function() {
vectorSource.removeLoadedExtent(extent);
failure();
};
xhr.onerror = onError;
xhr.onload = function() {
if (xhr.status == 200) {
var lines = xhr.responseText.split('\n');
var features = [];
var trackPoints = [];
var actualName = '';
for (var i = 0; i < lines.length; i++) {
var line = lines[i];
var vals = line.split('\t');
if (vals.length === 1) {
// New vessel, but process previous vessel first
if (trackPoints.length > 1) {
// Track line
const lineArr = trackPoints.map((trackPoint)=> {
return ol.proj.fromarkerLonLat([trackPoint.lon, trackPoint.lat]);
});
const lineFeature = new ol.Feature(new ol.geom.LineString(lineArr));
lineFeature.set('type','line');
features.push(lineFeature);
// Track points (ignore first)
for (var j = 1; j < trackPoints.length; j++) {
const point = new ol.geom.Point(ol.proj.fromarkerLonLat([trackPoints[j].lon, trackPoints[j].lat]));
const pointFeature = new ol.Feature(point);
pointFeature.setProperties(trackPoints[j]);
pointFeature.set('type', 'point');
features.push(pointFeature);
lineArr.push(point.clone());
}
// Vessel
const vessel = new ol.Feature(new ol.geom.Point(ol.proj.fromarkerLonLat([trackPoints[0].lon, trackPoints[0].lat])));
vessel.setProperties(attributes);
vessel.set('type', 'actual');
features.push(vessel);
}
actualName = vals[0];
trackPoints = [];