Skip to content

Instantly share code, notes, and snippets.

@jasondavies
Forked from mbostock/.block
Last active October 27, 2019 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jasondavies/6722361 to your computer and use it in GitHub Desktop.
Save jasondavies/6722361 to your computer and use it in GitHub Desktop.
Ocean
build
node_modules

A version of Mike Bostock’s Ocean with antimeridian cuts removed.

<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
background: #fcfcfa;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 960,
speed = -1e-2,
start = Date.now();
var sphere = {type: "Sphere"};
var projection = d3.geo.orthographic()
.scale(width / 2.2)
.clipAngle(90)
.translate([width / 2, height / 2])
.precision(.5);
var graticule = d3.geo.graticule();
var canvas = d3.select("body").append("canvas")
.attr("width", width)
.attr("height", height);
var context = canvas.node().getContext("2d");
var path = d3.geo.path()
.projection(projection)
.context(context);
d3.json("topo.json", function(error, topo) {
var ocean = topojson.feature(topo, topo.objects.ocean),
grid = graticule();
d3.timer(function() {
projection.rotate([speed * (Date.now() - start), -15]);
context.clearRect(0, 0, width, height);
context.beginPath();
path(sphere);
context.fillStyle = "#fff";
context.fill();
context.beginPath();
path(grid);
context.lineWidth = .5;
context.strokeStyle = "#ddd";
context.stroke();
context.beginPath();
path(ocean);
context.fillStyle = "rgba(70,130,180,.5)";
context.strokeStyle = "#000";
context.fill();
context.stroke();
context.beginPath();
path(sphere);
context.lineWidth = 1.5;
context.strokeStyle = "#000";
context.stroke();
});
});
d3.select(self.frameElement).style("height", height + "px");
</script>
all: topo.json
build/ne_%_ocean.zip:
mkdir -p build
curl -o $@.download --raw 'http://www.nacis.org/naturalearth/$*/physical/ne_$*_ocean.zip'
mv $@.download $@
build/ne_%.shp: build/ne_%.zip
unzip -d build $<
touch $@
topo.json: build/ne_110m_ocean.shp
node_modules/.bin/topojson \
--no-force-clockwise \
-q 1e5 \
-- \
ocean=build/ne_110m_ocean.shp \
> $@
{
"name": "anonymous",
"version": "0.0.1",
"private": true,
"devDependencies": {
"topojson": "1"
}
}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment