Skip to content

Instantly share code, notes, and snippets.

@danaoira
Last active March 5, 2018 23:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danaoira/0e18d8c5afe776e0cdfe94055d0b6f7c to your computer and use it in GitHub Desktop.
Save danaoira/0e18d8c5afe776e0cdfe94055d0b6f7c to your computer and use it in GitHub Desktop.
Ocean with marker
license: gpl-3.0
build
node_modules

One of the few cases where you want a counterclockwise polygon because the ocean covers greater than one hemisphere. The example demonstrates improved antimeridian stitching in TopoJSON 1.4.1.

forked from mbostock's block: Ocean

<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
background: #fcfcfa;
}
</style>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 960,
speed = 1e-2,
start = Date.now();
var sphere = {type: "Sphere"};
var point = {
type: "MultiPoint",
coordinates: [
[-122.332071, 47.606209],
[114.057865, 22.543096]
]
};
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) {
if (error) throw error;
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.fill();
context.beginPath();
path(sphere);
context.lineWidth = 1.5;
context.strokeStyle = "#000";
context.stroke();
context.beginPath();
path(point);
context.lineWidth = 10;
context.strokeStyle = "pink";
context.stroke();
context.fillStyle = "pink";
context.fill();
});
});
d3.select(self.frameElement).style("height", height + "px");
</script>
all: topo.json
build/ne_%_ocean.zip:
mkdir -p build
curl -o $@ --raw 'http://www.nacis.org/naturalearth/$*/physical/ne_$*_ocean.zip'
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