-
Notifications
You must be signed in to change notification settings - Fork 0
/
index_backup.html
110 lines (99 loc) · 3.34 KB
/
index_backup.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
107
108
109
110
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>SF Parks</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.11.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.11.0/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoianN0cmF0bWFuIiwiYSI6IlpVUTZSXzgifQ.hxmNOg44oouXakZyJQZX7Q';
var map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/jstratman/cienatk1p08cfsmkmkgtsjhln', //stylesheet location
center: [-122.430, 37.747], // starting position
zoom: 11 // starting zoom
});
map.on('style.load', function () {
// add geojson data as a new source
map.addSource("symbols", {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
-122.362, 37.735
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
-122.425, 37.763
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
-122.399, 37.797
]
}
}
]
}
});
// add source as a layer and apply some styles
map.addLayer({
"id": "symbols",
"interactive": true,
"type": "symbol",
"source": "symbols",
"layout": {
"icon-image": "default_marker"
},
"paint": {}
});
});
map.on('click', function (e) {
// Use featresAt to get features within a given radius of the click event
// Use layer option to avoid getting results from other layers
map.featuresAt(e.point, {layer: 'symbols', radius: 10, includeGeometry: true}, function (err, features) {
if (err) throw err;
// if there are features within the given radius of the click event,
// fly to the location of the click event
if (features.length) {
// Get coordinates from the symbol and center the map on those coordinates
map.flyTo({center: features[0].geometry.coordinates});
}
});
});
// Use the same approach as above to indicate that the symbols are clickable
// by changing the cursor style to 'pointer'.
map.on('mousemove', function (e) {
map.featuresAt(e.point, {layer: 'symbols', radius: 10}, function (err, features) {
if (err) throw err;
map.getCanvas().style.cursor = features.length ? "pointer" : "";
});
});
</script>
</body>
</html>