-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
92 lines (83 loc) · 2.99 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
<!DOCTYPE html>
<html>
<head>
<title>Map Viewer</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
<style>
body {
font-family: Arial, sans-serif;
}
#map {
height: 90vh;
width: 100vw;
display: none;
}
#controls {
text-align: center;
padding: 20px;
}
</style>
</head>
<body>
<div id="controls">
<label for="mapSelect">Select a map:</label>
<select id="mapSelect">
<!-- Options will be populated by JavaScript -->
</select>
<button id="loadMap">Load Map</button>
</div>
<div id="map"></div>
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
<script src="https://d3js.org/d3.v6.min.js"></script>
<script>
// Define map options
var maps = {
'Erangle': 'https://github.com/pubg/api-assets/blob/master/Assets/Maps/Erangel_Main_High_Res.png',
'Map 2': 'path/to/your_map2.png'
};
// Populate the select element with map options
var mapSelect = document.getElementById('mapSelect');
for (var mapName in maps) {
var option = document.createElement('option');
option.value = maps[mapName];
option.text = mapName;
mapSelect.appendChild(option);
}
document.getElementById('loadMap').addEventListener('click', function() {
var selectedMap = mapSelect.value;
loadMap(selectedMap);
});
function loadMap(imageUrl) {
document.getElementById('controls').style.display = 'none';
document.getElementById('map').style.display = 'block';
// Initialize the map
var map = L.map('map').setView([0, 0], 2);
// Custom map image dimensions and bounds
var imageWidth = 8000;
var imageHeight = 8000;
var southWest = map.unproject([0, imageHeight], 1);
var northEast = map.unproject([imageWidth, 0], 1);
var bounds = new L.LatLngBounds(southWest, northEast);
// Add the image overlay to the map
L.imageOverlay(imageUrl, bounds).addTo(map);
// Fit the map to the image bounds
map.fitBounds(bounds);
var points = [];
// Add a click event to get distance between two points
map.on('click', function(e) {
if (points.length < 2) {
points.push(e.latlng);
L.marker(e.latlng).addTo(map);
}
if (points.length === 2) {
var distance = map.distance(points[0], points[1]);
alert('Distance: ' + distance.toFixed(2) + ' meters');
points = [];
}
});
}
</script>
</body>
</html>