-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapbox_maps_api.html
More file actions
81 lines (74 loc) · 2.81 KB
/
mapbox_maps_api.html
File metadata and controls
81 lines (74 loc) · 2.81 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
<!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{
width: 100vw;
height: 100vh;
}
</style>
<title>Document</title>
</head>
<body>
<h1 class="text-center">my Mapbox Map Exercise</h1>
<h1 id="coords" style="width: inherit; "></h1>
<div id='map' class=" " ></div>
<script src="js/mapbox-geocoder-utils.js"></script>
<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>
mapboxgl.accessToken = MAPBOX_TOKEN;
const map = new mapboxgl.Map({
container: 'map', // container ID
style: 'mapbox://styles/mapbox/streets-v11', // style URL
center: [-96.7970, 32.7767], // starting position [lng, lat]
zoom: 12 //
})
var restaurants = [
{
name: 'The French Room',
address: ' Commerce St, Dallas, TX',
popupHTML: 'It\'s great!'
},
{
name: 'NOLA Brasserie',
address: ' Main St, Dallas, TX',
popupHTML: 'Too good!'
},
{
name: 'The Dock',
address: ' S Akard St, Dallas, TX ',
popupHTML: 'Awesome!'
}
];
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);
});
}
restaurants.forEach((item =>{
item.popupHTML = "<P style='color: whitesmoke; border: 1px solid silver;margin: 0; padding: 3px; background: #3B94D9; border-radius: 5px '>"+item.popupHTML+"</P>"
placeMarkerAndPopup(item, MAPBOX_TOKEN, map);
}))
</script>
</body>
</html>