Green marks : inverse OK ; red marks : broken.
Checking d3-geo-projection PR #106.
forked from Fil's block: geoGringortenQuincuncial inverse, fixed
xxxxxxxxxx
<meta charset="utf-8">
<style>
.stroke {
fill: none;
stroke: #000;
stroke-width: 3px;
}
.fill {
fill: #fff;
}
.graticule {
fill: none;
stroke: #777;
stroke-width: 0.5px;
stroke-opacity: 0.5;
}
.land {
fill: #222;
}
.boundary {
fill: none;
stroke: #fff;
stroke-width: 0.5px;
}
</style>
<svg width="960" height="500"></svg>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="d3-geo-projection.js"></script>
<script src="https://d3js.org/topojson.v1.min.js"></script>
<script>
var svg = d3.select("svg"),
width = +svg.attr("width"),
height = +svg.attr("height");
var projection = d3.geoLittrow().scale(280);
var graticule = d3.geoGraticule();
var path = d3.geoPath()
.projection(projection);
var defs = svg.append("defs");
defs.append("path")
.datum({type: "Sphere"})
.attr("id", "sphere")
.attr("d", path);
defs.append("clipPath")
.attr("id", "clip")
.append("use")
.attr("xlink:href", "#sphere");
svg.append("use")
.attr("class", "stroke")
.attr("xlink:href", "#sphere");
svg.append("use")
.attr("class", "fill")
.attr("xlink:href", "#sphere");
svg.append("path")
.datum(graticule)
.attr("class", "graticule")
.attr("clip-path", "url(#clip)")
.attr("d", path);
d3.range(-179, 179, 8)
.forEach(lon => d3.range(-89, 89, 8)
.forEach(lat => {
var o = [lon, lat],
m = projection(o),
i = projection.invert(m);
svg.append("path")
.attr("fill", Math.abs(o[0]-i[0]) + Math.abs(o[1]-i[1]) < 0.1 ? "green" : "red")
.attr("d", path({type:"Point", coordinates: o}))
}))
var marker = svg.append("path")
.attr("fill", "orange")
svg.on('mousemove', function() {
var mouse = d3.mouse(this);
marker.attr("d", path({type:"Point", coordinates: projection.invert(mouse)}));
});
d3.json("https://gist.githubusercontent.com/mbostock/4090846/raw/d534aba169207548a8a3d670c9c2cc719ff05c47/world-50m.json", function(error, world) {
if (error) throw error;
svg.insert("path", ".graticule")
.datum(topojson.feature(world, world.objects.land))
.attr("class", "land")
.attr("clip-path", "url(#clip)")
.attr("d", path);
svg.insert("path", ".graticule")
.datum(topojson.mesh(world, world.objects.countries, function(a, b) { return a !== b; }))
.attr("class", "boundary")
.attr("clip-path", "url(#clip)")
.attr("d", path);
});
</script>
https://d3js.org/d3.v4.min.js
https://d3js.org/topojson.v1.min.js