-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapbox_maps_api.html
More file actions
62 lines (55 loc) · 1.95 KB
/
mapbox_maps_api.html
File metadata and controls
62 lines (55 loc) · 1.95 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>First Mapbox Map</title>
<!-- Mapbox CSS -->
<link href='https://api.mapbox.com/mapbox-gl-js/v2.10.0/mapbox-gl.css' rel='stylesheet' />
<style>
#map {
/* the width and height may be set to any size */
width: 100%;
height: 700px;
}
</style>
</head>
<body>
<h1>My First Mapbox Map!</h1>
<!-- The HTML element that serves as the Mapbox container -->
<div id='map'></div>
<!-- Mapbox JS -->
<script src='https://api.mapbox.com/mapbox-gl-js/v2.10.0/mapbox-gl.js'></script>
<!-- Custom JS -->
<script src="js/keys.js"></script>
<script src="js/mapbox-geocoder-utils.js"></script>
<script>
mapboxgl.accessToken = MAPBOX_API_KEY;
const restaurants = [
{name: "Los Barrios", address: "4223 Blanco Rd, San Antonio, TX 78212"},
{name: "Texas Roadhouse", address: "23102 W I-10, San Antonio, TX 78257"},
{name: "Chick Fil-A", address: "3214 SE Military Dr, San Antonio, TX 78223"} ];
const map = new mapboxgl.Map({
container: 'map', // container ID
style: 'mapbox://styles/mapbox/streets-v11', // style URL
zoom: 10, // starting zoom
// center: [restLong, restLat] // [lng, lat]
});
for (let restaurant of restaurants) {
// Find location of restaurant and center map
geocode(restaurant.address, MAPBOX_API_KEY)
.then(results => {
let restLong = results[0];
let restLat = results[1];
map.setCenter([restLong, restLat]);
// Create marker at restaurant location
const marker = new mapboxgl.Marker()
.setLngLat([restLong, restLat])
.addTo(map);
const restPopup = new mapboxgl.Popup()
.setHTML(`<p>${restaurant.name}</p>`);
marker.setPopup(restPopup);
});
}
</script>
</body>
</html>