-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapbox-2.html
More file actions
56 lines (48 loc) · 1.87 KB
/
mapbox-2.html
File metadata and controls
56 lines (48 loc) · 1.87 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
<!--8/19/2021-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Second Mapbox Mini Exercise</title>
<link href='https://api.mapbox.com/mapbox-gl-js/v2.4.1/mapbox-gl.css' rel='stylesheet' />
<style>
#map {
width: 800px;
height: 800px;
}
</style>
</head>
<body>
<h1>Marker Coordinates: <span id="coordinates"></span></h1>
<div id="map"></div>
<script src='https://api.mapbox.com/mapbox-gl-js/v2.4.1/mapbox-gl.js'></script>
<script src="js/keys.js"></script>
<script>
"use strict";
mapboxgl.accessToken = MAPBOX_API_TOKEN;
var map = new mapboxgl.Map({
container: 'map', // container ID
style: 'mapbox://styles/mapbox/streets-v11', // style URL
center: [-77.0502, 38.8893], // starting position [lng, lat]
zoom: 10 // starting zoom
});
var memorialPopup = new mapboxgl.Popup()
.setHTML('<h1>Lincoln Memorial</h1>');
var memorialMarker = new mapboxgl.Marker({draggable: true})
.setLngLat([-77.0502, 38.8893])
.setPopup(memorialPopup)
.addTo(map);
memorialMarker.on('dragend', function() {
var markerCoordinates = memorialMarker.getLngLat();
// document.querySelector('#coordinates').innerHTML = markerCoordinates.lng;
memorialPopup.setHTML(markerCoordinates.lng);
});
</script>
</body>
</html>
<!--Instructions for this second mini exercise:-->
<!--Create an HTML file named mapbox-2.html and create a mapbox map that shows Washington D.C. with a marker on the Lincoln Memorial. Then add a popup to the Lincoln Memorial marker that contains the text "Lincoln Memorial". Bonus: when the marker is dragged and released, display the coordinates in an h1.-->
<!--geocode("1600 Pennsylvania Ave.", MAPBOX_API_TOKEN).then(function(result) {-->
<!-- map.setCenter(result);-->
<!-- map.setZoom(13);-->
<!--});-->