Going from San Francisco to Paris I was asked “Why Reykjavík?”
forked from mbostock's block: This Is a Globe
forked from Fil's block: This Is a Globe in d3.v4
forked from Fil's block: Why Reykjavík?
xxxxxxxxxx
<meta charset="utf-8">
<body>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://d3js.org/topojson.v2.min.js"></script>
<script>
var width = 960,
height = 600;
var radius = height / 2 - 5,
scale = radius,
velocity = .02;
var projection = d3.geoOrthographic()
.translate([width / 2, height / 2])
.scale(scale)
.clipAngle(90);
var canvas = d3.select("body").append("canvas")
.attr("width", width)
.attr("height", height);
var context = canvas.node().getContext("2d");
var path = d3.geoPath()
.projection(projection)
.context(context);
var zoom = d3
.zoom()
.on("zoom start end", zoomed)
.scaleExtent([0.7, 5])
.translateExtent([[0,0], [width, height]]);
canvas.call(zoom);
var init_scale = projection.scale(),
init_translate = projection.translate();
function zoomed() {
var t = d3.event.transform;
projection.scale(init_scale * t.k)
.translate(t.apply(init_translate));
}
d3.json("https://gist.githubusercontent.com/mbostock/4090846/raw/d534aba169207548a8a3d670c9c2cc719ff05c47/world-110m.json", function(error, world) {
if (error) throw error;
var land = topojson.feature(world, world.objects.land);
var places = {
"type": "FeatureCollection",
"bbox": [-126.507568, 3.590178, 98.217773, 51.481383],
"features": [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [98.217773, 3.590178]
},
"properties": {
"name": "Leuser Ecosystem"
}
}, {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-76.025391, 50.303376]
},
"properties": {
"name": "Broadback Forest"
}
}, {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-126.507568, 51.481383]
},
"properties": {
"name": "Great Bear Rainforest"
}
}]
};
d3.timer(function(elapsed) {
context.clearRect(0, 0, width, height);
projection.rotate([velocity * elapsed, -40]);
context.beginPath();
path(land);
context.fillStyle = '#333';
context.fill();
context.beginPath();
path(places);
path.pointRadius(10);
context.strokeStyle = 'magenta';
context.stroke();
context.fillStyle = 'magenta';
context.fill();
context.strokeStyle = 'black';
context.beginPath();
path({type:"Sphere"});
context.lineWidth = 2.5;
context.stroke();
});
});
d3.select(self.frameElement).style("height", height + "px");
</script>
</body>
https://d3js.org/d3.v4.min.js
https://d3js.org/topojson.v2.min.js