-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample_map.html
More file actions
117 lines (105 loc) · 4.73 KB
/
sample_map.html
File metadata and controls
117 lines (105 loc) · 4.73 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Load data from an external GeoJSON file</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<link href="https://api.mapbox.com/mapbox-gl-js/v3.5.1/mapbox-gl.css" rel="stylesheet">
<script src="https://api.mapbox.com/mapbox-gl-js/v3.5.1/mapbox-gl.js"></script>
<style>
body { margin: 0; padding: 0; }
#map { position: absolute; top: 0; bottom: 0; width: 100%; }
</style>
<script src="https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-directions/v4.3.1/mapbox-gl-directions.js"></script>
<link rel="stylesheet" href="https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-directions/v4.3.1/mapbox-gl-directions.css" type="text/css">
</head>
<body>
<div id="map"></div>
<script src="config.js"></script>
<script>
mapboxgl.accessToken = mapboxApiKey;
const map = new mapboxgl.Map({
container: 'map', // container ID
// Choose from Mapbox's core styles, or make your own style with Mapbox Studio
// style: 'mapbox://styles/mapbox/satellite-v9', // satellite url
// style: 'mapbox://styles/mapbox/streets-v11', // basic streets
style: 'mapbox://styles/marioag/clzbybnep002n01p646zu2qpk', // modified streets
zoom: 14, // starting zoom
center: [-73.9604192, 40.8075803] // // starting center in [lng, lat]
});
map.on('style.load', () => {
map.setFog({}); // Set the default atmosphere style
});
map.addControl(
new MapboxDirections({
accessToken: mapboxgl.accessToken
}),
'top-left'
);
const jsonData = fetch('https://data.cityofnewyork.us/resource/43nn-pn8j.geojson?cuisine_description=Pizza&$limit=10000')
.then(response => response.json())
.then(data => {
// create geometry from the lat, lon properties
data.features.forEach(feature => {
feature.geometry = {
type: 'Point',
coordinates: [Number(feature.properties.longitude), Number(feature.properties.latitude)]
};
});
map.on('load', () => {
map.addSource('restaurants', {
type: 'geojson',
data: data
});
map.addLayer({
'id': 'restaurants-layer',
'type': 'circle',
'source': 'restaurants',
'paint': {
'circle-radius': 6,
'circle-stroke-width': 2,
'circle-color': [
'match',
['get', 'score'],
'1', '#00FF00',
'2', '#FFFF00',
'3', '#FFA500',
'4', '#FF0000',
/* other */ '#000000'
],
'circle-stroke-color': 'white'
}
});
console.log(map.getStyle())
map.on('click', 'restaurants-layer', (e)=> {
// console.log(e.features[0].properties);
const { dba, grade, grade_date, inspection_date, violation_code, violation_description } = e.features[0].properties;
const popupHtml = `
<h3>${dba}</h3>
<p>Grade: ${grade}</p>
<p>Grade Date: ${grade_date}</p>
<p>Inspection Date: ${inspection_date}</p>
<p>Violation Code: ${violation_code}</p>
<p>Violation Description: ${violation_description}</p>
`;
// get coordinates
// coords = e.features[0].geometry.coordinates.slice();
// request url
// const url = `https://maps.googleapis.com/maps/api/streetview?size=400x400&location=${coords[0]},${coords[1]}/&fov=80&heading=70&pitch=0&key=AIzaSyCIHVy5bmgfgUYd-3Qgzd1Tqj4D3o2pd7U`;
// fetch*(url)
// .then(response => response.blob())
// .then(blob => {
// const imageUrl = URL.createObjectURL(blob);
// console.log(imageUrl);
// });
// create the popup
new mapboxgl.Popup()
.setLngLat(e.features[0].geometry.coordinates)
.setHTML(popupHtml)
.addTo(map);
})
});
});
</script>
</body>
</html>