-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapbox.html
247 lines (201 loc) · 7.59 KB
/
mapbox.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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' /> <!-- Encoding -->
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.44.2/mapbox-gl.js'></script> <!-- Source: Mapbox GL JS -->
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.44.2/mapbox-gl.css' rel='stylesheet' /> <!-- Source: Add Mapbox CSS -->
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<script src='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v2.2.0/mapbox-gl-geocoder.min.js'></script>
<link rel='stylesheet' href='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v2.2.0/mapbox-gl-geocoder.css' type='text/css' />
<style>
.geocoder {
position:absolute;
z-index:1;
width:50%;
left:50%;
margin-left:-25%;
top:20px;
}
.mapboxgl-ctrl-geocoder { min-width:100%; }
</style>
<style> <!-- Popup Style -->
/* Marker tweaks */
.mapboxgl-popup-close-button {
display: none;
}
.mapboxgl-popup-content {
font: 400 15px/18px 'Source Sans Pro', 'Helvetica Neue', Sans-serif;
padding: 0;
width: 180px;
}
.mapboxgl-popup-content-wrapper {
padding: 1%;
}
.mapboxgl-popup-content h3 {
background: #717171;
color: #fff;
margin: 0;
display: block;
padding: 10px;
border-radius: 3px 3px 0 0;
font-weight: 700;
margin-top: -15px;
}
.mapboxgl-popup-content h4 {
margin: 0;
display: block;
padding: 10px;
font-weight: 400;
}
.mapboxgl-popup-content div {
padding: 10px;
}
.mapboxgl-container .leaflet-marker-icon {
cursor: pointer;
}
.mapboxgl-popup-anchor-top > .mapboxgl-popup-content {
margin-top: 15px;
}
.mapboxgl-popup-anchor-top > .mapboxgl-popup-tip {
border-bottom-color: #91c949;
}
</style>
<style>
.legend {
background: rgba(255, 255, 255, 0.5);
border-radius: 3px;
border-style: solid;
border-width: 5px;
border-color: #1da1ab;
bottom: 30px;
box-shadow: 0 1px 2px rgba(0,0,0,0.10);
font: 12px/20px 'Helvetica Neue', Arial, Helvetica, sans-serif;
padding: 10px;
position: absolute;
right: 10px;
z-index: 1;
opacity = 0.5;
}
.legend h3 {
background: #808080;
color: #fff;
margin: +10px;
display: block;
padding: 10px;
width: 140px;
border-radius: 3px 3px 0 0;
font-size: large;
margin-top: -10px;
margin-right:-10px;
margin-left:-10px;
padding-left:5em;
}
.legend div span {
display:block;
float:left;
height:15px;
width:100%;
text-align:center;
font-size:12px;
background: rgba(255, 255, 255, 0.5);
}
</style>
<style>
#title {
position: absolute;
box-shadow: 0 1px 2px rgba(0,0,0,0.10);
border-radius: 3px;
opacity: 1;
top: 15px;
left: 20px;
width: 350px;
overflow: auto;
background: rgba(255, 255, 255, 0.5);
border-radius: 3px;
border-style: solid;
border-width: 5px;
border-color: #1da1ab;
font-family: "Arial";
padding-left: 20px;
padding-right: 20px;
padding-bottom: 15px;
border-radius: 3px;
}
</style>
<div id='state-legend' class='legend'>
<h3>Map Key</h3>
<div><span style='background: rgba(165, 0, 38, 0.7)'><b>Most Deprived Decile<b/></span></div>
<div><span style='background: rgba(215, 48, 39, 0.7)'><b>2nd<b/></span></div>
<div><span style='background: rgba(244, 109, 67, 0.7)'><b>3rd<b/></span></div>
<div><span style='background: rgba(253, 174, 97, 0.7)'><b>4th<b/></span></div>
<div><span style='background: rgba(254, 224, 139, 0.7)'><b>5th<b/></span></div>
<div><span style='background: rgba(217, 239, 139, 0.7)'>6th<b/></span></div>
<div><span style='background: rgba(166, 217, 106, 0.7)'><b>7th<b/></span></div>
<div><span style='background: rgba(102, 189, 99, 0.7)'><b>8th<b/></span></div>
<div><span style='background: rgba(26, 152, 80, 0.7)'><b>9th<b/></span></div>
<div><span style='background: rgba(0, 104, 55, 0.7)'><b>Least Deprived Decile<b/></span></div>
<small>Source: <a href="https://data.cdrc.ac.uk/dataset/cdrc-english-indices-of-deprivation-2015-geodata-pack-liverpool-e08000012">Consumer Data Research Centre</a></small>
</div>
<!-- Map ID -->
<div id='map'></div>
<!-- Geocoder ID -->
<div id='geocoder' class='geocoder'></div>
<div id='title'>
<h2>Deprivation in Liverpool (2015)</h2>
<small>Liverpool is the third most deprived town in England <a href="https://www.ons.gov.uk/releases/townsandcitiesanalysis">(ONS 2015)</a>. This interactive choropleth of IMD Rank <a href="https://data.cdrc.ac.uk/dataset/cdrc-english-indices-of-deprivation-2015-geodata-pack-liverpool-e08000012">(Indices of Multiple Deprivation 2015)</a> to visualise the distribution of deprivation in Liverpool. Additionally total crime count for 2015 was obtained using an <a href="https://data.police.uk/docs/">API</a> and average house prices was aggregated at the LSOA level. </small>
<div id="tooltip-name"></div>
<div id='tooltip'></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1IjoidGFzdGF0aGFtMSIsImEiOiJjamZ1ejY2bmYxNHZnMnhxbjEydW9sM29hIn0.w9ndNH49d91aeyvxSjKQqg'; //public access token
// Set bounds to Liverpool
var bounds = [
[-3.237485, 53.220836], // Southwest coordinates
[-2.633053, 53.543151]] // Northeast coordinates
var map = new mapboxgl.Map({
container: 'map', //type of container
style: 'mapbox://styles/tastatham1/cjg3vyld813id2spdnhy4sf9u', //user generated style from Mapbox
center: [-2.981979, 53.406315], // Set Zoom centre point
zoom: 10.9, // Sets automatic zoom
minZoom: 10.9, // Sets min zoom
maxZoom: 15, // Sets max zoom
maxBounds: bounds // Sets bounds as max
});
map.addControl(new mapboxgl.NavigationControl({ //Add navigation control - North Arrow
position: 'top-right' // position of navigation top-right
}));
map.addControl(new mapboxgl.FullscreenControl()); //Add full screen mode
map.addControl(new mapboxgl.ScaleControl({ //Add scale bar
maxWidth: 300,
unit: 'imperial'
}));
var geocoder = new MapboxGeocoder({ //Define Geocoder
accessToken: mapboxgl.accessToken,
bbox: [-3.237485, 53.220836, -2.633053, 53.543151] //// limit results to the geographic bounds
});
document.getElementById('geocoder').appendChild(geocoder.onAdd(map)); //Add Geocoder on top of map
map.on('load', function () {
// When a click event occurs on a feature in the imddata layer, open p
map.on('click', 'imd1', function (e) {
new mapboxgl.Popup()
.setLngLat(e.lngLat)
.setHTML("<h3><b>IMD Rank:</b> "+e.features[0].properties.imd_rank + "</h3><h4><b>IMD Score:</b> "+e.features[0].properties.imd_score + "</h4><h4><b>Education:</b> "+e.features[0].properties.education + "</h4><h4><b>Income:</b> "+e.features[0].properties.income + "</h4><h4><b>Crime Count:</b> "+e.features[0].properties.Crime + "</h4><h4><b>House Price:</b> £"+e.features[0].properties.Sale_Price + "</h4>")
.addTo(map);
});
// Change the cursor to a pointer when the mouse is over the states layer.
map.on('mouseenter', 'im1', function () {
map.getCanvas().style.cursor = 'pointer';
});
// Change it back to a pointer when it leaves.
map.on('mouseleave', 'imd1', function () {
map.getCanvas().style.cursor = '';
});
});
</script>
</body>
</html>