-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
106 lines (99 loc) · 4.9 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>PDX Traffic</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src='https://api.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.js'></script>
<link href='https://api.mapbox.com/mapbox-gl-js/v2.14.1/mapbox-gl.css' rel='stylesheet' />
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@500&display=swap" rel="stylesheet">
<link rel="stylesheet" href="main.css" />
<link rel="stylesheet" href="./styles/cams.css" />
</head>
<body>
<div id="map"></div>
<div id="main">
<h2>Mapbox Nav API Demos</h2>
<p class="txt">Mapbox is a geodata platform of global sources powering Maps, Search, and Navigation APIs.
This is an unofficial collection of navigation demos. Get your token
<a href="https://studio.mapbox.com/">here</a>.</p>
<ul class="txt">
<h2>Directions</h2>
<p>Get fast and efficient ETAs with turn-by-turn directions.</p>
<li><a href="./directions/">Directions (plugin)</a></li>
<li><a href="./directions/custom.html">Directions (custom)</a></li>
<li><a href="./directions/draw-directions.html">Draw Directions (custom)</a></li>
<h2>Map Matching</h2>
<p>Snap messy GPS locations to the nearest routable network and get turn-by-turn directions.</p>
<li><a href="./map-matching/">Match a drawn line to the map</a></li>
<li><a href="./map-matching/match-coordinates.html">Map-match a list of coordinates</a></li>
<h2>Isochrones</h2>
<p>Get travel times and distances from a location displayed as contours.</p>
<li><a href="./isochrone/">How far can you travel in 15 min? 🚴♂️</a></li>
<h2>Optimization</h2>
<p>Solve the traveling salesperson problem.</p>
<li><a href="./optimization/">Traveling Sales Person Problem</a></li>
<li><a href="./optimization/optimize-coordinates.html">Optimize a route with a set of coordinates</a></li>
<li><a href="./optimization/ride.html">Generate Optimized Cycle Route with Random Points</a></li>
<li><a href="https://geografa.github.io/mowsf/">Calculate optimal delivery route</a></li>
<h2>Matrix</h2>
<p>Find travel times from origin(s) to destination(s)</p>
<li><a href="./matrix/two-points.html">Calc travel times between two points (Matrix API)</a></li>
<li><a href="./matrix/two-points-with-directions.html">Calc travel times between two points with a route (Matrix and Directions API)</a></li>
<li><a href="./matrix/eta-to-marker.html">Get ETAs to central location (Matrix API)</a></li>
</ul>
</div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoiZ3JhZmEiLCJhIjoiY2pxbjFhMTg1MDJ2MzQ0bXJpZ2c5NjM3eCJ9.XDmc8knZy11F1omDy_P22w';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/grafa/ck5ediqej18c81ioj4jrgw8su',
center: [-122.67143949070442,45.54722707150694],
zoom: 11,
minZoom: 10
});
// Create a popup, but don't add it to the map yet.
var popup = new mapboxgl.Popup({
closeButton: false,
closeOnClick: false
});
// When a click event occurs on a feature in the states layer,
// open a popup at the location of the click, with description
// HTML from the click event's properties.
map.on('click', 'cctvinventory', (e) => {
getMatrix(e);
popup.setLngLat(e.lngLat)
// .setHTML(e.features[0].properties["cctv-url"])
.setHTML('<img src=" '+ e.features[0].properties["cctv-url"] + '" /><br><h2>' + eta + ' min to PDX ✈</h2>')
.addTo(map);
});
getMatrix = (e) => {
const url = 'https://api.mapbox.com/directions-matrix/v1/mapbox/driving-traffic/' + e.lngLat.lng +','+ e.lngLat.lat + ';-122.58458586634072,45.58556897518142?sources=0&destinations=all&access_token=pk.eyJ1IjoiZ3JhZmEiLCJhIjoiY2pxbjFhMTg1MDJ2MzQ0bXJpZ2c5NjM3eCJ9.XDmc8knZy11F1omDy_P22w';
var req = new XMLHttpRequest();
req.responseType = 'json';
req.open('GET', url, true);
req.onload = function() {
var jsonResponse = req.response;
// do something with jsonResponse
var eta = Math.ceil(jsonResponse.durations[0][1]/60);
document.getElementById('pop').innerHTML = '<img src=" '+ fe.features[0].properties["cctv-url"] + '" /><br><h2>' +
eta + ' min to PDX ✈</h2>';
req.send();
};
}
// // Change the cursor to a pointer when
// // the mouse is over the states layer.
map.on('mouseenter', 'cctvinventory', () => {
map.getCanvas().style.cursor = 'pointer';
});
// // Change the cursor back to a pointer
// // when it leaves the states layer.
map.on('mouseleave', 'cctvinventory', () => {
map.getCanvas().style.cursor = '';
});
</script>
</body>
</html>