-
Notifications
You must be signed in to change notification settings - Fork 1
/
challenge-sfcrimes0.html
75 lines (69 loc) · 2.31 KB
/
challenge-sfcrimes0.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no' />
<!--[if lte IE 8]>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.ie.css" />
<![endif]-->
<style type="text/css">
body {
padding: 0;
margin: 0;
}
html, body, #leaflet-map {
height: 100%;
}
.leaflet-popup-content {
max-height: 400px;
overflow-y: scroll;
}
</style>
<link rel="stylesheet" href="//cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
</head>
<body>
<div id="leaflet-map"></div>
<script src="//cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<script src="//rawgit.com/calvinmetcalf/leaflet-ajax/master/dist/leaflet.ajax.min.js"></script>
<script>
// MAP
var map = L.map('leaflet-map', {
center: [37.767, -122.452],
zoom: 11,
});
// copyright
var mbAttr = 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
mbUrl = 'https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png';
// mapbox gray
var grayscale = L.tileLayer(mbUrl, {
id: 'examples.map-20v6611k',
attribution: mbAttr
});
grayscale.addTo(map);
// geojson
var jsonpTest = L.geoJson.ajax("http://sanfrancisco.crimespotting.org/crime-data?format=json&count=2000&dstart=2014-12-01&dend=2015-02-01", {
onEachFeature: popUp,
dataType:"jsonp"
}).addTo(map);
// popup Function(feature, layer)
function popUp(f, l) {
var content = "<table class=\"marker-properties\"><tbody>";
var out = [];
var regexp = new RegExp('^http');
var value;
if (f.properties) {
for (var key in f.properties) {
if (regexp.test(f.properties[key])) {
value = "<a href=\"" + f.properties[key] + "\">" + f.properties[key] + "</a>";
} else {
value = f.properties[key];
}
out.push("<tr class=\"unchanged\"><th>" + key + "</th><td>" + value);
}
content = content + out.join("</td></tr>") + "</tbody></table>";
l.bindPopup(content);
}
}
</script>
</body>
</html>