-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapbox-lec.html
More file actions
97 lines (88 loc) · 2.72 KB
/
mapbox-lec.html
File metadata and controls
97 lines (88 loc) · 2.72 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>First Mapbox Map</title>
<!-- Mapbox CSS -->
<link href='https://api.mapbox.com/mapbox-gl-js/v2.10.0/mapbox-gl.css' rel='stylesheet' />
<style>
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
#map {
width: 50%;
height: 500px;
margin: 20px auto;
}
</style>
</head>
<body>
<header>
<h1>Mapbox Exercises</h1>
</header>
<!-- The HTML element that serves as the Mapbox container -->
<div id='map'></div>
<script src="js/keys.js"></script>
<script src="js/mapbox-geocoder-utils.js"></script>
<!-- Mapbox JS -->
<script src='https://api.mapbox.com/mapbox-gl-js/v2.10.0/mapbox-gl.js'></script>
<!-- Custom JS -->
<script>
// mapboxgl.accessToken = MAPBOX_API;
// const map = new mapboxgl.Map({
// container: 'map', // container ID
// style: 'mapbox://styles/mapbox/satellite-streets-v12', // style URL
// zoom: 10, // starting zoom
// center: [-98.4916, 29.4252] // [lng, lat]
// });
// const marker = new mapboxgl.Marker()
// .setLngLat([-98.4916, 29.4260])
// .addTo(map);
//setting a popup object
// let popup = new mapboxgl.Popup()
// .setLngLat([-98.489615, 29.426827])
// .setHTML("<p>Codeup Rocks!</p>")
// .addTo(map);
// const codeupPopup = new mapboxgl.Popup()
// .setHTML("<p>Welcome to San Antonio!</p>");
//
// marker.setPopup(codeupPopup);
// geocode("900 Jackson St UNIT 410, Dallas, TX 75202", MAPBOX_API).then( result => {
// console.log(result);
// map.setCenter(result);
// map.setZoom(20);
// });
//
// reverseGeocode({lng: -98.4816, lat:29.4260}, MAPBOX_API).then( result => {
// console.log(result);
// })
const ACCESS_TOKEN = MAPBOX_API;
mapboxgl.accessToken = ACCESS_TOKEN;
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v9',
zoom: 10,
center: [-98.4916, 29.4252]
});
const alamoInfo = {
address: "The Alamo, San Antonio",
popupHTML: "<p>Welcome to the Alamo!</p>"
};
function placeMarkerAndPopup(info, token, map) {
geocode(info.address, token).then( coords => {
let popup = new mapboxgl.Popup()
.setHTML(info.popupHTML);
let marker = new mapboxgl.Marker()
.setLngLat(coords)
.addTo(map)
.setPopup(popup);
popup.addTo(map);
});
}
placeMarkerAndPopup(alamoInfo, ACCESS_TOKEN, map);
</script>
</body>
</html>
http://api.openweathermap.org/geo/1.0/direct?q=${city}&limit=5&appid={API key}