Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Projection Contexts
projection.line = function(coordinates, context) {
if (!(n = coordinates.length)) return;
context = radiansAndRotateContext(projectAndTransformContext(context));
var i = 0,
n = coordinates.length,
p = coordinates[0];
context.moveTo(p[0], p[1]);
while (++i < n) context.lineTo((p = coordinates[i])[0], p[1]);
};
function radiansAndRotateContext(context) {
return {
moveTo: function() {
var p = arguments;
radians(p);
rotate(p);
context.moveTo(p[0], p[1]);
},
lineTo: function() {
var p = arguments;
radians(p);
rotate(p);
context.lineTo(p[0], p[1]);
},
closePath: function() {
context.closePath();
}
};
}
function intersectAntemeridian(context) {
var λ0, φ0, sλ0;
return {
moveTo: function(λ, φ) {
0 = λ > 0 ? π : -π;
context.moveTo0 = λ, φ0 = φ);
},
lineTo: function(λ, φ) {
var= λ > 0 ? π : -π;
if (sλ0 !==&& Math.abs- λ0) >= π) {
context.lineTo(sλ0, φ0 = d3_geo_projectionIntersectAntemeridian0, φ0, λ, φ));
context.moveTo(sλ0 = sλ, φ0);
}
context.lineTo0 = λ, φ0 = φ);
},
closePath: function() {
context.closePath();
}
};
}
function projectAndTransformContext(context) {
return {
moveTo: function() {
var p = arguments;
project(p);
transform(p);
context.moveTo(p[0], p[1]);
},
lineTo: function() {
var p = arguments;
project(p);
transform(p);
context.lineTo(p[0], p[1]);
},
closePath: function() {
context.closePath();
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.