-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapbox-maps-api.html
More file actions
136 lines (107 loc) · 4.43 KB
/
mapbox-maps-api.html
File metadata and controls
136 lines (107 loc) · 4.43 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
<!doctype html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<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">
<!-- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> -->
<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;
}
.mapboxgl-popup-anchor-bottom > .mapboxgl-popup-tip {
border-top-color: red !important;
}
</style>
<title>Document</title>
</head>
<body>
<h1></h1>
<div id='map'></div>
<h1 id="coords"></h1>
<!-- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script> -->
<script src="https://code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.53.0/mapbox-gl.js'></script>
<script src="js/keys.js"></script>
<script src="js/mapbox-geocoder-utils.js"></script>
<script>
// mapboxgl.accessToken = MAPBOX_TOKEN;
// var map = new mapboxgl.Map({
// container: 'map',
// style: 'mapbox://styles/mapbox/streets-v11',
// zoom: 10,
// center: [-98.4916, 29.4252]
//
// });
mapboxgl.accessToken = MAPBOX_TOKEN;
const map = new mapboxgl.Map({
container: 'map', // container ID
style: 'mapbox://styles/mapbox/streets-v11', // style URL
//reverse coordinates, add negative to first
center: [-96.77990311542614, 32.78490797329269], // starting position [lng, lat]
zoom: 5, // starting zoom
});
setTimeout(function() {
map.setCenter([-96.77990311542614, 32.78490797329269]);
map.setZoom(15);
map.setStyle('mapbox://styles/mapbox/streets-v11');
}, 3000);
// let popup = new mapboxgl.Popup()
// .setHTML("Terry Black's BBQ");
// let marker = new mapboxgl.Marker({draggable: true})
// .setLngLat([-96.77990311542614, 32.78490797329269])
// .setPopup(popup)
// .addTo(map);
// marker.on('dragend', function() {
// let coordinates = marker.getLngLat();
// console.log(coordinates);
// console.log(coordinates.lat);
// console.log(coordinates.lng);
// $('#coords').html('Latitude: ' + coordinates.lat + '<br> Longitude: ' + coordinates.lng);
// });
// var marker = new mapboxgl.Marker()
// .setLngLat([-98.4916, 29.4260])
// .addTo(map);
// geocode("Dallas, Texas", MAPBOX_TOKEN).then(function(result) {
// map.setCenter(result);
// map.setZoom(8);
// });
var restaurants = [
{
name: 'Silo',
address: 'Silo: Elevated Cuisine, San Antonio, TX',
message: 'It\'s great!',
location: [-96.7813790617483, 32.78245215132888]
},
{
name: 'Chama Gaucha Steakhouse',
address: 'Chama Gaucha Steakhouse, San Antonio, TX',
message: 'Too good!',
location: [-96.78152315708984, 32.783438084026564 ]
},
{
name: 'Tarka Indian Kitchen',
address: 'Tarka Indian Kitchen, San Antonio, TX',
message: 'Awesome!',
location: [-96.78243505118027, 32.784341025996014 ]
}
];
restaurants.forEach(function(restaurant) {
let popup = new mapboxgl.Popup({offset: 25})
.setHTML(
"<h2>" + restaurant.name + "</h2>" +
"<h4><em>" + restaurant.address + "</em></h4>" +
"<p>" + restaurant.message + "</p>");
let marker = new mapboxgl.Marker()
.setLngLat(restaurant.location)
.setPopup(popup)
.addTo(map);
})
</script>
</body>
</html>