forked from amitkaps/weed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.html
163 lines (106 loc) · 4.04 KB
/
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
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
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js" charset="utf-8"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/queue-async/1.0.7/queue.min.js"></script>
<style>
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.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: 100%; height: 100%"></div>
<script>
queue()
.defer(d3.json, 'data.json')
.defer(d3.json, 'data/us-states.json')
.await(makeMap)
function onEachFeature(feature, layer) {
// does this feature have a property named popupContent?
if (feature.properties && feature.properties.popupContent) {
layer.bindPopup(feature.properties.popupContent);
}
};
function makeMap(error, data_1,gjson_1) {
function matchKey(datapoint, key_variable){
if (typeof key_variable[0][datapoint] === 'undefined') {
return null;
}
else {
return parseFloat(key_variable[0][datapoint]);
};
};
var color = d3.scale.threshold()
.domain([600000.0, 4000000.0, 7000000.0, 10000000.0, 10000000.0])
.range(['#EDF8FB', '#BFD3E6', '#9EBCDA', '#8C96C6', '#8C6BB1', '#88419D']);
var map = L.map('map').setView([48, -102], 3);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 18,
minZoom: 1,
attribution: 'Map data (c) <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
}).addTo(map);
function style_1(feature) {
return {
fillColor: color(matchKey(feature.id, data_1)),
weight: 1,
opacity: 1,
color: 'black',
fillOpacity: 0.6
};
}
gJson_layer_1 = L.geoJson(gjson_1, {style: style_1,onEachFeature: onEachFeature}).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, 11000000])
.range([0, 400]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("top")
.tickSize(1)
.tickValues([600000.0, 4000000.0, 7000000.0, 10000000.0, 10000000.0]);
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('total_population');
};
</script>
</body>