-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
73 lines (62 loc) · 1.46 KB
/
index.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
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<style>
path {
fill: none;
stroke: #777;
stroke-linejoin: round;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script>
var src = "http://represent.opennorth.ca/boundaries/ontario-electoral-districts/simple_shape";
var width = 960;
var height = 1160;
var svg = d3
.select("body")
.append("svg")
.attr("width", width)
.attr("height", height);
var projection = d3
.geo
.albers()
.scale(1)
.translate([0, 0]);
var path = d3
.geo
.path()
.projection(projection);
var buildGeoJson = function(json){
var geoJson = {
"type": "FeatureCollection",
"features": []
};
json.objects.forEach(function(obj){
var feature = {
"type": "Feature",
"geometry": obj.simple_shape,
"properties": {"name": obj.name}
};
geoJson.features.push(feature);
});
return geoJson;
};
d3.json(src, function(error, json) {
var geoJson = buildGeoJson(json);
var b = path.bounds(geoJson);
var s = .70 / Math.max((b[1][0] - b[0][0]) / width, (b[1][1] - b[0][1]) / height);
var t = [(width - s * (b[1][0] + b[0][0])) / 2, (height - s * (b[1][1] + b[0][1])) / 2];
projection
.scale(s)
.translate(t);
svg.selectAll("path")
.data(geoJson.features)
.enter()
.append("path")
.attr("d", path);
});
</script>
</body>
</html>