-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsite.js
70 lines (62 loc) · 1.51 KB
/
site.js
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
var mapboxgl = require('mapbox-gl')
mapboxgl.accessToken = getAccessToken()
// Alternative to the `sourceTypes:` option is to do the following
// before creating the map:
//
// mapboxgl.Source.addType('topojson', require('./topojson_source'))
//
// (This can also be done after, but that requires listening for the
// 'source-type.add' event before using it.)
var map = window.map = new mapboxgl.Map({
container: 'map',
zoom: 5.2,
center: [-119.393, 36.883],
style: 'mapbox://styles/mapbox/streets-v8',
sourceTypes: {
topojson: require('./topojson_source')
}
})
map.addControl(new mapboxgl.Navigation())
map.on('load', function () {
map.addSource('counties', {
type: 'topojson',
data: 'ca.json',
workerOptions: {
layer: 'counties'
}
})
map.addLayer({
'id': 'county-boundaries',
'type': 'line',
'source': 'counties',
'paint': {
'line-color': '#EC8D8D',
'line-width': {
'base': 1.5,
'stops': [
[
5,
0.75
],
[
18,
32
]
]
}
}
}, 'country-label-lg')
})
function getAccessToken () {
var accessToken = (
getURLParameter('access_token') ||
localStorage.getItem('accessToken')
)
localStorage.setItem('accessToken', accessToken)
return accessToken
}
function getURLParameter (name) {
var regexp = new RegExp('[?&]' + name + '=([^&#]*)', 'i')
var output = regexp.exec(window.location.href)
return output && output[1]
}