Skip to content

Instantly share code, notes, and snippets.

@martgnz
Last active October 28, 2017 15:12
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 martgnz/d8bc3d6c29e712e3255f095671a51967 to your computer and use it in GitHub Desktop.
Save martgnz/d8bc3d6c29e712e3255f095671a51967 to your computer and use it in GitHub Desktop.
Azimuthal Equidistant
license: mit
border: none
height: 1000

Azimuthal Equidistant projection done with Canvas.

Using the type "Sphere" to get the outline instead of graticule.outline().

<!DOCTYPE html>
<meta charset="utf-8" />
<body>
<script src="https://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="https://d3js.org/topojson.v1.min.js"></script>
<script src="https://unpkg.com/rbush@1.4.3/rbush.js"></script>
<script src="https://unpkg.com/d3-geo-projection@0.2.16/d3.geo.projection.min.js"></script>
<script src="https://unpkg.com/spamjs@1.1.0/spam.min.js"></script>
<script type='text/javascript'>
var graticule = d3.geo.graticule();
d3.json("https://unpkg.com/world-atlas@1.1.4/world/50m.json", function(err, d) {
topojson.presimplify(d);
var map = new StaticCanvasMap({
element: "body",
width: 960,
height: 1000,
projection: d3.geo
.azimuthalEquidistant()
.scale(150)
.translate([960 / 2, 1000 / 2])
.clipAngle(180 - 4e-3)
.precision(0.1),
data: [
{
features: topojson.feature(d, d.objects["countries"]),
static: {
prepaint: function(parameters) {
parameters.context.beginPath();
parameters.path(graticule());
parameters.context.lineWidth = 0.5;
parameters.context.strokeStyle = "rgb(170,170,170)";
parameters.context.stroke();
parameters.context.beginPath();
parameters.path({ type: "Sphere" });
parameters.context.lineWidth = 1.5;
parameters.context.strokeStyle = "rgb(30,30,30)";
parameters.context.stroke();
},
paintfeature: function(parameters, d) {
parameters.context.lineWidth = 0.5;
parameters.context.strokeStyle = "rgb(255,255,255)";
parameters.context.stroke();
parameters.context.fillStyle = "#111";
parameters.context.fill();
}
}
}
]
});
map.init();
});
</script>
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