-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathosm.html
136 lines (89 loc) · 3.07 KB
/
osm.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
<!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>
<script src="http://d3js.org/topojson.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, 'data2.json')
.defer(d3.json, 'us_counties_20m_topo.json')
.await(makeMap)
function makeMap(error, data_1,tjson_1) {
topo_1 = topojson.feature(tjson_1, tjson_1.objects.us_counties_20m);
function matchKey(datapoint, key_variable){
return(parseFloat(key_variable[0][datapoint]));
};
var color = d3.scale.threshold()
.domain([0, 5, 7, 9, 11, 13])
.range(['#FFFFCC', '#C7E9B4', '#7FCDBB', '#41B6C4', '#1D91C0', '#225EA8', '#0C2C84']);
var map = L.map('map').setView([40, -99], 4);
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.id, data_1)),
weight: 1,
opacity: 0.3,
color: 'black',
fillOpacity: 0.6
};
}
gJson_layer_1 = L.geoJson(topo_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, 14])
.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('Unemployment Rate 2011 (%)');
};
</script>
</body>