-
Notifications
You must be signed in to change notification settings - Fork 66
/
ward_map.html
134 lines (87 loc) · 3.04 KB
/
ward_map.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
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.5/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.5/leaflet.js"></script>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="http://d3js.org/queue.v1.min.js"></script>
<style>
.legend {
padding: 0px 0px;
font: 10px sans-serif;
background: white;
background: rgba(255,255,255,0.8);
box-shadow: 0 0 15px rgba(0,0,0,0.2);
border-radius: 5px;
}
.key path {
display: none;
}
</style>
</head>
<body>
<div id="map" style="width: 960px; height: 500px"></div>
<script>
queue()
.defer(d3.json, 'data/data.json')
.defer(d3.json, 'data/wards.geojson')
.await(makeMap)
function makeMap(error, data_1,gjson_1) {
function matchKey(datapoint, key_variable){
return(parseFloat(key_variable[0][datapoint]));
};
var color = d3.scale.threshold()
.domain([0.082715907469937747, 0.19630946375513353, 0.54354553836381736, 1.2741887593292438, 5.1079713241686795, 15.39304728160239])
.range(['#EDF8FB', '#BFD3E6', '#9EBCDA', '#8C96C6', '#8C6BB1', '#88419D', '#6E016B']);
var map = L.map('map').setView([51.5, 0.0], 10);
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data (c) <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
}).addTo(map);
function style_1(feature) {
return {
fillColor: color(matchKey(feature.properties.NAME, data_1)),
weight: 1,
opacity: 0.2,
color: 'black',
fillOpacity: 0.75
};
}
gJson_layer_1 = L.geoJson(gjson_1, {style: style_1}).addTo(map)
var legend = L.control({position: 'topright'});
legend.onAdd = function (map) {var div = L.DomUtil.create('div', 'legend'); return div};
legend.addTo(map);
var x = d3.scale.linear()
.domain([0, 16])
.range([0, 400]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("top")
.tickSize(1)
.tickValues(color.domain())
var svg = d3.select(".legend.leaflet-control").append("svg")
.attr("id", 'legend')
.attr("width", 450)
.attr("height", 40);
var g = svg.append("g")
.attr("class", "key")
.attr("transform", "translate(25,16)");
g.selectAll("rect")
.data(color.range().map(function(d, i) {
return {
x0: i ? x(color.domain()[i - 1]) : x.range()[0],
x1: i < color.domain().length ? x(color.domain()[i]) : x.range()[1],
z: d
};
}))
.enter().append("rect")
.attr("height", 10)
.attr("x", function(d) { return d.x0; })
.attr("width", function(d) { return d.x1 - d.x0; })
.style("fill", function(d) { return d.z; });
g.call(xAxis).append("text")
.attr("class", "caption")
.attr("y", 21)
.text('Density (km2)');
};
</script>
</body>