I am trying to use raster map playback after in this example . If you change the projection kavrayskiy7
projection on the azimuthal equidistant projection,
var projection = d3.geo.azimuthalEquidistant() .scale(90) .translate([width / 2, height / 2]) .clipAngle(180 - 1e-3) .precision(.1);
he must project the Earth onto a disk (image of a projection map). However, raster recreation goes beyond this disk and fills the entire canvas with an expanded image (the inverse projection function is not injective, several x / y points on the map correspond to the same lon / lat coordinate). In the original example, this should be avoided with the line
if (λ > 180 || λ < -180 || φ > 90 || φ < -90) { i += 4; continue; }
but for this example this does not work. I found other glitches, for example, when using the Mollweide projection (two lines appear at the poles) due to the same effect.
To solve this problem, one way would be to correct the inverse projections so that they return an error or None when the input x / y is out of range. My attempt was to check if the point is at a distance using a direct projection of the entire sphere to get the SVG path with the border of the map, as indicated in this code:
var path = d3.geo.path() .projection(projection); var bdry = svg.append("defs").append("path") .datum({type: "Sphere"}) .attr("id", "sphere") .attr("d", path);
(see, for example, this example ). However, I did not find a simple way to check if the point [x,y]
inside the closed SVG path.
So my questions are:
- Is there a mistake in the back projections, or am I not using them correctly?
- How can I find if the point
[x,y]
is inside the svg path, assuming this is the best approach? - To curiosity, where is the algorithm code for the d3
path
function to obtain the boundary profile of the map? I could not find it on the github repository.
Thanks.
Edit: I looked at all 44 projections in this example , and I found glitches on the following 25:
Albers, Bromley, Collignon, Eckert II, Eckert IV, Eckert VI, Hammer, Hill, Goode Homolosine, Lambert Cylindrical Equal Area, Larrivée, Laskowski, McBryde-Thomas Flat-Polar Parabolic, McBryde-Thomas Flat-Polar Quartic, Mc Brad -Thomas Sinusoidal Planar, Molveid, Earth, Nell-Hammer, Polyclinic, Sinu-Molveid, Van der Grinten, van der Grinten IV, Wagner IV, Wagner VII, Winkel Triple.