-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAdaptiveCompositeMapProjection_PortraitFormat.html
153 lines (133 loc) · 3.87 KB
/
AdaptiveCompositeMapProjection_PortraitFormat.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
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Adaptive Composite Map Projection (Portrait format)</title>
<style>
body {
background: #fcfcfa;
height: 600px;
position: relative;
width: 400px;
}
.stroke {
fill: none;
stroke: #000;
stroke-width: 3px;
}
.fill {
fill: #000;
}
.graticule {
fill: none;
stroke: #fff;
stroke-width: .5px;
stroke-opacity: .5;
}
.land {
fill: #fff;
stroke:#777;
stroke-width:.75px;
}
.boundary {
fill: none;
stroke: #fff;
stroke-width: .5px;
}
</style>
</head>
<body>
<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.v1.min.js"></script>
<script src="D3proj/transformedLambertAzimuthal.js"></script>
<script src="D3proj/transformedLambertAzimuthalTransverse.js"></script>
<script src="D3proj/transverseCylindricalEqualArea.js"></script>
<script src="AdaptiveCompositeMapProjection.js"></script>
<script>
var width = 400,
height = 600,
scale = 1,
m0,
o0,
currentProj,
rotate = [0.1,0.1],
projection = PortraitMapACMP(1, [0,0]).translate([width / 2, height / 2]),
graticule = d3.geo.graticule(),
sphere = {type: "Sphere"};
var canvas = d3.select("body").append("canvas")
.attr("width", width)
.attr("height", height);
var context = canvas.node().getContext("2d");
var path = d3.geo.path()
.projection(projection)
.context(context);
var zoom = d3.behavior.zoom()
.center([width / 2, height / 2])
.on("zoomstart", function(){
m0 = [d3.event.sourceEvent.pageX, d3.event.sourceEvent.pageY];
var proj = projection.rotate();
o0 = [-proj[0],-proj[1]];
d3.event.sourceEvent.stopPropagation();
})
.on("zoom", function() {
if (m0) {
var constant = (scale < 4) ? 4 : scale * 2;
var m1 = [d3.event.sourceEvent.pageX, d3.event.sourceEvent.pageY],
o1 = [o0[0] + (m0[0] - m1[0]) / constant, o0[1] + (m1[1] - m0[1]) / constant];
}
rotate = [-o1[0], -o1[1]];
scale = (d3.event.scale >= 1) ? d3.event.scale : 1;
projection = PortraitMapACMP(scale, rotate).translate([width / 2, height / 2]);
path = d3.geo.path().projection(projection);
context.clearRect(0, 0, width, height);
// Update sphere styles
context.beginPath();
path.context(context)(sphere);
context.fillStyle = "#000";
context.fill();
// Update graticule styles
context.beginPath();
path.context(context)(grid);
context.lineWidth = 0.5;
context.strokeStyle = "#ddd";
context.stroke();
// Update land styles
context.beginPath();
path.context(context)(land);
context.fillStyle = "#fff";
context.fill();
context.strokeStyle = "#000";
context.stroke();
});
d3.json("countries_1e5.json", function(error, data) {
land = topojson.feature(data, data.objects.countries),
grid = graticule();
context.clearRect(0, 0, width, height);
// Style sphere
context.beginPath();
path(sphere);
context.fillStyle = "#000";
context.fill();
// Style graticule
context.beginPath();
path(grid);
context.lineWidth = 0.5;
context.strokeStyle = "#ddd";
context.stroke();
// Style land
context.beginPath();
path(land);
context.fillStyle = "#fff";
context.fill();
context.strokeStyle = "#000";
context.stroke();
canvas.call(zoom);
d3.select("body").append("text")
.attr("id", "info");
d3.select("body").append("text")
.attr("id", "proj");
});
</script>
</body>
</html>