-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapbox_maps_api.html
More file actions
178 lines (163 loc) · 6.23 KB
/
Copy pathmapbox_maps_api.html
File metadata and controls
178 lines (163 loc) · 6.23 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Mapbox Exercise</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 style="text-align: center">Check Out My Old Favorite Restaurants!</h1>
<!-- <br>-->
<!-- <button id="test-button" type="button">Do something</button>-->
<!-- <br>-->
<div id='map' style='width: 800px; height: 600px; margin: auto'></div>
<br>
<div style="text-align: center">
<button id="zoom-in" type="button">Zoom In</button> <!--see zoomIn-->
<button id="zoom-out" type="button">Zoom Out</button>
<label for="zoom-input">Enter the desired zoom level: </label>
<input id="zoom-input" type="text">
<button id="zoom-submit" type="button">Submit</button>
<label for="address-input">Enter an address: </label>
<input id="address-input" type="text">
<button id="submit" type="button">Find Location</button>
<button id="remove-markers" type="button">Remove All Markers</button>
</div>
<script src="js/keys.js"></script> <!--this needs to be listed first before other scripts-->
<script src="js/mapbox-geocoder-utils.js"></script>
<script src="https://code.jquery.com/jquery-2.2.4.min.js" integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
<script>
let testVariable = 'Test Variable';
let restaurants = [
{
name: "El Burrito",
address: "422 W Southline St, Cleveland, TX 77327",
foodType: "Mexican"
},
{
name: "Little Caesars",
address: "1825 E Houston St, Cleveland, TX 77327",
foodType: "Pizza"
},
{
name: "Jack N The Box",
address: "419 S Washington Ave, Cleveland, TX 77327",
foodType: "Fast Food"
}
];
mapboxgl.accessToken = MAPBOX_KEY;
const map = new mapboxgl.Map({
container: 'map', // container ID
style: 'mapbox://styles/mapbox/streets-v11', // style URL
center: [-95.098485, 30.3429914], // starting position [lng, lat]
zoom: 12 // starting zoom
});
let marker;
let popup;
$(document).ready(function() {
function placeMarkerAndPopup(info, MAPBOX_KEY, map) {
geocode(info.address, MAPBOX_KEY).then(function(coordinates) {
popup = new mapboxgl.Popup()
.setHTML("<strong>" + info.name + "</strong>" + "<br>" + info.address + "<br>" + "<em>" + info.foodType + "</em>");
marker = new mapboxgl.Marker()
.setLngLat(coordinates)
.addTo(map)
.setPopup(popup);
// popup.addTo(map);
$(popup).click(function () {
popup.addTo(map);
});
});
}
restaurants.forEach(function (element) {
placeMarkerAndPopup(element, MAPBOX_KEY, map);
});
// function placeMarker(info, MAPBOX_KEY, map) {
// geocode(info.address, MAPBOX_KEY).then(function(coordinates) {
// marker = new mapboxgl.Marker()
// .setLngLat(coordinates)
// .addTo(map)
// marker.addTo(map);
// });
// }
//
// function placePopUp() {
// geocode(info.address, MAPBOX_KEY).then(function(coordinates) {
// popup = new mapboxgl.Popup()
// .setHTML("<strong>" + info.name + "</strong>" + "<br>" + info.address + "<br>" + "<em>" + info.foodType + "</em>");
// marker.setPopup(popup);
// });
// }
//
// //iterate through each object and add marker with info
// restaurants.forEach(function (element) {
// placeMarker(element, MAPBOX_KEY, map);
// });
//
// restaurants.forEach(function (element) {
// placePopUp(element, MAPBOX_KEY, map);
// });
//iterate through each object and add marker with info
// restaurants.forEach(function (element) {
// placeMarkerAndPopup(element, MAPBOX_KEY, map);
// });
$('#test-button').click(function () {
alert("Test button");
// restaurants.forEach(function (element) {
// placeMarkerAndPopup(element, MAPBOX_KEY, map);
// });
});
//
// let elBurrito = new mapboxgl.Marker({
// color: "red"
// }).setLngLat([-95.0990043, 30.3368053]).setDraggable(true);
//
// elBurrito.addTo(map);
//
// let elBurritoPopup = new mapboxgl.Popup()
// .setHTML('<h3>El Burrito</h3>' + testVariable + "<p>Info in a paragraph.</p>")
// elBurrito.setPopup(elBurritoPopup);
//
// let littleCaesars = new mapboxgl.Marker({
// color: "blue"
// }).setLngLat([-95.0690217, 30.339046]).setDraggable(true);
//
// littleCaesars.addTo(map);
//
// let littleCaesarsPopup = new mapboxgl.Popup()
// .setHTML('<h3>Little Caesars</h3>')
// littleCaesars.setPopup(littleCaesarsPopup);
//
// let jackNTheBox = new mapboxgl.Marker({
// color: "green"
// }).setLngLat([-95.0942338, 30.3387689]).setDraggable(true);
//
// jackNTheBox.addTo(map);
//
// let jackNTheBoxPopup = new mapboxgl.Popup()
// .setHTML('<h3>Jack N The Box</h3>')
// // .addTo(map);
// jackNTheBox.setPopup(jackNTheBoxPopup);
//Can't get these to work, come back to it
// $('#zoom-in').click(function () {
// map.zoomTo(map.getZoom() + 1);
// });
//
// $('#zoom-out').click(function () {
// map.zoomTo(map.getZoom() - 1);
// });
//
// $('#submit').click(function () {
// map.zoomTo($('#input').val());
// });
//
// $('#remove-markers').click(function () {
// elBurrito.remove();
// littleCaesars.remove();
// jackNTheBox.remove();
// });
});
</script>
</body>
</html>