-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmap-chart.html
More file actions
77 lines (63 loc) · 1.75 KB
/
Copy pathmap-chart.html
File metadata and controls
77 lines (63 loc) · 1.75 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
svg {
background-color: rgb(34, 34, 34);
box-shadow: 0 0 10px 0 rgba(0, 0, 0, .3);
}
body {
display: flex;
align-items: center;
justify-content: center;
padding: 0;
margin: 0;
height: 100vh;
}
</style>
</head>
<body>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script src="./utils.js"></script>
<script>
const width = 600
const height = 600
const projection = d3.geoMercator()
.scale(120)
.translate([width / 2, height / 2])
const path = d3.geoPath()
.projection( projection )
const zoom = d3.zoom()
.scaleExtent([1, 8])
.on('zoom', handleZoom)
function handleZoom() {
const {
transform
} = d3.event
svg.attr('transform', transform)
}
let svg = d3.select('body')
.append('svg')
.call(setAttr, {
width,
height
})
.call(zoom)
svg = svg.append('g')
d3.json('./mock/worldmap.geojson')
.then(data => {
svg.append('path')
.datum(data)
.call(setAttr, {
d: path,
fill: '#555',
stroke: 'rgb(34, 34, 34)'
})
})
</script>
</body>
</html>