-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
74 lines (58 loc) · 2.39 KB
/
test.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
<!DOCTYPE html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title></title>
<script src="vendor/d3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script type="text/javascript" src="build/js/all.min.js"></script>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
</style>
</head>
<body>
<script>
var width = 960;
var height = 1120;
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
// var projection = d3.geo.albers()
// .scale(2100);
// var path = d3.geo.path().projection(projection);
// var b = path.bounds(feature),
// s = 0.95 / Math.max(
// (b[1][0]-b[0][0])/width,
// (b[1][1]-b[0][1])/height
// );
// b = d3.geo.bounds(feature);
// projection.center([(b[1][0]+b[0][0])/2, (b[1][1]+b[0][1])/2]);
// projection.translate([width/2, height/2]);
d3.json("./data/HUC_17.topo.json", function(error, topology) {
console.log(topology);
var center = d3.geo.centroid(topology)
var scale = 1500;
var offset = [width/2, height/2];
var projection = d3.geo.mercator().scale(scale).center(center)
.translate(offset);
var path = d3.geo.path().projection(projection);
var bounds = path.bounds(topology);
var hscale = scale*width / (bounds[1][0] - bounds[0][0]);
var vscale = scale*height / (bounds[1][1] - bounds[0][1]);
var scale = (hscale < vscale) ? hscale : vscale;
var offset = [width - (bounds[0][0] + bounds[1][0])/2,
height - (bounds[0][1] + bounds[1][1])/2];
projection = d3.geo.mercator().center(center)
.scale(scale).translate(offset);
path = path.projection(projection);
svg.selectAll("path")
.data(topojson.feature(topology, topology.objects.NHDFlowline).features)
.enter()
.append("path")
.attr("d", path);
});
</script>
</body>
</html>