-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange-language.html
69 lines (66 loc) · 2.11 KB
/
change-language.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
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<link href="https://unpkg.com/[email protected]/dist/maplibre-gl.css" rel="stylesheet" />
<script src="https://unpkg.com/[email protected]/dist/maplibre-gl.js"></script>
<style>
html,
body {
margin: 0;
padding: 0;
height: 100%;
}
#map {
min-height: 500px;
height: 100%;
width: 100%;
}
select {
z-index: 1;
position: absolute;
top: 5px;
left: 5px;
padding: 5px;
background: white;
}
</style>
</head>
<body>
<div id="map">
<select id="languages">
<option selected>Automatic</option>
<option value="en">English</option>
<option value="fr">French</option>
<option value="it">Italian</option>
<option value="es">Spanish</option>
<option value="de">German</option>
<option value="nl">Dutch</option>
<option value="zh">Chinese</option>
<option value="ja">Japanese</option>
<option value="ko">Korean</option>
<option value="ru">Russian</option>
</select>
</div>
<script>
// Don't forget to replace <YOUR_ACCESS_TOKEN> by your own access token
const accessToken = "<YOUR_ACCESS_TOKEN>";
const styleId = "jawg-lagoon";
const map = new maplibregl.Map({
container: "map",
style: `https://api.jawg.io/styles/${styleId}.json?access-token=${accessToken}`,
zoom: 2,
center: [2.3210938, 48.7965913],
hash: true,
}).addControl(new maplibregl.NavigationControl(), "top-right");
// This plugin is used for right to left languages
maplibregl.setRTLTextPlugin("https://unpkg.com/@mapbox/[email protected]/mapbox-gl-rtl-text.min.js");
map.on("load", () => {
document.getElementById("languages").addEventListener("change", (event) => {
const language = event.target.value;
map.setStyle(`https://api.jawg.io/styles/${styleId}.json?access-token=${accessToken}&lang=${language}`);
});
});
</script>
</body>
</html>