-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapbox_maps_api.html
More file actions
155 lines (121 loc) · 4.41 KB
/
Copy pathmapbox_maps_api.html
File metadata and controls
155 lines (121 loc) · 4.41 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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Mapbox Map</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<!-- include mapbox css link-->
<!-- <link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.53.0/mapbox-gl.css' rel='stylesheet' />-->
<link href='https://api.mapbox.com/mapbox-gl-js/v2.12.0/mapbox-gl.css' rel='stylesheet'/>
<link href="css/bootstrap-grid.css" rel="stylesheet">
<style>
#my-map {
width: 100%;
height: 400px;
}
</style>
</head>
<body>
<div class="container-fluid">
<!-- <div class="form-group">-->
<!-- <label for="address-input" class="form-label">Enter an address</label>-->
<!-- <input id="address-input" class="form-input" type="text">-->
<!-- </div>-->
<!--make a container in which to show the map-->
<div id="my-map">
</div>
<div class="row justify-content-center">
<div class="col-6">
<select id="zoom" class="form-select" aria-label="Default select example">
<option selected>5</option>
<option>15</option>
<option>20</option>
</select>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.3.js" integrity="sha256-nQLuAZGRRcILA+6dMBOvcRh5Pe310sBpanc6+QBmyVM=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<!--include mapbox js -->
<!--<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.53.0/mapbox-gl.js'></script>-->
<script src='https://api.mapbox.com/mapbox-gl-js/v2.12.0/mapbox-gl.js'></script>
<!--include my keys!!!-->
<script src="js/keys.js"></script>
<!--include geocoding library-->
<script src="js/mapbox-geocoder-utils.js"></script>
<script>
$(document).ready(function() {
mapboxgl.accessToken = MAPBOX_API_KEY;
const restaurants = [];
let dynamicZoom = 5;
const map = new mapboxgl.Map({
container: "my-map",
style: "mapbox://styles/mapbox/satellite-streets-v12",
zoom: 5,
center: [-98.4946, 29.4252]
});
function pinThatAddress(address, name, description, pic) {
geocode(address, MAPBOX_API_KEY).then(function(result) {
const marker = new mapboxgl.Marker();
marker.setLngLat(result);
marker.addTo(map);
const popup = new mapboxgl.Popup();
popup.setHTML(`
<div class="card" style="width: 100%;">
<img src=${pic} class="card-img-top" alt="location">
<div class="card-body">
<h5 class="card-title">${name}</h5>
<p class="card-text">
${address}
</p>
<p class="card-text" style="color: cornflowerblue">
${description}
</p>
</div>
</div>
`);
marker.setPopup(popup);
}).catch(function(error) {
console.log("Boom");
});
for (const restaurant of restaurants) {
restaurants.push({
name: name,
address: address
});
}
}
pinThatAddress(
"602 Northwest Loop 410 #126, San Antonio, TX 78216",
"SP Cafe",
"Usual Order: Lg Wonton Soup w/ Thai Boba Tea",
"img/mapbox/spcafe.jpeg"
);
pinThatAddress(
"2524 N Main Ave, San Antonio, TX 78212",
"Capparelli's",
"Usual Order: Md Italian Wedding Soup w/ soft drink",
"img/mapbox/capparellis.jpeg"
);
pinThatAddress(
"902 NE Interstate 410 Loop, San Antonio, TX 78209\n",
"Magic Time Machine",
"Usual Order: Beeebabababadabop",
"img/mapbox/magic_time_machine.jpeg"
);
// reverse geocode method from mapbox-geocoder-utils.js
// reverseGeocode({lng: -98.393114, lat: 29.507893}, MAPBOX_API_KEY).then(function(results) {
// // logs the address for The Alamo
// console.log(results);
// });
// marker = new mapboxgl.Marker();
// marker.setLngLat([-98.4960, 29.5185]);
// marker.addTo(map);
//
// const popup = new mapboxgl.Popup();
// popup.setHTML("<h3>North Start Mall</h3>");
// marker.setPopup(popup);
});
</script>
</body>
</html>