/
map.html
136 lines (119 loc) · 5.23 KB
/
map.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
<head>
<title>ETS2 Local Radio map</title>
<meta charset="utf-8">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css"
integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ=="
crossorigin=""/>
<style>
.lightblue {
background-color: lightblue;
}
body {
background: url('lib/img/loading.gif') no-repeat fixed center;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js"
integrity="sha512-/Nsx9X4HebavoBvEBuyp3I7od5tA0UzAxs+j83KgC8PU0kgB4XiK4Lfe4y4cgBtaRJQEIFCW+oC506aPT2L1zw=="
crossorigin=""></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/randomcolor/0.4.4/randomColor.js"></script>
<script src="config.js"></script>
<!--
<script src="cities/cities-ets2.js"></script>
<script src="stations/stations-europe.js"></script>
-->
</head>
<body style="margin: 0;">
<div id="map" style="width: 100vw; height: 100vh;"></div>
<!--div style="overflow: scroll; width: 100vw; height: 100vh;" id="draw"></div-->
<script>
loadScripts();
function loadScripts() {
var game = "ets2";
if(window.location.href.split("?").length > 1) {
if (window.location.href.split("?")[1].indexOf("ats") == 0){
game = "ats";
}
}
$.getScript("stations/" + g_skinConfig[game].stations, function () {
$.getScript("cities/" + g_skinConfig[game].map, function () {
initialise();
});
});
}
var map;
function initialise() {
map = L.map('map', {
crs: L.CRS.Simple,
minZoom: -10
}).setView([0, 0], -8);
//L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
// attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
//}).addTo(map);
var country_colors = {};
var overlay_countries = {};
for (var i = 0; i < cities.length; i++) {
var lat = cities[i].z;
var lon = cities[i].x;
console.log(cities[i].country);
var radius = (7500) * country_properties[cities[i].country].relative_radius;
if (typeof city_properties[cities[i]["gameName"]] !== "undefined" && typeof city_properties[cities[i]["gameName"]]["relative_radius"] !== "undefined") {
radius = radius * city_properties[cities[i]["gameName"]]["relative_radius"];
}
lat = -lat;
if (!country_colors.hasOwnProperty(cities[i].country)) {
country_colors[cities[i].country] = randomColor();
overlay_countries[cities[i].country] = L.layerGroup([]);
}
//L.marker([lat, lon]).addTo(map)
var circle = L.circle([lat, lon], {
color: country_colors[cities[i].country],
fillColor: country_colors[cities[i].country],
fillOpacity: 0.3,
radius: radius
}).bindTooltip("<strong style='color: " + country_colors[cities[i].country] + "'>" + cities[i].gameName + "</strong>", {permanent: true}).openTooltip();;
var whitenoise = radius * 0.6;
if (typeof city_properties[cities[i].gameName] !== "undefined") {
if (typeof city_properties[cities[i].gameName]["relative_whitenoise"] !== "undefined") {
whitenoise = whitenoise / city_properties[cities[i].gameName]["relative_whitenoise"];
}
}
var circle2 = L.circle([lat, lon], {
color: "#25383C",
fillColor: "#ffffff",
fillOpacity: 0,
radius: whitenoise
});
overlay_countries[cities[i].country].addLayer(circle).addTo(map);
overlay_countries[cities[i].country].addLayer(circle2).addTo(map);
}
overlay_countries = sortObject(overlay_countries);
L.control.layers(null, overlay_countries).addTo(map);
map.attributionControl.addAttribution("<a href='javascript:showCurrentPosition()'>Show current location</a> | <a href='?ats'>ATS map</a>");
map.on("click", function (e) {
console.log("X: " + e.latlng.lng + "; Y: " + -e.latlng.lat);
})
}
function sortObject(obj) {
return Object.keys(obj).sort().reduce(function (result, key) {
result[key] = obj[key];
return result;
}, {});
}
var currentMarker = null;
function showCurrentPosition() {
$.getJSON("/api/", function (data) {
var lat = -data.Physics.CoordinateZ;
var lon = data.Physics.CoordinateX;
if(currentMarker == null) {
currentMarker = L.marker([lat, lon]).addTo(map).bindTooltip("<strong>Your current position</strong>", {
permanent: true,
className: "lightblue"
}).openTooltip();
} else {
currentMarker.setLatLng([lat, lon]);
}
});
}
</script>
</body>