-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapbox-maps-api.html
More file actions
64 lines (60 loc) · 2.18 KB
/
mapbox-maps-api.html
File metadata and controls
64 lines (60 loc) · 2.18 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
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="UTF-8">
<title>Mapbox API Exercise</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>
<select name="zoom-select" id="zoom-select">
<option selected disabled>Zoom Level</option>
<option value="5">Zoom Level 5</option>
<option value="9">Zoom Level 9</option>
<option value="15">Zoom Level 15</option>
<option value="20">Zoom Level 20</option>
</select>
<h1>My First Mapbox Map!</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>
//----------------------------------------mapbox gl map-------------------------------------------------------------
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.7970, 32.7767] // [lng, lat]
});
//----------------------------------------mapbox gl marker--------------------------------------------------------------
//setting a marker object
let marker = new mapboxgl.Marker()
//setting marker object location
.setLngLat([-96.8021422, 32.7779628])
//adding marker to map
.addTo(map)
//----------------------------------------mapbox gl popup-----------------------------------------------------------
let popup = new mapboxgl.Popup()
.setLngLat([-96.8021422,32.7779628])
.setHTML("<h1>Mcdonalds!</p>")
marker.setPopup(popup)
// ------------------------------------------mapbox gl geocoder-------------------------------------------------------
let currentLocation = geocode("Allen", MAPBOX_TOKEN);
currentLocation.then(function (results){
console.log(results)
})
</script>
</body>
</html>