-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapbox_maps_api.html
More file actions
66 lines (56 loc) · 2.02 KB
/
mapbox_maps_api.html
File metadata and controls
66 lines (56 loc) · 2.02 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
63
64
65
66
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Mapbox!!</title>
<script src='https://api.mapbox.com/mapbox-gl-js/v3.0.0/mapbox-gl.js'></script>
<link href='https://api.mapbox.com/mapbox-gl-js/v3.0.0/mapbox-gl.css' rel='stylesheet'/>
<link rel="stylesheet" href="css/mapbox.css">
</head>
<body>
<header>
<h1>My Mapbox Exercise</h1>
<hr>
</header>
<div id='map' style='width: 80vw; height: 50vh; margin: auto; border-radius: 15px; '></div>
<script src="js/keys.js"></script>
<script src="js/mapbox-geocoder-utils.js"></script>
<script>
mapboxgl.accessToken = MB_KEY;
const map = new mapboxgl.Map({
container: 'map', // container ID
style: 'mapbox://styles/mapbox/streets-v12', // style URL
center: [-95.7309312, 29.8173647], // starting position [lng, lat]
zoom: 8, // starting zoom
});
map.addControl(new mapboxgl.NavigationControl()); // adds a zoom controller
const favoriteRestaurant = [
{
name: "los Perez",
location: "3211 Grand Pkwy Suite 100, Katy, TX 77449",
popupContent: "This is my first favorite restaurant, Los Perez!"
},
{
name: "Torchy's Tacos",
location: "19111 Katy Fwy #100, Houston, TX 77094",
popupContent: "This is my second favorite restaurant, Torchy's Tacos!"
},
{
name: "Toasted Yolk",
location: "98 W Grand Pkwy S #100, Katy, TX 77494",
popupContent: "This is my favorite breakfast restaurant, Toasted Yolk!"
}
];
favoriteRestaurant.forEach(restaurant => {
geocode(restaurant.location, MB_KEY).then(coords => {
const marker = new mapboxgl.Marker()
.setLngLat(coords)
.addTo(map);
const popUp = new mapboxgl.Popup()
.setHTML(`<p>${restaurant.popupContent} <br> located at: ${restaurant.location}</p>`);
marker.setPopup(popUp);
});
});
</script>
</body>
</html>