forked from aourednik/historical-basemaps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
d3example.html
86 lines (73 loc) · 2.1 KB
/
d3example.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
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.land {
fill: #222;
}
.boundary {
fill: none;
stroke: #fff;
stroke-width: 0.5px;
}
.states {
stroke: #fff;
stroke-width: 0.5;
}
</style>
<!--
To run locally:
- In Firefox: disable strict origin control in about:cofig
- Launch Chrome with /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --disable-web-security --user-data-dir
-->
<svg width="1400" height="1000"></svg>
<script src="d3/d3.v4.min.js"></script>
<script src="d3/d3-geo-projection.v1.min.js"></script>
<!-- <script src="d3/topojson.v2.min.js"></script> -->
<script src="d3/d3-scale-chromatic.v0.3.min.js"></script>
<script src="d3/queue.v1.min.js"></script>
<script>
var svg = d3.select("svg"),
width = +svg.attr("width"),
height = +svg.attr("height");
var projection =
d3.geoPeirceQuincuncial()
// d3.geoGringortenQuincuncial()
// d3.geoInterruptedMollweideHemispheres()
// d3.geoAzimuthalEquidistant()
// d3.geoInterruptedMollweideHemispheres()
// d3.geoWiechel()
// d3.geoPolyhedralWaterman()
// d3.geoSinuMollweide()
// d3.geoNaturalEarth1()
// d3.geoLoximuthal()
// d3.geoBonne()
// d3.geoBertin()
.scale(214)
.translate([width / 2, height / 2])
.precision(0.1);
var path = d3.geoPath()
.projection(projection);
queue()
.defer(d3.json, 'world_1880.geojson')
.await(makeMyMap);
function makeMyMap(error, states) {
if (error) throw error;
var colors = d3.scaleOrdinal(d3.schemePaired);
svg.append("g")
.attr("class", "states")
.selectAll("path")
.data(states.features)
.enter().append("path")
.attr("d", path)
.attr("fill", function(d){
console.log(d.properties.ABBREVNAME)
if (d.properties.ABBREVNAME==="Antarctica") {return("white")}
else if (d.properties.NAME==null | d.properties.NAME=='unclaimed') {return("grey")}
else {
return(colors(d.properties.NAME))
//return(colors[Math.floor(Math.random() * colors.length)])
}
})
;
}
</script>