-
Notifications
You must be signed in to change notification settings - Fork 1
/
change-style.html
42 lines (40 loc) · 1.46 KB
/
change-style.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
<html>
<head>
<link href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" rel="stylesheet" />
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<style>
body {
margin: 0;
padding: 0;
}
#map {
min-height: 500px;
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
// Don't forget to replace <YOUR_ACCESS_TOKEN> by your own access token
const accessToken = '<YOUR_ACCESS_TOKEN>';
const map = L.map('map').setView([48.7965913, 2.3210938], 3);
// List of all our defaults styles names
const styles = ['jawg-streets', 'jawg-sunny', 'jawg-terrain', 'jawg-dark', 'jawg-light'];
const baselayers = {};
// Creating one tile layers for each style
styles.forEach((style) =>
baselayers[style] = L.tileLayer(
`https://tile.jawg.io/${style}/{z}/{x}/{y}.png?access-token=${accessToken}`, {
attribution: '<a href="https://jawg.io" title="Tiles Courtesy of Jawg Maps" target="_blank" class="jawg-attrib">© <b>Jawg</b>Maps</a> | <a href="https://www.openstreetmap.org/copyright" title="OpenStreetMap is open data licensed under ODbL" target="_blank" class="osm-attrib">© OSM contributors</a>',
}
)
);
// Set the default layer when you open the map
baselayers['jawg-streets'].addTo(map);
// Associating each style name to its tile layer
L.control.layers(baselayers).addTo(map);
</script>
</body>
</html>