Skip to content

Commit 499bcae

Browse files
committed
Add and update example maps.
1 parent bc15009 commit 499bcae

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

examples/country-index.html

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
</head>
1515
<body>
1616
<div class="container d3-geomap" id="main"></div>
17+
<script src="https://unpkg.com/d3-zoom"></script>
18+
<script src="https://unpkg.com/d3-drag"></script>
1719

1820
<script src="../node_modules/d3-array/dist/d3-array.js"></script>
1921
<script src="../node_modules/d3-geo/dist/d3-geo.js"></script>
@@ -44,7 +46,7 @@
4446
if (resp.ok) return resp.text();
4547
throw new Error(`HTTP error! Status: ${resp.status}`);
4648
}).then(text => {
47-
drawCountries(JSON.parse(text));
49+
drawCountries(JSON.parse(text).sort((a, b) => a.name.localeCompare(b.name)));
4850
});
4951

5052
function drawCountries(countries) {
@@ -55,7 +57,8 @@
5557
map_container.append('h2').text(country.name);
5658

5759
const country_map = d3.geomap()
58-
.geofile(`../dist/topojson/countries/${country.iso3}.json`);
60+
.geofile(`../dist/topojson/countries/${country.iso3}.json`)
61+
.projection(d3.geoMercator)
5962
country_map.draw(map_container);
6063
});
6164
}

examples/country-map.html

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Country Map</title>
6+
<link href="../dist/d3-geomap.css" rel="stylesheet">
7+
</head>
8+
<body>
9+
<div class="d3-geomap" id="main"></div>
10+
11+
<script src="../node_modules/d3-array/dist/d3-array.js"></script>
12+
<script src="../node_modules/d3-geo/dist/d3-geo.js"></script>
13+
14+
<script src="../node_modules/d3-dsv/dist/d3-dsv.js"></script>
15+
<script src="../node_modules/d3-fetch/dist/d3-fetch.js"></script>
16+
17+
<script src="../node_modules/d3-time/dist/d3-time.js"></script>
18+
<script src="../node_modules/d3-time-format/dist/d3-time-format.js"></script>
19+
<script src="../node_modules/d3-format/dist/d3-format.js"></script>
20+
<script src="../node_modules/d3-scale/dist/d3-scale.js"></script>
21+
<script src="../node_modules/d3-color/dist/d3-color.js"></script>
22+
<script src="../node_modules/d3-interpolate/dist/d3-interpolate.js"></script>
23+
24+
<script src="../node_modules/d3-selection/dist/d3-selection.js"></script>
25+
<script src="../node_modules/d3-timer/dist/d3-timer.js"></script>
26+
<script src="../node_modules/d3-ease/dist/d3-ease.js"></script>
27+
<script src="../node_modules/d3-dispatch/dist/d3-dispatch.js"></script>
28+
<script src="../node_modules/d3-transition/dist/d3-transition.js"></script>
29+
30+
<script src="../node_modules/topojson/dist/topojson.js"></script>
31+
<script src="../dist/d3-geomap.js"></script>
32+
33+
<script>
34+
const iso3 = 'ESP';
35+
const name = 'Spain';
36+
37+
const container = d3.select('#main').append('div')
38+
.attr('id', iso3)
39+
.attr('class', 'country');
40+
container.append('h2').text(name);
41+
42+
d3.geomap()
43+
.geofile(`../dist/topojson/countries/${iso3}.json`)
44+
.unitId('fips')
45+
.draw(container);
46+
</script>
47+
</body>
48+
</html>

examples/index.html

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ <h1>d3-geomap examples</h1>
2222
<li>
2323
<a href="./country-index.html">Country Index</a>
2424
</li>
25+
<li>
26+
<a href="./country-map.html">Country Map</a>
27+
</li>
2528
<li>
2629
<a href="./geodata-property.html">geoData Property</a>
2730
</li>

0 commit comments

Comments
 (0)