-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapbox-lec.html
More file actions
76 lines (61 loc) · 2.18 KB
/
mapbox-lec.html
File metadata and controls
76 lines (61 loc) · 2.18 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MAPBOX - Lecture</title>
<script src='https://api.mapbox.com/mapbox-gl-js/v2.6.1/mapbox-gl.js'></script>
<link href='https://api.mapbox.com/mapbox-gl-js/v2.6.1/mapbox-gl.css' rel='stylesheet' />
</head>
<body>
<h1>Welcome to Mapbox!</h1>
<div id='map' style='width: 800px; height: 600px;'></div>
<script src="js/keys.js"></script>
<script src="js/mapbox-geocoder-utils.js"></script>
<script>
mapboxgl.accessToken = MAPBOX_KEY;
const map = new mapboxgl.Map({
container: 'map', // container ID
style: 'mapbox://styles/mapbox/streets-v11', // style URL
center: [-98.4705371,29.5311973], // starting position [lng, lat] //SAT Airport
// center: [-97.0425239, 32.8998091], // DFW Airport
zoom: 9 // starting zoom
});
// MARKERS
//Instantiate a new Marker object.
var codeup = new mapboxgl.Marker({
color: 'blue',
}).setLngLat([-98.4615,29.426827]).setDraggable(true);
codeup.addTo(map);
// fires off a function once marker has been moved on the map
codeup.on('dragend', function(){
var lng = codeup.getLngLat().lng;
var lat = codeup.getLngLat().lat;
map.setCenter([lng,lat]);
popup.setLngLat(codeup.getLngLat())
console.log(codeup.getLngLat());
})
// How to remove marker
// codeup.remove();
var alamo = new mapboxgl.Marker();
alamo.setLngLat([-98.5334885,29.4066423]);
alamo.addTo(map);
//POP-UPS
var popup = new mapboxgl.Popup()
.setLngLat(codeup.getLngLat())
// .setHTML('<img src ="img/slowbro.png">')
.addTo(map)
var mysteryPlace = new mapboxgl.Marker();
var newPlace = new mapboxgl.Marker();
reverseGeocode({lat: 32.77, lng: -96.79}, MAPBOX_KEY).then(function(results){
// var res = results.features[0].center;
// newPlace.setLngLat([res[0],res[1]]);
// newPlace.addTo(map);
})
geocode("lytle, TX, United States", MAPBOX_KEY).then(function (results) {
// console.log(results)
mysteryPlace.setLngLat([results[0],results[1]]);
mysteryPlace.addTo(map);
})
</script>
</body>
</html>