-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhovermaps.html
120 lines (112 loc) · 3.96 KB
/
hovermaps.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="//leafletjs.com/dist/leaflet.css" />
<!--[if lte IE 8]>
<link rel="stylesheet" href="/static/leaflet/leaflet.ie.css" />
<![endif]-->
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//leafletjs.com/dist/leaflet.js"></script>
<script src="js/TileLayer.GeoJSON.js"></script>
<script src="js/d3.v3.js"></script>
<script src="js/activemaps_config.js"></script>
<style>
html, body, #map {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script type="text/javascript">
var region = "bayarea";
var file = "bayarea_chts_tractvolume";
if(document.URL.indexOf('?') != -1) {
var tmpregion = document.URL.match(/region=([^&]+)/);
if(tmpregion != null) region = tmpregion[1];
var tmpfile = document.URL.match(/file=([^&]+)/);
if(tmpfile != null) file = tmpfile[1] ;
}
console.log(region);
var centerd = REGIONCENTERS;
var center = centerd[region];
console.log(file);
var map = new L.Map('map'),
cloudmadeUrl = 'http://{s}.tile.cloudmade.com/1a1b06b230af4efdbb989ea99e9841af/997/256/{z}/{x}/{y}.png',
cloudmadeAttribution = 'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 CloudMade';
map.setView(new L.LatLng(center[0],center[1]), 12);
var baseLayer = new L.TileLayer(cloudmadeUrl, { attribution: cloudmadeAttribution});
map.addLayer(baseLayer);
var data = null;
d3.csv("data/"+file+".csv", function(d) {
return {
fromtract: +d.fromtract,
totract: +d.totract,
volume: +d.volume
};
}, function(error, rows) {
var d = {};
rows.forEach(function(r) {
if(!(r.fromtract in d)) d[r.fromtract] = {};
if(!(r.totract in d[r.fromtract])) d[r.fromtract][r.totract] = 0;
d[r.fromtract][r.totract] += r.volume;
vol = d[r.fromtract][r.totract];
if(!("max" in d[r.fromtract]) || vol > d[r.fromtract]["max"]) d[r.fromtract]["max"] = vol;
});
data = d;
});
var defstyle = {
"clickable": true,
"color": "#00D",
"fillColor": "#00D",
"weight": 1.0,
"opacity": 0.3,
"fillOpacity": 0.1
}
var FEATUREID = null;
function style(feature) {
if(feature === undefined || FEATUREID === null || data === null
|| !(FEATUREID in data) || !(feature.id in data[FEATUREID])) {
defstyle["fillOpacity"] = .01;
return defstyle;
}
defstyle["fillOpacity"] = data[FEATUREID][feature.id] / data[FEATUREID]["max"] / 1.33 + .25;
return defstyle;
}
var tblname = {'bayarea':'bayarea','mexicocity':'mexcity'}[region];
var geojsonURL = 'http://paris.urbansim.org:8763/'+tblname+'/{z}/{x}/{y}.geojson';
var geojsonTileLayer = new L.TileLayer.GeoJSON(geojsonURL, {
clipTiles: true,
unique: function (feature) {
return feature.id;
}
}, {
style: style,
onEachFeature: function (feature, layer) {
if (feature.properties) {
var popupString = '<div class="popup">';
for (var k in feature.properties) {
var v = feature.properties[k];
popupString += k + ': ' + v + '<br />';
}
popupString += '</div>';
layer.bindPopup(popupString);
}
if (!(layer instanceof L.Point)) {
layer.on('mouseover', function () {
FEATUREID = feature.id;
geojsonTileLayer.geojsonLayer.setStyle(style);
});
}
}
}
);
map.addLayer(geojsonTileLayer);
</script>
</body>
</html>