-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.htm
75 lines (73 loc) · 2.2 KB
/
index.htm
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
<!DOCTYPE html>
<html>
<head>
<title>Simple Leaflet Map with Heatmap </title>
<meta charset="utf-8" />
<link
rel="stylesheet"
href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.css"
/>
</head>
<body>
<script src="codes.js"></script>
<script
src="http://cdn.leafletjs.com/leaflet-0.7/leaflet.js">
</script>
<script
src="http://leaflet.github.io/Leaflet.heat/dist/leaflet-heat.js">
</script>
<script src="2013-earthquake.js"></script>
<script>
function go(){
try{
document.getElementById('mapwrap').innerHTML = '<div id="map" style="width: 600px; height: 400px"></div>';
var input = document.getElementById('codes').value;
var splitInput = input.split('\n');
var code_counts = {};
for (var i = 0; i < splitInput.length; i++){
var code = splitInput[i].trim();
if (code != ''){
if (code in code_counts) code_counts[code] += 1;
else code_counts[code] = 1;
}
}
if (Object.keys(code_counts).length <= 1){
alert('Must have more than one unique zip code.');
return;
}
var latSum = 0;
var lonSum = 0;
var data = [];
for (var code in code_counts) {
var loc = codes[code];
latSum += loc['lat'];
lonSum += loc['lon'];
data.push([loc['lat'], loc['lon'], code_counts[code]]);
}
var len = data.length;
var map = L.map('map').setView([latSum/len,lonSum/len], 5);
var bounds = L.latLngBounds(data);
map.fitBounds(bounds);//works!
mapLink =
'<a href="http://openstreetmap.org">OpenStreetMap</a>';
L.tileLayer(
'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© ' + mapLink + ' Contributors',
maxZoom: 18,
}).addTo(map);
var heat = L.heatLayer(data,{
radius: 20,
blur: 15,
maxZoom: 17,
gradient: {0.4: 'blue', 0.65: 'lime', 1: 'red'},
minOpacity: 0.4
}).addTo(map);
}catch(e){alert('There was a problem processing your input. Check that the values are valid and try again.');}
}
</script>
<textarea id="codes" name="Text1" cols="40" rows="5"></textarea>
<button onclick="go()">Generate Map</button>
<div id="mapwrap">
<div id="map" style="width: 600px; height: 400px"></div></div>
</body>
</html>