-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapbox_maps_api.html
More file actions
89 lines (79 loc) · 2.48 KB
/
mapbox_maps_api.html
File metadata and controls
89 lines (79 loc) · 2.48 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
<!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 Map Exercise</title>
<script src='https://api.mapbox.com/mapbox-gl-js/v1.10.0/mapbox-gl.js'></script>
<link href='https://api.mapbox.com/mapbox-gl-js/v1.10.0/mapbox-gl.css' rel='stylesheet' />
<style>
body {
margin: 0;
display: flex;
min-height: 100vh;
}
#map {
width: 1100px;
height: 600px;
margin: auto;
}
</style>
</head>
<body>
<div id='map'></div>
<script src="js/keys.js"></script>
<script src="js/mapbox-geocode-utils.js"></script>
<script>
var restaurants = [
{
name: "Ito Ramen",
address: "14395 Blanco Rd, San Antonio, TX 78216",
message: "Best Ramen!"
},
{
name: "Marco's Pizza",
address: "10919 Culebra Rd #158, San Antonio, TX 78253",
message: "Amazing Pizza!"
},
{
name: "Taco Bell",
address: "12360 Leslie Rd, Helotes, TX 78023",
message: "Fav Fast Food!"
}
];
mapboxgl.accessToken = MAPBOX_KEY;
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v9',
center: [-98.4996, 29.6052],
zoom: 14
});
// restaurants.forEach(function(restaurant) {
// var = new mapboxgl.Marker();
// geocode(restaurants.restaurant.address, mapboxKey).then(function (result) {
// console.log(result);
// map.setCenter(result);
// marker
// .setLngLat(result);
// .addTo(map);
// })
//
// var popup = new mapboxgl.Popup();
// popup.setHTML("<h1>" + restaurant.name +"</h1>")
// marker.setPopup(popup);
// });
restaurants.forEach(function(restaurant) {
geocode(restaurant.address, MAPBOX_KEY).then(function(coords) {
var popup = new mapboxgl.Popup()
.setHTML('<h3>' + restaurant.name + '</h3>' + '<p>' + restaurant.message + '</p>');
var marker = new mapboxgl.Marker()
.setLngLat(coords)
.addTo(map)
.setPopup(popup);
});
});
</script>
</body>
</html>