-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapbox_lecture.html
More file actions
93 lines (74 loc) · 2.45 KB
/
mapbox_lecture.html
File metadata and controls
93 lines (74 loc) · 2.45 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>First Mapbox Map</title>
<!-- Mapbox CSS -->
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.53.0/mapbox-gl.css' rel='stylesheet' />
<!-- Custom CSS -->
<style>
#map {
/* the width and height may be set to any size */
width: 85%;
height: 500px;
}
</style>
</head>
<body>
<h1>My First Mapbox Map!</h1>
<!-- The HTML element that serves as the Mapbox container -->
<div id='map'></div>
<!-- Mapbox JS -->
<script src="js/keys.js"></script><!--create keys file that is hidden using gitignore file-->
<script src="js/mapbox-geocoder-utils.js"></script>
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.53.0/mapbox-gl.js'></script>
<!-- Custom JS -->
<script>
mapboxgl.accessToken = MAPBOX_TOKEN;<!--On keys js created const named mapbox-->
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v9',
zoom: 10,
center: [-96.80326437171331, 32.77779919064542]
});
var marker = new mapboxgl.Marker()
.setLngLat([-96.80326437171331, 32.77779919064542])
.addTo(map);
var popup = new mapboxgl.Popup()
.setLngLat([-96.80326437171331, 32.7777991906454289615])
.setHTML("<p>Codeup Rocks!</p>")
.addTo(map)
// var alamoPopup = new mapboxgl.Popup()
// .setHTML("<p>Web developers!</p>")
marker.setPopup(popup)
// the geocode method from mapbox-geocoder-utils.js
geocode("900 Jackson St #410, Dallas, TX 75202", MAPBOX_TOKEN).then(function(result) {
console.log(result);
map.setCenter(result);
map.setZoom(15);
});
reverseGeocode({lng: -96.80326437171331, lat: 32.7777991906454289615}, MAPBOX_TOKEN).then(function(results) {
// logs the address for Dallas Founders Square
console.log(results);
});
var accessToken = MAPBOX_TOKEN;
mapboxgl.accessToken = accessToken;
var alamoInfo = {
address: "Dallas Founder's Square",
popupHTML: "<p>Remember the Alamo!</p>"
};
function placeMarkerAndPopup(info, token, map) {
geocode(info.address, token).then(function(coordinates) {
var popup = new mapboxgl.Popup()
.setHTML(info.popupHTML);
var marker = new mapboxgl.Marker()
.setLngLat(coordinates)
.addTo(map)
.setPopup(popup);
popup.addTo(map);
});
}
placeMarkerAndPopup(alamoInfo, accessToken, map);
</script>
</body>
</html>