-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.switcher.js
47 lines (38 loc) · 1.91 KB
/
map.switcher.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
var mapSelectorContainer = document.createElement('div');
mapSelectorContainer.className = 'map-switcher';
let mapNames = mapPropertiesArray.map(map => map.worldName);
// Create and append radio buttons for each map
mapNames.forEach((map, index) => {
let radioButton = document.createElement('input');
radioButton.type = 'radio';
radioButton.name = 'mapSelector';
radioButton.value = map;
radioButton.id = 'map' + index;
radioButton.defaultChecked = index === 0;
let label = document.createElement('label');
label.htmlFor = 'map' + index;
label.appendChild(document.createTextNode(map));
mapSelectorContainer.appendChild(radioButton);
mapSelectorContainer.appendChild(label);
mapSelectorContainer.appendChild(document.createElement('br'));
});
document.body.appendChild(mapSelectorContainer);
// Add event listener to switch maps when a radio button is selected
document.getElementsByName('mapSelector').forEach((radioButton, index) => {
radioButton.addEventListener('change', function() {
if (this.checked) {
let selectedMapProperties = mapPropertiesArray[index];
let selectedMapRegions = mapRegionsArray[index];
let selectedMapMarkers = mapCustomMarkersArray[index];
let selectedMapPlayers = mapPlayersArray[index];
if (selectedMapMarkers && selectedMapMarkers.isEnabled && selectedMapMarkers.markers) {
selectedMapProperties.markers = selectedMapProperties.markers.concat(selectedMapMarkers.markers);
}
if (selectedMapPlayers && selectedMapPlayers.length > 0) {
selectedMapProperties.markers = selectedMapProperties.markers.concat(unmined.createPlayerMarkers(selectedMapPlayers));
}
document.getElementById('map').innerHTML = ''; // clear current map
unmined.map('map', selectedMapProperties, selectedMapRegions);
}
});
});