-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapbox_maps_api.html
More file actions
63 lines (54 loc) · 1.83 KB
/
mapbox_maps_api.html
File metadata and controls
63 lines (54 loc) · 1.83 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Favorite Restaurant</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: 500px;
}
</style>
</head>
<body>
<h1 style="display:flex; justify-content: center">My Favorite Restaurants in Chicago</h1>
<!-- The HTML element that serves as the Mapbox container -->
<div id='map'></div>
<script src="js/keys.js"></script>
<script src="js/mapbox-geocoder-utils.js"></script>
<!-- Mapbox JS -->
<script src='https://api.mapbox.com/mapbox-gl-js/v2.10.0/mapbox-gl.js'></script>
<!-- Custom JS -->
<script>
mapboxgl.accessToken = MAPBOX_API_KEY;
// creating a new map
const map = new mapboxgl.Map({
// setting the location for my map depending on the id in my html
container: 'map', // container ID
// this is setting my mapboxgl styling
style: 'mapbox://styles/mapbox/streets-v12', // style URL
// this decides how zoomed in my map is
zoom: 12, // starting zoom
// this add the center to my map using the lng, lat
center: [-87.6298, 41.8781] // [lng, lat]
});
const locations = [
{ lngLat: [-87.6298, 41.8781], popupContent: "<p>Welcome to Giordano's!</p>" },
{ lngLat: [-87.6279646, 41.8781], popupContent: "<p>Mind Your Manners At Ed Debevic's!</p>" },
{ lngLat: [-87.62349062885487, 41.752666214105915], popupContent: "<p>Welcome to Baba's!</p>" }
];
// create markers and popups
locations.forEach(location => {
const marker = new mapboxgl.Marker()
.setLngLat(location.lngLat)
.addTo(map);
const popup = new mapboxgl.Popup()
.setHTML(location.popupContent);
marker.setPopup(popup);
})
</script>
</body>
</html>