-
Notifications
You must be signed in to change notification settings - Fork 29
/
map6.html
186 lines (159 loc) · 7.32 KB
/
map6.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
185
186
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Cell Towers in Oregon (2009)</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css"/>
<link href="https://fonts.googleapis.com/css?family=Titillium+Web" rel="stylesheet">
<style>
html, body, #map { width: 100%; height: 100%; margin: 0; background: #fff; }
.legend {
line-height: 16px;
width: 140px;
color: #333333;
font-family: 'Titillium Web', sans-serif;
padding: 6px 8px;
background: white;
background: rgba(255,255,255,0.5);
box-shadow: 0 0 15px rgba(0,0,0,0.2);
border-radius: 5px;
}
.legend i {
width: 16px;
height: 16px;
float: left;
margin-right: 8px;
opacity: 0.9;
}
.legend img {
width: 16px;
height: 16px;
margin-right: 3px;
float: left;
}
.legend p {
font-size: 12px;
line-height: 16px;
margin: 0;
}
</style>
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet-ajax/2.1.0/leaflet.ajax.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chroma-js/1.3.4/chroma.min.js"></script>
<script type="text/javascript" src="https://cloudybay.github.io/leaflet.latlng-graticule/leaflet.latlng-graticule.js"></script>
</head>
<body>
<!-- Our web map and content will go here -->
<div id="map"></div>
<script>
// 1. Create a map object.
var mymap = L.map('map', {
center: [44.13, -119.93],
zoom: 7,
maxZoom: 10,
minZoom: 3,
detectRetina: true});
// 2. Add a base map.
L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png').addTo(mymap);
// 3. Add cell towers GeoJSON Data
// Null variable that will hold cell tower data
var cellTowers = null;
// 4. build up a set of colors from colorbrewer's dark2 category
var colors = chroma.scale('Dark2').mode('lch').colors(9);
// 5. dynamically append style classes to this page. This style classes will be used for colorize the markers.
for (i = 0; i < 9; i++) {
$('head').append($("<style> .marker-color-" + (i + 1).toString() + " { color: " + colors[i] + "; font-size: 15px; text-shadow: 0 0 3px #ffffff;} </style>"));
}
// Get GeoJSON and put on it on the map when it loads
cellTowers= L.geoJson.ajax("assets/cell_towers.geojson", {
// assign a function to the onEachFeature parameter of the cellTowers object.
// Then each (point) feature will bind a popup window.
// The content of the popup window is the value of `feature.properties.company`
onEachFeature: function (feature, layer) {
layer.bindPopup(feature.properties.company);
},
pointToLayer: function (feature, latlng) {
var id = 0;
if (feature.properties.company == "New Cingular") { id = 0; }
else if (feature.properties.company == "Cellco") { id = 1; }
else if (feature.properties.company == "RCC Minnesota") { id = 2; }
else if (feature.properties.company == "Verizon") { id = 3; }
else if (feature.properties.company == "US Cellular") { id = 4; }
else if (feature.properties.company == "Hood River Cellular") { id = 5; }
else if (feature.properties.company == "Medford Cellular") { id = 6; }
else if (feature.properties.company == "Oregon RSA") { id = 7; }
else { id = 8;} // "Salem Cellular"
return L.marker(latlng, {icon: L.divIcon({className: 'fa fa-signal marker-color-' + (id + 1).toString() })});
},
attribution: 'Cell Tower Data © Map Cruzin | Oregon counties © Oregon Explorer | Base Map © CartoDB | Made By Bo Zhao'
}).addTo(mymap);
// 6. Set function for color ramp
colors = chroma.scale('OrRd').colors(5); //colors = chroma.scale('OrRd').colors(5);
function setColor(density) {
var id = 0;
if (density > 18) { id = 4; }
else if (density > 13 && density <= 18) { id = 3; }
else if (density > 10 && density <= 13) { id = 2; }
else if (density > 5 && density <= 10) { id = 1; }
else { id = 0; }
return colors[id];
}
// 7. Set style function that sets fill color.md property equal to cell tower density
function style(feature) {
return {
fillColor: setColor(feature.properties.CT_CNT),
fillOpacity: 0.4,
weight: 2,
opacity: 1,
color: '#b4b4b4',
dashArray: '4'
};
}
// 8. Add county polygons
L.geoJson.ajax("assets/counties.geojson", {
style: style
}).addTo(mymap);
// 9. Create Leaflet Control Object for Legend
var legend = L.control({position: 'topright'});
// 10. Function that runs when legend is added to map
legend.onAdd = function () {
// Create Div Element and Populate it with HTML
var div = L.DomUtil.create('div', 'legend');
div.innerHTML += '<b># Cell Tower</b><br />';
div.innerHTML += '<i style="background: ' + colors[4] + '; opacity: 0.5"></i><p>19+</p>';
div.innerHTML += '<i style="background: ' + colors[3] + '; opacity: 0.5"></i><p>14-18</p>';
div.innerHTML += '<i style="background: ' + colors[2] + '; opacity: 0.5"></i><p>11-13</p>';
div.innerHTML += '<i style="background: ' + colors[1] + '; opacity: 0.5"></i><p> 6-10</p>';
div.innerHTML += '<i style="background: ' + colors[0] + '; opacity: 0.5"></i><p> 0- 5</p>';
div.innerHTML += '<hr><b>Company<b><br />';
div.innerHTML += '<i class="fa fa-signal marker-color-1"></i><p> New Cingular</p>';
div.innerHTML += '<i class="fa fa-signal marker-color-2"></i><p> Cello</p>';
div.innerHTML += '<i class="fa fa-signal marker-color-3"></i><p> RCC Minnesota</p>';
div.innerHTML += '<i class="fa fa-signal marker-color-4"></i><p> Verizon</p>';
div.innerHTML += '<i class="fa fa-signal marker-color-5"></i><p> US Cellular</p>';
div.innerHTML += '<i class="fa fa-signal marker-color-6"></i><p> Hood River Cellular</p>';
div.innerHTML += '<i class="fa fa-signal marker-color-7"></i><p> Medford Cellular</p>';
div.innerHTML += '<i class="fa fa-signal marker-color-8"></i><p> Oregon RSA</p>';
div.innerHTML += '<i class="fa fa-signal marker-color-9"></i><p> Salem Cellular</p>';
// Return the Legend div containing the HTML content
return div;
};
// 11. Add a legend to map
legend.addTo(mymap);
// 12. Add a scale bar to map
L.control.scale({position: 'bottomleft'}).addTo(mymap);
// 13. Add a latlng graticules.
L.latlngGraticule({
showLabel: true,
opacity: 0.2,
color: "#747474",
zoomInterval: [
{start: 2, end: 7, interval: 2},
{start: 8, end: 11, interval: 0.5}
]
}).addTo(mymap);
</script>
</body>
</html>