Skip to content

Instantly share code, notes, and snippets.

@hepplerj
Last active April 28, 2016 17:14
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 hepplerj/11074df2789d8fea8feecd84437e6531 to your computer and use it in GitHub Desktop.
Save hepplerj/11074df2789d8fea8feecd84437e6531 to your computer and use it in GitHub Desktop.
Greenland coast
node_modules
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.
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<style>
body {
background: #333;
}
.coastline {
fill: none;
stroke: orange;
stroke-width: 1px;
}
.graticule {
fill: none;
stroke: #777;
stroke-width: .5px;
stroke-opacity: .5;
}
.land {
fill: #222;
}
.boundary {
fill: none;
stroke: #333;
stroke-width: .5px;
}
</style>
</head>
<div id="map"></div>
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="//d3js.org/topojson.v1.min.js"></script>
<script src="//d3js.org/queue.v1.min.js"></script>
<script src="main.js"></script>
</body>
queue()
.defer(d3.json, "world-50m.json")
.defer(d3.json, "coast.topojson")
.await(makeMap);
// Defaults
var width = 600,
height = 600;
var svg = d3.select('#map').append('svg')
.attr('width', width)
.attr('height', height);
// Projection information
var projection = d3.geo.stereographic()
.scale(2500)
.translate([width / 2, height / 2])
.rotate([50, -70])
.clipAngle(180 - 1e-4)
.clipExtent([[0, 0], [width, height]])
.precision(.1);
var path = d3.geo.path()
.projection(projection);
// Build our map
function makeMap(error, world, greenland) {
if (error) throw error;
// Draw world countries and borders
svg.insert("path", ".graticule")
.datum(topojson.feature(world, world.objects.land))
.attr("class", "land")
.attr("d", path);
svg.insert("path", ".graticule")
.datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; }))
.attr("class", "boundary")
.attr("d", path);
// Select our coastline objects
var route = topojson.feature(greenland, greenland.objects['coast']);
// Make a group for features
var greenland_coast = svg.append('g').attr('class', 'feature-group');
// Add coastline data
greenland_coast.selectAll('.coastline')
.data(route.features)
.enter().append('path')
.attr('class', 'coastline')
.attr('d', path);
}
{
"name": "greenland-map",
"version": "0.0.1",
"description": "Mapping the coast of Greenland",
"keywords": [
"Greenland",
"d3js",
"visualization",
"spatial history",
"digital humanities"
],
"main": "main.js",
"author": "Jason Heppler <jason@jasonheppler.org>",
"license": "MIT",
"dependencies": {
"d3": "3",
"topojson": "1",
"d3-queue": "1"
},
"devDependencies": {
"d3": "3",
"topojson": "1",
"d3-queue": "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