forked from credomane/FactorioMods_FactorioMaps
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html.template
532 lines (476 loc) · 17.2 KB
/
index.html.template
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
<!DOCTYPE html>
<html>
<head>
<title>FactorioMaps</title>
<script src="/cdn-cgi/apps/head/ThhfSzyp6GI_EE-HfsckZnD6ThE.js"></script><link href="https://factorio.com/static/img/favicon.ico" rel="icon" type="image/x-icon">
<meta name="og:image" content="https://i.factoriomaps.com/t92kw.png" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.3/leaflet.css" integrity="sha256-iYUgmrapfDGvBrePJPrMWQZDcObdAcStKBpjP3Az+3s="
crossorigin="anonymous" />
<style type="text/css">
html {
height: 100%
}
body {
height: 100%;
margin: 0px;
padding: 0px
}
#map {
height: 100%;
z-index: 0;
background-color: rgb(27, 44, 51) !important;
}
#gmnoprint {
width: auto;
}
/* DOWN BUTTON CSS */
#downBtn {
position: fixed;
/* Fixed/sticky position */
bottom: 0px;
/* Place the button at the bottom of the page */
right: 50%;
transform: translate(50%, 0);
z-index: 99;
/* Make sure it does not overlap */
border: none;
/* Remove borders */
outline: none;
/* Remove outline */
background-color: chocolate;
/* Set a background color */
color: white;
/* Text color */
cursor: pointer;
/* Add a mouse pointer on hover */
padding: 5px;
/* Some padding */
border-radius: 7px;
/* Rounded corners */
font-size: 18px;
/* Increase font size */
}
#downBtn:hover {
background-color: #555;
/* Add a dark-grey background on hover */
}
/* FANCY DOWNLOAD CSS */
#modal {
display: none;
position: absolute;
top: 150px;
bottom: 30px;
background-color: rgb(27, 45, 51);
padding: 20px;
z-index: 100;
width: 400px;
right: 50%;
margin-right: -200px;
border: none;
border-radius: 5px;
color: #C6FFFD;
}
#modal.open {
display: block;
}
#modal ul li {
list-style-type: none;
margin-bottom: 5px;
}
#modal .close {
cursor: pointer;
float: right;
margin-top: -20px;
}
#modal .title {
font-size: 2em;
text-align: center;
margin-bottom: 15px;
}
#modal .mapLayerLink {
float: right;
padding: 0px 25px;
background-color: chocolate;
color: #CFFFFD;
border-radius: 8px;
line-height: 35px;
}
#modal .mapLayerLink.disabled {
background-color: grey;
cursor: not-allowed;
}
#modal .mapLayerLink:hover {
background-color: #555;
}
hr.clear {
clear: both;
float: none;
border: 0;
width: 0;
height: 0;
padding: 0;
margin: 0;
}
#modal .body {
overflow-y: auto;
max-height: 92%;
}
/* END FANCY DOWNLOAD CSS */
#nextBtn {
position: fixed; /* Fixed/sticky position */
top: 50%; /* Place the button at the bottom of the page */
right: -38px; /* Place the button 30px from the right */
z-index: 99; /* Make sure it does not overlap */
border: none; /* Remove borders */
outline: none; /* Remove outline */
background-color: chocolate; /* Set a background color */
color: white; /* Text color */
cursor: pointer; /* Add a mouse pointer on hover */
padding: 6px; /* Some padding */
border-radius: 6px; /* Rounded corners */
font-size: 18px; /* Increase font size */
transform: rotate(90deg);
}
#nextBtn:hover {
background-color: #555; /* Add a dark-grey background on hover */
}
#prevBtn {
position: fixed; /* Fixed/sticky position */
top: 50%; /* Place the button at the bottom of the page */
left: -35px; /* Place the button 30px from the right */
z-index: 99; /* Make sure it does not overlap */
border: none; /* Remove borders */
outline: none; /* Remove outline */
background-color: chocolate; /* Set a background color */
color: white; /* Text color */
cursor: pointer; /* Add a mouse pointer on hover */
padding: 6px; /* Some padding */
border-radius: 6px; /* Rounded corners */
font-size: 18px; /* Increase font size */
transform: rotate(-90deg);
}
#prevBtn:hover {
background-color: #555; /* Add a dark-grey background on hover */
}
img.leaflet-tile.leaflet-tile-loaded {
image-rendering: pixelated;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.3.3/leaflet.js" integrity="sha256-lwWHyfIX653fxmxYjZUYOSM7ufWv6dMT8ISVuTWwoOY="
crossorigin="anonymous"></script>
<link href='https://cdnjs.cloudflare.com/ajax/libs/leaflet.fullscreen/1.4.5/Control.FullScreen.css' rel='stylesheet'
/>
<script src='https://cdnjs.cloudflare.com/ajax/libs/leaflet.fullscreen/1.4.5/Control.FullScreen.min.js'></script>
<!-- HERE: DONT FORGET TO FIX THIS -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<!-- HERE: ESPECIALLY THESE TWO -->
<link rel="stylesheet" href="https://rawgit.com/L0laapk3/Leaflet.OpacityControls/master/Control.Opacity.css" />
<script src="https://rawgit.com/L0laapk3/Leaflet.OpacityControls/master/Control.Opacity.js" ></script>
<script src="mapInfo.js"></script>
</head>
<body>
<div id="map" style="background: #1B2D33;"></div>
<script>
"use strict";
//var _getTileUrl = L.TileLayer.prototype.getTileUrl;
//L.TileLayer.prototype.getTileUrl = function(coords) { return _getTileUrl.call(this, {x: coords.x - 1 * Math.pow(2, coords.z - 2), y: coords.y, z: coords.z}); };
L.TileLayer.prototype.getTileUrl = function(c) {
var mapIndex = this.tileIndex[c.z] && this.tileIndex[c.z][c.y] && this.tileIndex[c.z][c.y][c.x];
if (isNaN(mapIndex))
mapIndex = this.tileIndex.fallback;
if (isNaN(mapIndex))
return "";
return "Images/" + mapInfo.maps[mapIndex].path + "/" + this.surface + "/" + this.daytime + "/" + c.z + "/" + c.x + "/" + c.y + ".jpg";
}
var surface = "nauvis";
var layers = [], saves = [], countAvailableSaves = 0;
var globalTileIndex = {};
var globalTileNightIndex = {};
for (var i = 0; i < mapInfo.maps.length; i++) {
var map = mapInfo.maps[i];
var layer = map.surfaces[surface];
if (!globalTileNightIndex[surface]) {
globalTileNightIndex[surface] = layer.chunks ? {} : {fallback: i};
globalTileIndex[surface] = layer.chunks ? {} : {fallback: i};
}
for (var z = layer.zoom.min; z <= layer.zoom.max; z++)
if (!globalTileNightIndex[surface][z]) {
globalTileNightIndex[surface][z] = {};
globalTileIndex[surface][z] = {};
}
(layer.chunks || "").split('=').forEach(function(row) {
function B64Parse(offset) {
return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(row[offset])
+ 64 * "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(row[offset+1])
+64*64*"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(row[offset+2])
- 2**16;
}
console.assert(row.length % 3 == 0); //corrupted data, prevent infinite loop
var j = 3, y = B64Parse(0) - 2**17;
if (!globalTileNightIndex[surface][layer.zoom.max][y]){
globalTileNightIndex[surface][layer.zoom.max][y] = {};
globalTileIndex[surface][layer.zoom.max][y] = {};
}
while (j < row.length) {
var stop = B64Parse(j + 3)
var start = B64Parse(j);
var mode = start > 2**16;
for (var x = start - mode*2**17; x < (stop - (stop>2**16)*2**17); x++) {
globalTileNightIndex[surface][layer.zoom.max][y][x] = i;
if (mode)
globalTileIndex[surface][layer.zoom.max][y][x] = i;
for (var z = 1; z <= layer.zoom.max - layer.zoom.min; z++) {
if (!globalTileNightIndex[surface][layer.zoom.max-z][y >> z]) {
globalTileNightIndex[surface][layer.zoom.max-z][y >> z] = {};
globalTileIndex[surface][layer.zoom.max-z][y >> z] = {};
}
if ((mode ? globalTileIndex : globalTileNightIndex)[surface][layer.zoom.max-z][y >> z][x >> z] == i)
break;
globalTileNightIndex[surface][layer.zoom.max-z][y >> z][x >> z] = i;
if (mode)
globalTileIndex[surface][layer.zoom.max-z][y >> z][x >> z] = i;
}
}
j += mode == stop > 2**16 ? 6 : 3;
}
});
var tileIndex = { fallback: globalTileIndex[surface].fallback };
for (var z in globalTileIndex[surface]) {
if (z == "fallback")
continue;
tileIndex[z] = {};
for (var y in globalTileIndex[surface][z]) {
tileIndex[z][y] = {};
for (var x in globalTileIndex[surface][z][y])
tileIndex[z][y][x] = globalTileIndex[surface][z][y][x];
}
}
var tileNightIndex = { fallback: globalTileNightIndex[surface].fallback };
for (var z in globalTileNightIndex[surface]) {
if (z == "fallback")
continue;
tileNightIndex[z] = {};
for (var y in globalTileNightIndex[surface][z]) {
tileNightIndex[z][y] = {};
for (var x in globalTileNightIndex[surface][z][y])
tileNightIndex[z][y][x] = globalTileNightIndex[surface][z][y][x];
}
}
layers[i] = {};
["day", "night"].forEach(function(daytime) {
if (layer[daytime] == "true") {
var LLayer = L.tileLayer(undefined, {
id: layer.path,
attribution: '<a href="https://github.com/L0laapk3/FactorioMods_FactorioMaps">FactorioMaps</a>',
minNativeZoom: layer.zoom.min,
maxNativeZoom: layer.zoom.max,
minZoom: layer.zoom.min >= 1 ? layer.zoom.min - 1 : 1,
maxZoom: 23, //layer.zoom.max + 2,
noWrap: true,
tileSize: 512 / window.devicePixelRatio,
keepBuffer: 3
});
LLayer.surface = surface;
LLayer.daytime = daytime;
LLayer.path = map.path;
LLayer.tileIndex = daytime == "day" ? tileIndex : tileNightIndex;
layers[i][daytime] = LLayer;
}
});
/* EDIT */
if (layer.save && layer.save.download) {
saves.push({
layer: layer.save.name || layer.name,
url: layer.save.url
});
if (layer.save.url) {
countAvailableSaves++;
}
}
/* END EDIT */
}
/* EDIT */
if (countAvailableSaves > 0 || mapInfo.links && mapInfo.links.save) {
var btn = document.createElement("a"), modal = document.getElementById("modal"), ulContainer = document.getElementById("save-download-container"), modalClose = modal.getElementsByClassName("close")[0], opened = false, built = false;
btn.id = 'downBtn';
btn.appendChild(document.createTextNode("Download Save"))
if (saves.length <= 1) {
//Act like a download link
btn.href = saves.length === 1 ? saves[0].url : m.links.save;
btn.target = '_blank';
} else {
btn.addEventListener('click', function () {
if (!opened) {
if (!built) {
//Empty the modal, re-create modal content and display it
while (ulContainer.lastChild) {
ulContainer.removeChild(ulContainer.lastChild);
}
for (var i in saves) {
if (saves.hasOwnProperty(i)) {
var saveObj = saves[i];
var li = document.createElement("li"), a = document.createElement("a"), span = document.createElement("span"), hr = document.createElement("hr");
hr.classList.add("clear");
a.classList.add("mapLayerLink");
li.classList.add("mapLayer");
a.appendChild(document.createTextNode("Download"));
a.target = "_blank";
if (!saveObj.url) {
a.setAttribute("disabled", "disabled");
a.classList.add("disabled");
} else {
a.href = saveObj.url;
}
span.classList.add("mapLayerName")
span.appendChild(document.createTextNode(saveObj.layer));
li.appendChild(span);
li.appendChild(a);
li.appendChild(hr);
ulContainer.appendChild(li);
}
}
modal.classList.add("open");
opened = true;
}
}
});
modalClose.addEventListener("click", function () {
if (opened) {
modal.classList.remove("open");
opened = false;
}
});
}
document.getElementById("buttonAnchor").appendChild(btn);
}
var nightOpacity = 0;
var timestamp = (layers[0].day || layers[0].night).path;
var startZ = 16, startX = 0, startY = 0;
var coordScale = 2**19 / 16 * window.devicePixelRatio;
try {
var split = window.location.hash.substr(1).split('/');
if (window.location.hash[0] == '#' && split[0] == "1" && split[1] == "nauvis") {
if (!isNaN(parseInt(split[2]))) startZ = parseInt(split[2]);
startX = parseInt(split[3]) / coordScale || startX;
startY = parseInt(split[4]) / coordScale || startY;
nightOpacity = parseFloat(split[5]) || nightOpacity;
if (!isNaN(parseInt(split[6]))) {
timestamp = split[6];
if (!isNaN(parseInt(split[7])))
timestamp += "-" + split[7];
}
}
} catch (_) {}
var lastHash = "";
function updateHash() {
//console.log(map.getZoom(), Math.round(map.getCenter().lat * coordScale), Math.round(map.getCenter().lng * coordScale), nightOpacity, timestamp);
var hash = "#" + [1, surface, map.getZoom(), Math.round(map.getCenter().lat * coordScale), Math.round(map.getCenter().lng * coordScale), nightOpacity, timestamp.replace('-', '/')].join("/");
if (hash != lastHash) {
window.location.replace(hash);
lastHash = hash;
}
}
/* END EDIT */
var leafletLayers = [];
var map = L.map('map', {
center: [startX, startY],
zoom: startZ,
layers: [],
fadeAnimation: false,
zoomAnimation: true,
crs: L.CRS.Simple // the map is 2D by nature
});
map.on("zoomend moveend", updateHash);
var opacitySlider, timeSlider;
var mapLoadedBySlider = false;
if (layers.some(function(layer) { return layer.day; }) && layers.some(function(layer) { return layer.night; })) {
//L.control.layers({Day: layers.Day}, {Night: layers.Night}, { collapsed: m.meta.map.options.collapseLayerList }).addTo(map).setPosition('bottomright');
opacitySlider = new L.Control.opacitySlider({
position: "bottomright",
orientation: "horizontal",
initial: nightOpacity,
length: 135,
gravitate: 7,
labels: [ {name: "Day", position: 0, layers: layers.map(l => l.day)}, {name: "Nightvision", position: .42, gravitate: 5}, {name: "Night", position: 1, layers: layers.map(l => l.night)} ],
onChange: function(value) {
nightOpacity = Math.round(value * 100) / 100;
updateHash();
}
});
map.addControl(opacitySlider);
mapLoadedBySlider = true;
}
if (layers.length > 1 && true) {
var min = Math.min.apply(undefined, mapInfo.maps.map(l => parseInt(l.path)));
var max = Math.max.apply(undefined, mapInfo.maps.map(l => parseInt(l.path)));
var len = Math.min(window.innerHeight * .8, Math.max(95, 45 * (layers.length - 1)));
var timeLabels = layers.map(function(layer, i) {
return {
name: mapInfo.maps[i].path + "h",
position: i * 30/len + (parseInt(mapInfo.maps[i].path) - min) / (max - min) * (1 - (layers.length - 1) * 30/len),
layers: ["day", "night"].map(n => layer[n]).filter(l => l)
}
});
var initialTime;
for (var i = 0; i < timeLabels.length; i++) {
if (parseFloat(timestamp) < parseInt(timeLabels[i].name)) {
if (!i)
initialTime = timeLabels[i].position;
else
initialTime = timeLabels[i].position - (timeLabels[i].position - timeLabels[i-1].position) * (parseInt(timeLabels[i].name) - parseFloat(timestamp)) / (parseInt(timeLabels[i].name) - parseInt(timeLabels[i-1].name));
break;
} else if (parseFloat(timestamp) == parseInt(timeLabels[i].name)) {
var diff = parseInt(timeLabels[i].name.split("-")[1] || 0) - parseFloat(timestamp.split("-")[1] || 0);
if (diff == 0) {
initialTime = timeLabels[i].position;
break;
} else if (diff > 0) {
initialTime = timeLabels[i].position - (timeLabels[i].position - timeLabels[i-1].position) * diff / (parseInt(timeLabels[i].name.split("-")[1] || 0) - parseInt(timeLabels[i-1].name.split("-")[1] || 0));
break;
}
}
}
timeSlider = new L.Control.opacitySlider({
position: "bottomright",
orientation: "vertical",
initial: initialTime,
length: len,
evenSpacing: true,
gravitate: 5,
backdrop: false,
labels: timeLabels,
onChange: function(value, localValue, below, above) {
if (!above)
timestamp = below.name.slice(0, -1);
else {
var one = below.name.slice(0, -1).split("-");
var two = above.name.slice(0, -1).split("-");
if (one[0] == two[0])
timestamp = one[0] + "-" + Math.round(((parseInt(one[1]) || 0) + localValue * ((parseInt(two[1]) || 0) - (parseInt(one[1]) || 0))) * 100) / 100;
else
timestamp = "" + Math.round((parseInt(one[0]) + localValue * (parseInt(two[0]) - parseInt(one[0]))) * 100) / 100;
}
updateHash();
}
});
map.addControl(timeSlider);
mapLoadedBySlider = true;
}
if (!mapLoadedBySlider)
map.addLayer(layers[0].day || layers[0].night);
map.addControl(new L.Control.FullScreen().setPosition('bottomright'));
map.zoomControl.setPosition('bottomleft')
/*if (m.meta.map.markers !== null && m.meta.map.markers !== undefined) {
for (i = 0; i < m.meta.map.markers.length; i++) {
var markerData = m.meta.map.markers[i], div = document.createElement('div'), title = document.createElement('h3');
div.innerHTML = '<h3>' + markerData.title + '</h3>' + markerData.text;
L.marker(markerData.coords, { title: markerData.title }).addTo(map).bindPopup(div);
}
}*/
</script>
</body>
</html>