-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcoordman.js
144 lines (126 loc) · 3.74 KB
/
coordman.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
if (!("userdata" in window))
alert("Userdata corrupted or not found, please consult console logs and the README!")
let openSidebar = () => document.getElementById("sidebar").style.width = "350px";
let closeSidebar = () => document.getElementById("sidebar").style.width = "0";
let attribution = '<a href="https://github.com/rebane2001/coordman">Coordman</a> by Rebane';
let tileSize = 512;
// Layers for different dimensions
let tileLayers = {
"nether": L.tileLayer(
'tiles/{DIM}/{z}/{x},{y}.png', {
attribution,
tileSize,
maxZoom: 0,
minZoom: -16,
DIM: "DIM-1"
}),
"netherbg": L.tileLayer(
'tiles/{DIM}/{z}/{x},{y}.png', {
attribution,
tileSize,
maxZoom: 0,
minZoom: -16,
zoomOffset: 3,
DIM: "DIM-1"
}),
"overworld": L.tileLayer(
'tiles/{DIM}/{z}/{x},{y}.png', {
attribution,
tileSize,
maxZoom: 0,
minZoom: -16,
DIM: "DIM0"
}),
"end": L.tileLayer(
'tiles/{DIM}/{z}/{x},{y}.png', {
attribution,
tileSize,
maxZoom: 0,
minZoom: -16,
DIM: "DIM1"
})
};
let layers = {
"Overworld+Nether": L.layerGroup([tileLayers['netherbg'],tileLayers['overworld']]),
"Overworld": tileLayers['overworld'],
"Nether": tileLayers['nether'],
"The End": tileLayers['end']
};
// Guide overlays
let worldBorder = L.polyline([
[-30000000, -30000000],
[-30000000, 30000000],
[30000000, 30000000],
[30000000, -30000000],
[-30000000, -30000000]
], {color: 'red'});
let mainHighways = L.polyline([
[0, 0],
[-30000000, 0],
[0, 0],
[30000000, 0],
[0, 0],
[0, -30000000],
[0, 0],
[0, 30000000],
[0, 0]
], {color: 'LimeGreen'});
let diagHighways = L.polyline([
[0, 0],
[-30000000, -30000000],
[0, 0],
[30000000, -30000000],
[0, 0],
[-30000000, 30000000],
[0, 0],
[30000000, 30000000],
[0, 0]
], {color: 'MediumSpringGreen'});
let disabledLayer = L.tileLayer("",{minZoom: 99});
let waypoints = {
"- Guides -": disabledLayer,
"Worldborder": worldBorder,
"Main Highways": mainHighways,
"Diag. Highways": diagHighways,
"- <a href=\"#\" onClick=\"openSidebar()\">Waypoints</a> -": disabledLayer,
};
let defaultLayers = [tileLayers['overworld'], worldBorder];
let sidebar = document.getElementById("sidebar");
// Load icons/locations from userdata
for (const group of window.userdata.groups){
let groupItems = [];
sidebar.innerHTML += `<h3>${group.name}</h3>`
for (const marker of group.markers){
let icon = L.icon({
iconUrl: `icons/${marker.icon}.png`,
shadowUrl: 'icons/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
tooltipAnchor: [16, -28],
shadowSize: [41, 41]
});
// Leaflet maps use a weird coordinate system, so this is fine
let newMarker = L.marker([-marker.coords[1], marker.coords[0]], {icon});
let markerData = (typeof marker.data == "string") ? marker.data : marker.data.join("<br>\n");
newMarker.bindPopup(`<h3>${marker.name}</h3>${markerData}`);
groupItems.push(newMarker);
console.log(newMarker.getLatLng());
sidebar.innerHTML += `${marker.name} (<a href="#" onClick="map.setView([${-marker.coords[1]},${marker.coords[0]}],0)">${marker.coords}</a>)<br>`;
}
waypoints[group.name] = L.layerGroup(groupItems);
if (group.default)
defaultLayers.push(waypoints[group.name]);
}
// Create the map
var map = L.map('map', {
crs: L.CRS.Simple,
minZoom: -16,
layers: defaultLayers
}).setView([0,0], 0);
L.control.layers(layers, waypoints).addTo(map);
// Set coord overlay on the bottom
map.on('mousemove', function(ev) {
let coords = [Math.round(ev.latlng.lng),Math.round(-ev.latlng.lat)];
document.getElementById("coordstext").innerText = "Coords: " + coords;
});