-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapbox-1.html
More file actions
100 lines (82 loc) · 2.64 KB
/
mapbox-1.html
File metadata and controls
100 lines (82 loc) · 2.64 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
98
99
100
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Mapbox-1</title>
<!--MapboxTags-->
<link href='https://api.mapbox.com/mapbox-gl-js/v2.2.0/mapbox-gl.css' rel='stylesheet' />
</head>
<body>
<h1>Welcome to mapbox</h1>
<div id='map' style='width: 80vw; height: 80vh; margin: auto;'></div>
<button type="button" id="sat-map">Change Style</button>
<button type="button" id="fly">Fly to DFW</button>
<input type="text" id="input">
<button type="button" id="btn">Search</button>
<!--<button type="button" id="zoomIn">Zoom In</button>-->
<!--<button type="button" id="zoomOut">Zoom Out</button>-->
<script src="js/jquery-3.6.0.min.js"></script>
<script src="js/keys.js"></script>
<script src='https://api.mapbox.com/mapbox-gl-js/v2.2.0/mapbox-gl.js'></script>
<script src="js/mapbox-geocoder-utils.js"></script>
<script>
mapboxgl.accessToken = MAPBOX_ACCESS_TOKEN;
var map = new mapboxgl.Map({
container: 'map', // container ID
style: 'mapbox://styles/mapbox/streets-v11', // style URL
center: [-97.109, 32.738], // starting position [lng, lat]
zoom: 12 // starting zoom
});
$("#sat-map").click(function(){
map.setStyle("mapbox://styles/mapbox/dark-v10");
});
function changeLocation(){
map.flyTo({
center: [-97.3435927135541, 32.73141775471965]
});
}
$("#fly").click(function(){
setTimeout(changeLocation, 3000);
})
//zoom feature
// $("#zoomIn").click(function(){
// map.setZoom(map.getZoom() + 1);
// });
// $("#zoomOut").click(function(){
// map.setZoom(map.getZoom() - 1);
// });
map.addControl(new mapboxgl.NavigationControl());
//marker 1
var marker = new mapboxgl.Marker({
draggable: true,
color: "red",
})
.setLngLat([-97.109, 32.738])
.addTo(map)
// marker.on("dragend", function(){
// console.log(marker.getLngLat());
// })
// marker2
// var favRest = new mapboxgl.Marker({
// draggable: false,
// color: "cyan",
// })
// .setLngLat([-97.3435927135541, 32.73141775471965])
// .addTo(map);
$("#btn").click(function(){
var userInput = $("#input").val();
geocode(userInput, MAPBOX_ACCESS_TOKEN).then(function(info){
console.log(info)
var newCenter = {
lng: info[0],
lat: info[1]
};
marker.setLngLat(newCenter);
popup.setHTML("<h3>" + userInput + "</h3>");
marker.setPopup(popup);
map.flyTo({center: newCenter});
});
});
</script>
</body>
</html>