-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
367 lines (346 loc) · 18.2 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<!DOCTYPE html>
<html>
<head>
<title>Map | Narvik Bunkers</title>
<meta charset="utf-8">
<meta name="author" content="Chris Petrich">
<meta name="description" content="Location map of WW2 bunkers, tunnels and structures in and around Narvik, Ofoten, Norway, mostly built by German forces, among them Regelbau bunkers 634 and 628. Some tunnels feature German steel doors 434P01 or 436P01, or gas doors 19P7 or 723P3.">
<!-- tell mobile browser to turn off scaling -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link rel="stylesheet" href="https://necolas.github.io/normalize.css/latest/normalize.css" />
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.14.0/css/all.min.css" />
<!-- locate control plug-in -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet.locatecontrol/dist/L.Control.Locate.min.css" />
<script src="https://cdn.jsdelivr.net/npm/leaflet.locatecontrol/dist/L.Control.Locate.min.js" charset="utf-8"></script>
<!-- use UTM33-projected tiles -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.7.5/proj4.min.js" integrity="sha512-Nwp3XMQKRvqr376bCa50Hs4X4z5zbsefo63QLa62poTx5o/GhYgjnToCoBZk7bxjeP2y84oEgKNUrpK2+2Czyg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4leaflet/1.0.2/proj4leaflet.min.js" integrity="sha512-GsAYl1wxzWW6azVpXkhyYfjMb2LbaOnlrqWMBdAk9xDcilinFvGMN+48Ajp/10u/9lcnh8YyS2CYNgung7ewHg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<style>
html, body {
padding: 0;
margin: 0;
}
html, body, #map {
height: 100%;
width: 100vw;
}
.full {
height: 100%;
width: 100vw;
position: relative;
}
.leaflet-popup-content { min-width: 15em; max-width:15em;} /* this typically scales with text width, so fix it here. */
.tips, a.tips {
box-shadow: 2px 2px 1px black;
margin-left: 0.1em;
margin-right: 0.1em;
border-radius: 0.5em;
border: 1px solid black;
font-size: 130%;
padding: 0.5em;
background: rgba(222,240,255,1);
color: black;
}
#infoBanner {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: rgba(255,255,255,0.7);
color: black;
padding: 1em 2em 1em 2em;
font: italic small-caps bold 100% sans-serif;
z-index: 1001;
display: none;
}
#infoBannerClose {
position: absolute;
top:0.2em;
right:0.2em;
font-size: 120%;
}
</style>
</head>
<body>
<div id="map"></div>
<div id="infoBanner">Feil eller noe som mangler? Send epost til
<a href="mailto:narvik.bunkers@gmail.com">narvik.bunkers@gmail.com</a>.
<br>Mer info: <a href="/about">www.narvik-bunkers.no/about/</a>
<button id="infoBannerClose">X</button>
</div>
<script>
var center_loc = -1;
var zoom_value = 18;
var pos_code = -1;
var params = new URLSearchParams(window.location.search);
if (params.has('ll')) {
var lls = params.get('ll');
if (lls.length < 100) {
var segments = lls.split(",");
if (segments.length == 2) {
var lat = +(segments[0]);
var lon = +(segments[1]);
if ((lat==lat) && (lon==lon) && (lat >= -90) && (lat <=90) && (lon>=-180) && (lon<=180)) {
center_loc = [lat, lon];
}
}
}
}
if (params.has('z')) {
var lls = params.get('z');
if (lls.length < 100) {
var zoom = +(lls);
if ((zoom >=1) && (zoom <= 20)) {
zoom_value = zoom;
}
}
}
if (params.has('pos')) {
var pos = params.get('pos');
if (pos.length >= 3) {
pos_code = pos.split('-');
}
}
if ((sessionStorage.getItem('infoBannerClosed') !== 'closed') &&
(!(navigator.userAgent.toLowerCase().includes('bot') ||
navigator.userAgent.toLowerCase().includes('crawl') ||
navigator.userAgent.toLowerCase().includes('spider') ||
navigator.userAgent.toLowerCase().includes('preview') ||
navigator.userAgent.toLowerCase().includes('search')))) {
document.getElementById('infoBanner').style.display = 'block';
}
document.getElementById('infoBannerClose').onclick = function(){
document.getElementById('infoBanner').style.display = 'none';
sessionStorage.setItem('infoBannerClosed','closed');
return false;
};
var url2 = 'narvik-bunkers.json';
L.tmhandler = L.Handler.extend({
addHooks: function() {
L.DomEvent.on(this._map._container, 'touchmove', this._touch, this);
},
_touch: function(e) {
cpos = map.getBounds().getCenter().lat + ' ' + map.getBounds().getCenter().lng;
}
});
L.Map.addInitHook('addHandler', 'ttmove', L.tmhandler);
var map = null;
const utm33Projection = true;
if (!utm33Projection) {
map = L.map('map',{zoomSnap:0}).fitBounds([[68.428, 17.37],[68.45, 17.54]]); // or use setView() to set the zoom level explicitly
L.tileLayer('https://cache{s}.kartverket.no/v1/wmts/1.0.0/topo/default/webmercator/{z}/{y}/{x}.png', {
attribution: '<a href="https://www.kartverket.no/">Kartverket</a> | <a href="/about/">Narvik Bunkers</a>',
subdomains: ['','2','3','4']
}).addTo(map);
} else {
// instantiation from https://github.com/cpetrich/leaflet-kartverket-UTM33, MIT license
const crsStr = 'EPSG:25833'; // a.k.a. utm33n
const crsProj4 = '+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs';
const crsTileOrg = [-2500000, 9045984];
const crsBaseResolution = 21664;
const crsMaxZoom = 18;
const crs = new L.Proj.CRS(crsStr, crsProj4,
{ origin: crsTileOrg,
resolutions: Array.from(Array(crsMaxZoom+2),(e,zoomLevel) => crsBaseResolution/Math.pow(2,zoomLevel))
});
map = L.map('map', {
zoomSnap: 0,
crs: crs,
}).fitBounds([[68.428, 17.37],[68.45, 17.54]]);
const url = 'https://cache{s}.kartverket.no/v1/wmts/1.0.0/topo/default/utm33n/{z}/{y}/{x}.png';
const kartverketTiles = L.tileLayer(url, {
subdomains: ['', '2', '3', '4'],
maxZoom: crsMaxZoom,
attribution: '<a href="https://www.kartverket.no/">Kartverket</a> | <a href="/about/">Narvik Bunkers</a>',
});
map.addLayer(kartverketTiles);
}
map.ttmove.enable();
if (center_loc != -1) {
map.setView(center_loc, zoom_value);
}
var locate = L.control.locate({setView:true, maxZoom:16, locateOptions:{enableHighAccuracy:true}}).addTo(map);
map.on('locationfound', function(e){locate.options.strings.popup = e.latlng.lat.toFixed(6) + ', ' + e.latlng.lng.toFixed(6);});
const req = new XMLHttpRequest();
var cpos = 'none';
var ocpos = 'init';
var repcnt = 0;
if (sessionStorage.getItem('tag') === null) {
sessionStorage.setItem('tag', Math.floor(Math.random() * 0x1000000).toString(16));
};
const requestTag = sessionStorage.getItem('tag');
req.open("GET", "https://xdat.eu/narvik-bunkers.no/?t="+requestTag+"&v=1.5&o=m&a=i&z="+encodeURIComponent(map.getZoom().toFixed(1))+"&r="+encodeURIComponent(document.referrer), true);
req.send();
map.on('mousemove', function (e) {cpos = e.latlng.lat + ' ' + e.latlng.lng;} );
map.on('zoomend', function(e) {
var query = 't='+requestTag+'&v=1.5&o=m&a=z';
query += '&l=' + encodeURIComponent(cpos);
query += '&z=' + encodeURIComponent(map.getZoom().toFixed(1));
if (repcnt === 0) {
query += "&r="+encodeURIComponent(document.referrer);
repcnt = 1;
}
if (cpos !== ocpos) {
req.open("GET", "https://xdat.eu/narvik-bunkers.no/?"+query, true);
req.send();
ocpos = cpos;
}
});
var scalebar = L.control.scale({metric:true, imperial:false}).addTo(map);
document.addEventListener("visibilitychange", () => {
req.open("GET", "https://xdat.eu/narvik-bunkers.no/?t="+requestTag+"&v=1.5&o=m&a=v&d="+document.visibilityState, true);
req.send();
});
var infoControl = L.Control.extend({
onAdd: function (map) {
var c = L.DomUtil.create('i');
c.style.fontFamily = 'FontAwesome';
c.style.fontStyle = 'normal';
c.textContent = "\uf05a"; // fa-info-circle
/* real border has an alpha channel */
c.style.border = '2px solid #ccc';
c.style.borderRadius = '3px';
c.style.fontSize = 'large';
c.style.backgroundColor = 'white';
c.style.backgroundSize = "30px 30px";
c.style.width = '30px';
c.style.height = '30px';
c.style.textAlign = 'center';
c.style.lineHeight = '30px';
c.zIndex = 800;
c.onmouseover = function(){
c.style.backgroundColor = '#f4f4f4';
};
c.onmouseout = function(){
c.style.backgroundColor = 'white';
};
c.onclick = function(){
window.open('about/');
};
return c;
}
});
var infoCtrl = new infoControl({position: 'topleft'}).addTo(map);
var BasicMarker = L.Icon.extend({
options: {
iconSize: [11, 11],
iconAnchor: [5, 5],
popupAnchor: [0, -5]
}
});
var HighlightMarker = L.Icon.extend({
options: {
iconSize: [15, 15],
iconAnchor: [7, 7],
popupAnchor: [0, -7]
}
});
var icons = {'circle-red': new BasicMarker({iconUrl: 'icons/circle-ring-red-11.png'}),
'rect-red': new BasicMarker({iconUrl: 'icons/rect-ring-red-11.png'}),
'u-red': new BasicMarker({iconUrl: 'icons/u-ring-red-11.png'}),
'cross-red': new BasicMarker({iconUrl: 'icons/cross-ring-red-11.png'}),
'circle-green': new BasicMarker({iconUrl: 'icons/circle-ring-green-11.png'}),
'circle-orange': new BasicMarker({iconUrl: 'icons/circle-ring-orange-11.png'}),
'circle-black': new BasicMarker({iconUrl: 'icons/circle-black-11.png'}),
'circle-dot-orange': new BasicMarker({iconUrl: 'icons/circle-dot-ring-orange-11.png'}),
'circle-cross-orange': new BasicMarker({iconUrl: 'icons/circle-cross-ring-orange-11.png'}),
'circle-blue-large': new HighlightMarker({iconUrl: 'icons/circle-ring-blue-15.png'})
};
function geojsonEachFeture(feature, layer) {
if (feature.properties && feature.properties.description) {
layer.bindPopup(feature.properties.description);
}
}
var location_data;
var http = new XMLHttpRequest();
http.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200 && this.responseText.substr(0,1) == "{") {
location_data = JSON.parse(this.responseText);
L.geoJSON(location_data.data, {
pointToLayer: function (f, latlng) {
return L.marker(latlng, {icon: icons[f.properties.iconImage]});
},
onEachFeature: geojsonEachFeture
}
).addTo(map);
if (pos_code != -1) {
var xmin = 1e10;
var xmax = -1e10;
var ymin = 1e10;
var ymax = -1e10;
location_data.data.features.forEach(function(item,index) {
if (pos_code.indexOf(item.properties.name) >= 0) {
xmin = item.geometry.coordinates[0] < xmin ? item.geometry.coordinates[0] : xmin;
xmax = item.geometry.coordinates[0] > xmax ? item.geometry.coordinates[0] : xmax;
ymin = item.geometry.coordinates[1] < ymin ? item.geometry.coordinates[1] : ymin;
ymax = item.geometry.coordinates[1] > ymax ? item.geometry.coordinates[1] : ymax;
/* place an icon here, place behind marker so we can still click the marker */
L.marker([item.geometry.coordinates[1],item.geometry.coordinates[0]],{icon: icons['circle-blue-large'], zIndexOffset: -1000}).addTo(map);
}
});
if ((xmin == xmax) && (ymin == ymax))
map.setView([ymin, xmin], zoom_value);
else if ((xmin < xmax) || (ymin < ymax))
map.fitBounds([[ymin-0.001, xmin-0.003],[ymax+0.001, xmax+0.003]]);
}
}
}
http.open("GET", url2, true);
http.send();
map.on('contextmenu', function(e) {
var marker = new L.marker(e.latlng,{
draggable: true,
autoPan: true
}).bindTooltip(e.latlng.lat.toFixed(5)+', '+e.latlng.lng.toFixed(5), {permanent: true, direction: 'right'}).addTo(map);
marker.on('contextmenu',function(e){map.removeLayer(this);});
marker.on('drag',function(e){this.setTooltipContent(e.latlng.lat.toFixed(5)+', '+e.latlng.lng.toFixed(5));});
});
/*
function tips_link(co) {
return '<a href="https://docs.google.com/forms/d/e/1FAIpQLSdkOmRXd3pS02xI5ROxpRH2nw9mbEAzTyI-flyP4Pq5he0MIw/viewform?usp=pp_url&entry.664230702=' + co.lat.toFixed(5) + '+N,+' + co.lng.toFixed(5) + '+%C3%98" class="tips" onclick="event.stopPropagation()" target="_blank" rel="noopener noreferrer">send tips...</a> <span onclick="close_tip(event)" class="tips">X</span>';
}
let single_click = null;
let current_tip = null;
function close_tip(e) {
map.removeLayer(current_tip);
current_tip = null;
e.stopPropagation();
}
function click_handler(e) {
single_click = null;
if (current_tip !== null) map.removeLayer(current_tip);
current_tip = null;
if (map.getZoom() < 13) return; // map too coarse
var marker = new L.marker(e.latlng,{
draggable: true,
autoPan: true
}).bindTooltip(tips_link(e.latlng), {interactive: true, permanent: true, direction: 'right'}).addTo(map);
marker.on('click',function(e){map.removeLayer(this);});
marker.on('drag',function(e){this.setTooltipContent(tips_link(e.latlng));});
current_tip = marker;
}
map.on('click', function(e) {
if (popup_just_closed != 0) return; // if this click had been propagated from a popup close click (i.e. click anywhere on the map) then ignore it
if (single_click === null)
single_click = setTimeout( click_handler, 300, e );
else {
clearTimeout(single_click);
single_click = null;
}
});
map.on('doubleclick', function(e) {
clearTimeout(single_click);
single_click = null;
});
let popup_just_closed = 0;
map.on('popupclose', function(e) {
popup_just_closed = 1; // while this is 1 ignore all (propagated) click events on the map that would otherwise open a suggestion link
setTimeout(function(){popup_just_closed = 0;}, 300);
});
*/
</script>
</body>
</html>