-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.html
80 lines (71 loc) · 2.13 KB
/
example.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
<!-- based on https://bl.ocks.org/d3noob/5c6eab54c8ca51929734b6f5cca2b231 -->
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.country {
stroke: white;
stroke-width: 0.25px;
fill: grey;
}
</style>
<body>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script src="https://unpkg.com/topojson@3"></script>
<script>
var width = 1670,
height = 884;
var projection = d3.geoNaturalEarth1()
.scale(300)
.center([-70, 35 ])
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
var path = d3.geoPath()
.projection(projection);
var g = svg.append("g");
// load and display the World
d3.json("https://raw.githubusercontent.com/cszang/dendrobox/master/data/world-110m2.json").then(function(topology) {
g.selectAll("path")
.data(topojson.feature(topology, topology.objects.countries).features)
.enter().append("path")
.attr('class', 'country')
.attr("d", path);
});
d3.json("./data.geojson").then(function({ features: seaLabels }) {
// g.selectAll("path")
// .data(topojson.feature(topology, topology.objects.countries).features)
// .enter().append("path")
// .attr("d", path);
g
.append('g')
.attr('class', 'seaLabels')
.selectAll('path')
.data(seaLabels)
.enter()
.append('path')
.attr('d', path)
.attr('class', 'seaLabel')
.attr('fill', 'none')
.attr('id', ({ properties: { id } }) => `seaLabelPath${id}`);
g
.append('g')
.attr('class', 'seaLabelsPaths')
.selectAll('textPath')
.data(seaLabels)
.enter()
.append('text')
.attr('fill', 'var(--country)')
.attr('id', 'curve-text')
.style('text-anchor', 'middle')
.attr('dy', '-0.5px')
.attr('font-size', ({ properties: { size } }) => size * 7)
.attr('letter-spacing', ({ properties: { spacing } }) => spacing * 7)
.append('textPath')
.attr('class', 'seaLabelTextPath')
.attr('startOffset', '50%')
.attr('xlink:href', ({ properties: { id } }) => `#seaLabelPath${id}`)
.text(d => d.properties.translations.en);
});
</script>
</body>
</html>