-
Notifications
You must be signed in to change notification settings - Fork 0
/
customize.js
140 lines (110 loc) · 3.38 KB
/
customize.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
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
var mapboxAccessToken = 'sk.eyJ1IjoicmVtb2NvZGUiLCJhIjoiY2l0MWJxeHVvMHBtOTJ5cGdyZmZpNWJkMSJ9.2eNgaP8442q_ZdWNXH5UkQ';
//var map = L.map('map').setView([37.8, -96], 4);
var map = L.map( 'map', {
center: [-37.8, 145.0],
minZoom: 2,
zoom: 11,
zoomControl: false
});
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=' + mapboxAccessToken, {
maxZoom: 18,
attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, ' +
'Imagery © <a href="http://mapbox.com">Mapbox</a>',
id: 'mapbox.light'
}).addTo(map);
// control that shows state info on hover
var info = L.control();
info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info');
this.update();
return this._div;
};
info.update = function (props) {
this._div.innerHTML = '<h4>Victoria Local Government Areas (LGA) Profile</h4>' + (props ?
'<b>' + props.lga + '</b>'
+ '<br />Popular Town: ' + props.pop_town
+ '<br />Crime Rank: ' + props.crime_rank
+ '<br />Safety Rank: ' + props.safe_rank
+ '<br />House Price Rank: ' + props.house_price_rank
+ '<br />Median House Price: $' + props.house_price
: 'Hover over a LGA');
};
info.addTo(map);
// get color depending on crime value
function getColor(d) {
return d > 180 ? '#800026' :
d > 150 ? '#BD0026' :
d > 120 ? '#E31A1C' :
d > 90 ? '#FC4E2A' :
d > 60 ? '#FD8D3C' :
d > 30 ? '#FEB24C' :
d > 0 ? '#FED976' :
'#FFEDA0';
}
function style(feature) {
return {
weight: 2,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.7,
fillColor: getColor(feature.properties.crime)
};
}
function highlightFeature(e) {
var layer = e.target;
layer.setStyle({
weight: 5,
color: '#666',
dashArray: '',
fillOpacity: 0.7
});
if (!L.Browser.ie && !L.Browser.opera && !L.Browser.edge) {
layer.bringToFront();
}
info.update(layer.feature.properties);
}
var geojson;
function resetHighlight(e) {
geojson.resetStyle(e.target);
info.update();
}
function zoomToFeature(e) {
map.fitBounds(e.target.getBounds());
}
function onEachFeature(feature, layer) {
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight,
click: zoomToFeature
});
}
geojson = L.geoJson(statesData, {
style: style,
onEachFeature: onEachFeature
}).addTo(map);
//map.attributionControl.addAttribution('Population data © <a href="http://census.gov/">US Census Bureau</a>');
var legend = L.control({position: 'bottomright'});
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend'),
grades = [0, 30, 60, 90, 120, 150, 180, 210],
labels = [],
from, to;
labels.push('Crime cases / 1K');
for (var i = 0; i < grades.length; i++) {
from = grades[i];
to = grades[i + 1];
labels.push(
'<i style="background:' + getColor(from + 1) + '"></i> ' +
from + (to ? '–' + to : '+'));
}
div.innerHTML = labels.join('<br>');
return div;
};
legend.addTo(map);
var lc = L.control.locate({
position: 'topleft',
strings: {
title: "Show me where I am, yo!"
}
}).addTo(map);