-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex3.html
151 lines (126 loc) · 3.48 KB
/
index3.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
<!DOCTYPE html>
<html>
<head>
<title>d3.geoInterruptedMollweideHemispheres</title>
<meta charset="utf-8">
<style>
body {
background: #fcfcfa;
}
.stroke {
fill: none;
stroke: #000;
stroke-width: 3px;
}
.fill {
fill: #fff;
}
.graticule {
fill: none;
stroke: #777;
stroke-width: .5px;
stroke-opacity: .5;
}
.land {
fill: #222;
}
.boundary {
fill: none;
stroke: #333;
stroke-width: .5px;
}
</style>
</head>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="//d3js.org/d3.geo.projection.v0.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 500;
var projection = d3.geo.interrupt(d3.geo.mollweide.raw)
// nice split
.lobes([[ // northern hemisphere
// [[-180, 0], [-100, 90], [ -40, 0]],
[[ -30, 0], [ 20, 50], [ 70, 0]]
], [ // southern hemisphere
// [[-180, 0], [-160, -90], [-100, 0]],
// [[-100, 0], [ -60, -90], [ -20, 0]],
[[ -30, 0], [ 20, -50], [ 70, 0]],
// [[ 80, 0], [ 140, -90], [ 180, 0]]
]])
// RANDOM testing
// .lobes([[ // northern hemisphere
// [[-150, 20], [ -120, 90], [ -30, 20]],
// [[ 0, 0], [ 90, 90], [ 180, 0]]
// ], [ // southern hemisphere
// [[-150, 20], [ -90, -90], [ -30, 20]],
// [[ 0, 0], [ 90, -90], [ 180, 0]]
// ]])
// west and east hemispheres
// .lobes([[ // northern hemisphere
// [[-180, 0], [ -90, 90], [ 0, 0]],
// [[ 0, 0], [ 90, 90], [ 180, 0]]
// ], [ // southern hemisphere
// [[-180, 0], [ -90, -90], [ 0, 0]],
// [[ 0, 0], [ 90, -90], [ 180, 0]]
// ]])
.rotate([0, 0])
.scale(165)
.translate([width / 2, height / 2])
.precision(.1);
var path = d3.geo.path()
.projection(projection);
var graticule = d3.geo.graticule();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var defs = svg.append("defs");
defs.append("path")
.datum({type: "Sphere"})
.attr("id", "sphere")
.attr("d", path);
defs.append("clipPath")
.attr("id", "clip")
.append("use")
.attr("xlink:href", "#sphere");
svg.append("use")
.attr("class", "stroke")
.attr("xlink:href", "#sphere");
svg.append("use")
.attr("class", "fill")
.attr("xlink:href", "#sphere");
svg.append("path")
.datum(graticule)
.attr("class", "graticule")
.attr("clip-path", "url(#clip)")
.attr("d", path);
//d3.json("https://www1.ncdc.noaa.gov/pub/data/nidis/geojson/global/base/worldboundary.geojson", function(error, world) {
// if (error) throw error;
//
// svg.insert("path", ".graticule")
// .datum(topojson.feature(world, world.objects.land))
// .attr("class", "land")
// .attr("clip-path", "url(#clip)")
// .attr("d", path);
//
// svg.insert("path", ".graticule")
// .datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; }))
// .attr("class", "boundary")
// .attr("clip-path", "url(#clip)")
//});
// Load map data
d3.json('https://www1.ncdc.noaa.gov/pub/data/nidis/geojson/global/base/world.geojson', function(error, mapData) {
var features = mapData.features;
// Draw each province as a path
svg.selectAll('path')
.data(features)
.enter().append('path', '.graticule')
.attr('d', path)
.attr("clip-path", "url(#clip)")
.attr('class', 'boundary');
});
d3.select(self.frameElement).style("height", height + "px");
</script>
</body>
</html>