-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapbox-geocoder-utils.html
More file actions
73 lines (59 loc) · 1.84 KB
/
mapbox-geocoder-utils.html
File metadata and controls
73 lines (59 loc) · 1.84 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
<!DOCTYPE html>
<html lang="en">
<head>
<!-- geocoder-->
<link rel="stylesheet" href="https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v5.0.0/mapbox-gl-geocoder.css" type="text/css">
<meta charset="UTF-8">
<title>Map Marker Example</title>
<!-- Mapbox CSS -->
<link href='https://api.mapbox.com/mapbox-gl-js/v2.10.0/mapbox-gl.css' rel='stylesheet' />
<!-- Custom CSS -->
<style>
#map {
/* the width and height may be set to any size */
width: 100%;
height: 700px;
}
</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='https://api.mapbox.com/mapbox-gl-js/v2.10.0/mapbox-gl.js'></script>
<!-- Mapbox Geocoder Util Methods -->
<script src="js/keys.js"></script>
<script src="mapbox-geocoder-utils.js"></script>
<!-- Custom JS -->
<script>
const ACCESS_TOKEN = MAPBOX_API;
mapboxgl.accessToken = ACCESS_TOKEN;
let map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v9',
zoom: 10,
center: [-96.80330059331894, 32.777946644194934]
});
const alamoInfo = {
address: "The Dallas World Aquarium, Dallas",
popupHTML: "<p>Welcome to the Alamo!</p>"
};
function placeMarkerAndPopup(info, token, map) {
geocode(info.address, token).then( coords => {
console.log(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, MAPBOX_API, map);
</script>
<!--geocoder-->
<script src="https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v5.0.0/mapbox-gl-geocoder.min.js"></script>
</body>
</html>