-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate_map.html
185 lines (157 loc) · 4.94 KB
/
state_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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
<html>
<head>
<meta charset=utf-8 />
<title>Choropleth</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox.js/v2.0.1/mapbox.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/v2.0.1/mapbox.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<style>
.leaflet-popup-close-button {
display: none;
}
.leaflet-popup-content-wrapper {
pointer-events: none;
}
.leaflet-control {
position: relative;
z-index: 7;
pointer-events: auto;
}
.leaflet-bottom {
position: absolute;
z-index: 1000;
pointer-events: none;
}
.info {
padding: 6px 8px;
font: 14px/16px Arial, Helvetica, 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;
}
.info h4 {
margin: 0 0 5px;
color: #777;
}
</style>
<script src='state_data.js'></script>
<script src='cnty_data.js'></script>
<script>
var mapboxAccessToken = 'pk.eyJ1IjoiYW5taW5zIiwiYSI6Ik9SZ3dyMjAifQ.2KVz9-1BSP3AF_s_Sx02ig';
var map = L.map('map').setView([37.8, -96], 4);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=' + mapboxAccessToken, {
id: 'mapbox.light'
}).addTo(map);
function style(features) {
return {
fillColor: features.properties.color,
weight: 1,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.7
};
}
// 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>Most Popular Industry:</h4>' + (props ?
'<b>' + props.state_name + '</b><br />' + props.naics_description
: 'Hover over a state');
};
info.addTo(map);
// function getColor(d) {
// return
// d = 'Retail trade' ? '#8DD3C7' :
// d = 'Construction' ? '#FFFFB3' :
// d = 'Other services (except public administration)' ? '#BEBADA :
// d = 'Accommodation and food services' ? '#FB8072' :
// d = 'Health care and social assistance' ? '#80B1D3' :
// d = 'Professional, scientific, and technical services' ? '#FDB462 :
// d = 'Manufacturing' ? '#B3DE69' :
// d = 'Mining, quarrying, and oil and gas extraction' ? '#FCCDE5 :
// d = 'Finance and insurance' ? '#D9D9D9' :
// d = 'Transportation and warehousing' ? '#BC80BD' :
// d = 'Wholesale trade' ? '#CCEBC5' :
// d = 'Administrative and support and waste management and remediation services' ? '#FFED6F' :
// d = 'Real estate and rental and leasing' ? '#E41A1C' :
// d = 'Information' ? '#377EB8' :
// d = 'Industries not classified' ? '#4DAF4A' :
// d = 'Educational services' ? '#984EA3' :
// d = 'Management of companies and enterprises' ? '#FF7F00' :
// d = 'Arts, entertainment, and recreation' ? '#FFFF33' :
// d = 'Agriculture, forestry, fishing and hunting' ? '#A65628' ;
// }
function highlightFeature(e) {
var layer = e.target;
layer.setStyle({
weight: 5,
color: '#666',
dashArray: '',
fillOpacity: 0.7
});
if (!L.Browser.ie && !L.Browser.opera) {
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(stateData, {
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 = function (a, d) {
// if (a.indexOf(d.naics_description) === -1) {
// a.push(d.naics_description);
// }
// return a;
// }, [],
// labels = [];
//
// for (var i = 0; i < grades.length; i++) {
// labels.push(
// '<i style="background:' + getColor(i) + '"></i> '
// );
// }
//
// div.innerHTML = labels.join('<br>');
// return div;
// };
//
// legend.addTo(map);
</script>
</body>
</html>