public
Created

London Traffic

  • Download Gist
index.html
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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
<!DOCTYPE html>
<head>
<style>
 
body {
background: rgb(10, 16, 29);
}
 
.points {
fill: rgb(243, 247, 28);
fill-opacity: 0.6;
stroke: none;
}
 
.water {
fill: rgb(63, 71, 85);
}
 
.landuse {
fill: rgb(51, 51, 51);
fill-opacity: 0.5;
}
 
.roads_residential {
fill: none;
stroke: rgb(63, 71, 85);
stroke-width: 0.2px;
}
 
.roads_secondary {
fill: none;
stroke: rgb(63, 71, 85);
stroke-width: 0.4px;
}
 
.roads_primary {
fill: none;
stroke: rgb(63, 71, 85);
stroke-width: 0.5px;
}
 
.roads_trunk {
fill: none;
stroke: rgb(63, 71, 85);
stroke-width: 0.8px;
}
 
.mask {
fill: none;
stroke: rgb(63, 71, 85);
stroke-width: 0.4px;
}
 
</style>
 
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/d3.geo.projection.v0.min.js"></script>
<script src="http://d3js.org/topojson.v0.min.js"></script>
</head>
<body>
<script>
 
var width = 2400,
height = 1800;
 
var projection = d3.geo.mercator()
.translate([width/2, height/2])
.center([-0.08, 51.4971])
.scale(150000);
var path = d3.geo.path()
.projection(projection);
 
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
 
var landuse = svg.append("g");
var water = svg.append("g");
var roads_residential = svg.append("g");
var roads_secondary = svg.append("g");
var roads_primary = svg.append("g");
var roads_trunk = svg.append("g");
var points = svg.append("g");
var mask = svg.append("mask").attr("id", "maskurl");
 
/* Traffic dataset */
d3.csv('majorroads/2001hgvs.csv', function(err, data) {
points.selectAll("circle")
.data(data)
.enter().append("circle")
.attr("cx", function(d) { return projection([d.Longitude, d.Latitude])[0]; })
.attr("cy", function(d) { return projection([d.Longitude, d.Latitude])[1]; })
.attr("r", function(d) { return Math.sqrt(d.AllHGVs)*0.25; })
.attr("mask", "url(#maskurl)")
.attr("class", "points");
});
 
/* Calls to individual topojson files, separated for clarity */
d3.json('roads_residential.topo.json', function(err, data) {
roads_residential.append("path")
.datum(topojson.object(data, data.objects.roads_residential1))
.attr("class", "roads_residential")
.attr("d", path);
roads_residential.append("path")
.datum(topojson.object(data, data.objects.roads_residential2))
.attr("class", "roads_residential")
.attr("d", path);
roads_residential.append("path")
.datum(topojson.object(data, data.objects.roads_residential3))
.attr("class", "roads_residential")
.attr("d", path);
});
 
d3.json('roads_secondary.topo.json', function(err, data) {
roads_secondary.append("path")
.datum(topojson.object(data, data.objects.roads_secondary1))
.attr("class", "roads_secondary")
.attr("d", path);
roads_secondary.append("path")
.datum(topojson.object(data, data.objects.roads_secondary2))
.attr("class", "roads_secondary")
.attr("d", path);
roads_secondary.append("path")
.datum(topojson.object(data, data.objects.roads_secondary3))
.attr("class", "roads_secondary")
.attr("d", path);
});
 
d3.json('roads_primary.topo.json', function(err, data) {
roads_primary.append("path")
.datum(topojson.object(data, data.objects.roads_primary1))
.attr("class", "roads_primary")
.attr("d", path);
roads_primary.append("path")
.datum(topojson.object(data, data.objects.roads_primary2))
.attr("class", "roads_primary")
.attr("d", path);
roads_primary.append("path")
.datum(topojson.object(data, data.objects.roads_primary3))
.attr("class", "roads_primary")
.attr("d", path);
});
 
d3.json('roads_trunk.topo.json', function(err, data) {
roads_trunk.append("path")
.datum(topojson.object(data, data.objects.roads_trunk1))
.attr("class", "roads_trunk")
.attr("d", path);
roads_trunk.append("path")
.datum(topojson.object(data, data.objects.roads_trunk2))
.attr("class", "roads_trunk")
.attr("d", path);
roads_trunk.append("path")
.datum(topojson.object(data, data.objects.roads_trunk3))
.attr("class", "roads_trunk")
.attr("d", path);
});
 
/* Call to the same topojson files to be used for the mask */
d3.json('roads_secondary.topo.json', function(err, data) {
mask.append("path")
.datum(topojson.object(data, data.objects.roads_secondary1))
.attr("class", "mask")
.attr("d", path);
mask.append("path")
.datum(topojson.object(data, data.objects.roads_secondary2))
.attr("class", "mask")
.attr("d", path);
mask.append("path")
.datum(topojson.object(data, data.objects.roads_secondary3))
.attr("class", "mask")
.attr("d", path);
});
 
d3.json('roads_primary.topo.json', function(err, data) {
mask.append("path")
.datum(topojson.object(data, data.objects.roads_primary1))
.attr("class", "mask")
.attr("d", path);
mask.append("path")
.datum(topojson.object(data, data.objects.roads_primary2))
.attr("class", "mask")
.attr("d", path);
mask.append("path")
.datum(topojson.object(data, data.objects.roads_primary3))
.attr("class", "mask")
.attr("d", path);
});
 
d3.json('roads_trunk.topo.json', function(err, data) {
mask.append("path")
.datum(topojson.object(data, data.objects.roads_trunk1))
.attr("class", "mask")
.attr("d", path);
mask.append("path")
.datum(topojson.object(data, data.objects.roads_trunk2))
.attr("class", "mask")
.attr("d", path);
mask.append("path")
.datum(topojson.object(data, data.objects.roads_trunk3))
.attr("class", "mask")
.attr("d", path);
});
 
d3.json('london.topo.json', function(err, data) {
landuse.append("path")
.datum(topojson.object(data, data.objects.landuse))
.attr("class", "landuse")
.attr("d", path);
 
water.append("path")
.datum(topojson.object(data, data.objects.waterway))
.attr("class", "water")
.attr("d", path);
});
 
</script>
</body>
</html>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.