-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapbox_maps_api.html
More file actions
65 lines (56 loc) · 2.4 KB
/
mapbox_maps_api.html
File metadata and controls
65 lines (56 loc) · 2.4 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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Mapbox Exercises</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9" crossorigin="anonymous">
<link href='https://api.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.css' rel='stylesheet'/>
<style>
#map {
width: 100%;
height: 75vh;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-HwwvtgBNo3bZJJLYd8oVXjrBZt8cqVSpeBNS5n7C8IVInixGAoxmnlMuBnhbgrkm" crossorigin="anonymous"></script>
<script src='https://api.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.js'></script>
<script src="js/mapbox-geocoder-utils.js"></script>
<script src="js/keys.js"></script>
<script>
mapboxgl.accessToken = mapboxApiToken;
const map = new mapboxgl.Map({
container: 'map', // container ID
style: 'mapbox://styles/mapbox/outdoors-v12', // style URL
center: [-98.4946, 29.4252,], // starting position [lng, lat]
zoom: (10) // starting zoom
});
//bonus- adds zoom nav buttons on the top rigt corner of the map
map.addControl(new mapboxgl.NavigationControl());
let objectArray = [
{address: "11330 Potranco Rd Unit 10", name: "<p>Dr. Banh Mi</p>"},
{address: "5700 Wurzbach Rd", name: "<p>Sari-Sari</p>"},
{address: "5638 W Hausman Rd", name: "<p>Sapporo sushi & Asian Fusion</p>"}
]
function placeMarkerAndPopup(restaraunt, token, map) {
geocode(restaraunt.address, token).then(function (coordinates) {
let popup = new mapboxgl.Popup()
.setHTML("<h2>" + restaraunt.name + "</h2>"
+ "<p>"+ restaraunt.address +"</p>");
let marker = new mapboxgl.Marker()
.setLngLat(coordinates)
.addTo(map)
.setPopup(popup);
// popup.addTo(map);
})
}
objectArray.forEach(function (restaraunt) {
placeMarkerAndPopup(restaraunt, mapboxApiToken, map)
})
</script>
</body>
</html>