-
Notifications
You must be signed in to change notification settings - Fork 0
/
map-app.js
78 lines (69 loc) · 1.91 KB
/
map-app.js
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
// use some code from D3 examples
var width = 1400,
height = 1600;
var labelCountries = {
'Qatar': 'कतार',
'Saudi Arabia': 'साउदी अरब',
'Nepal': 'नेपाल',
'Malaysia': 'मलेशिया'
}
var projection = d3.geo.cylindricalEqualArea()
.scale(800)
.translate([-400, 840])
.precision(0.0001);
var path = d3.geo.path()
.projection(projection);
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("countries.geo.json", function(error, countries) {
if (error) {
throw error;
}
var highlighted = [];
svg.selectAll("svg")
.data(countries.features)
.enter()
.append("path")
.attr("class", function(d) {
if (labelCountries[d.properties.name]) {
highlighted.push(d);
} else {
return "country";
}
})
.attr("d", path);
svg.selectAll("svg")
.data(highlighted)
.enter()
.append("path")
.attr("class", function(d) {
if (d.properties.name === "Nepal") {
return "country nepal";
} else if (d.properties.name === "United Arab Emirates") {
return "country uae";
} else if (d.properties.name === "Qatar") {
return "country qatar";
} else {
return "country highlight";
}
})
.attr("d", path);
svg.selectAll(".subunit-label")
.data(countries.features)
.enter().append("text")
.attr("class", "subunit-label")
.attr("transform", function(d) { return "translate(" + path.centroid(d) + ")"; })
.text(function(d) {
return labelCountries[d.properties.name] || '';
})
.attr("dy", function(d) {
var name = d.properties.name;
if (name === 'United Arab Emirates' || name === 'Qatar') {
return '-20px';
} else if (name === 'Nepal') {
return '-30px';
}
return '0px';
});
});