-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapbox_maps_api.html
More file actions
81 lines (67 loc) · 1.88 KB
/
Copy pathmapbox_maps_api.html
File metadata and controls
81 lines (67 loc) · 1.88 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
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Food Map</title>
<!-- Mapbox JS -->
<script src='https://api.mapbox.com/mapbox-gl-js/v2.10.0/mapbox-gl.js'></script>
<!-- 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 Favorite Restaurants</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.js"></script>
<!-- Custom JS -->
<script>
mapboxgl.accessToken = MAPBOX_TOKEN;
let map = new mapboxgl.Map({
container: 'map', // container ID
style: 'mapbox://styles/mapbox/streets-v11', // style URL
zoom: 10, // starting zoom
center: [-96.8285, 33.0460] // [lng, lat]
});
let marker = new mapboxgl.Marker().setLngLat([-96.8285, 33.0460])
.addTo(map);
let popup = new mapboxgl.Popup()
.setLngLat([-96.8285, 33.0460]).setHTML("<p>Kona Grill</p>")
marker.setPopup(popup);
let newLocation = geocode("Kona Grill", MAPBOX_TOKEN);
let restaurants = [
{
name: "Jaxson",
location:[-96.7996, 32.7824],
type: "Beer Garden"
},
{
name: "Torcheys",
location:[-97.0965,32.7631],
type: "Taco Happy Hour"
},
{
name: "The social house",
location:[-97.0959,32.7609],
type: "great brunch"
},
]
restaurants.forEach(function(restaurants){
let popup = new mapboxgl.Popup()
.setHTML('<h3>' + restaurants.name + '</h3>' + '<p>' + restaurants.type + '</p>')
marker = new mapboxgl.Marker()
.setLngLat(restaurants.location)
.addTo(map)
.setPopup(popup);
popup.addTo(map);
})
</script>
</body>
</html>