-
Notifications
You must be signed in to change notification settings - Fork 39
/
index.html
113 lines (97 loc) · 3.1 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE html>
<html>
<head>
<title>Leaflet.MakiMarkers Example</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link
rel="stylesheet"
href="https://unpkg.com/[email protected]/dist/leaflet.css"
/>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="Leaflet.MakiMarkers.js"></script>
</head>
<body>
<form id="tokenForm" style="padding-bottom:40px;">
<p>Enter your Mapbox access token in order to use Maki icons.</p>
<p>
Get the access token from
<a href="https://account.mapbox.com">your Mapbox Account</a>.
</p>
<label for="accessToken">Access Token: </label>
<input
type="text"
id="accessToken"
name="accessToken"
placeholder="pk.123..."
required
/>
<button type="submit">Show the map!</button>
</form>
<div id="map" style="width: 600px; height: 400px"></div>
<script>
const $form = document.getElementById("tokenForm");
let map;
$form.onsubmit = function(e) {
e.preventDefault();
const accessToken = document.getElementById("accessToken").value;
showMap(accessToken);
};
function showMap(accessToken) {
L.MakiMarkers.accessToken = accessToken;
if (map) { map.remove(); }
map = L.map("map").setView([30.289, -97.74], 12);
L.tileLayer(
"https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png",
{
maxZoom: 18,
attribution:
"Map tiles by Carto, under CC BY 3.0. Data by OpenStreetMap, under ODbL."
}
).addTo(map);
const rocketIcon = L.MakiMarkers.icon({
icon: "rocket",
color: "#b0b",
size: "m"
});
L.marker([30.287, -97.72], { icon: rocketIcon })
.addTo(map)
.bindPopup("<strong>Medium Rocket!</strong>");
const beerIcon = L.MakiMarkers.icon({
icon: "beer",
color: "#12a",
size: "l"
});
L.marker([30.31096, -97.74277], { icon: beerIcon })
.addTo(map)
.bindPopup("<strong>Large Beer!</strong>");
const warehouseIcon = L.MakiMarkers.icon({
icon: "warehouse",
color: "#0a0",
size: "s"
});
L.marker([30.26672, -97.74541], { icon: warehouseIcon })
.addTo(map)
.bindPopup("<strong>Small Warehouse!</strong>");
const noIconMarker = L.MakiMarkers.icon({
icon: null,
color: "#b00"
});
L.marker([30.308064585977814, -97.79387256712653], {
icon: noIconMarker
})
.addTo(map)
.bindPopup("<strong>No Icon!</strong>");
const noColorMarker = L.MakiMarkers.icon({
icon: null,
color: null
});
L.marker([30.25173261265964, -97.69636890501715], {
icon: noColorMarker
})
.addTo(map)
.bindPopup("<strong>No Color!</strong>");
}
</script>
</body>
</html>