In my latest project, I have created a jsfiddle showcasing a Bostock spinning globe implementation.
After successfully plotting a few city markers, I encountered a problem where not all cities were being displayed. Additionally, the script intended to hide markers that are not visible behind the globe was not functioning properly, causing the markers to move unexpectedly when scrolled out of view.
To view the fiddle and script in question, click here: http://jsfiddle.net/Guill84/jg3axLmx/1/
Below is the script used to position the cities and 'hide' them behind the globe:
function position_cities() {
var centerPos = projection.invert([380,380]);
var arc = d3.geo.greatArc();
svg.selectAll(".cities")
.style("fill", "blue")
.attr("cx", function(d) {
return projection([d.lon, d.lat])[0];
})
.attr("cy", function(d) {
return projection([d.lon, d.lat])[1];
})
.style({
"color": "#FFF",
"display": function(d) {
var x = projection([d.lon, d.lat])[0];
var y = projection([d.lon, d.lat])[1];
var d = arc.distance({
source: [d.lat, d.lon],
target: centerPos
});
return (d > 1.57) ? 'none' : 'inline';
}
});
}
Furthermore, I am seeking assistance on how to add labels to these markers and modify their shape to be square instead of circular.
A question similar to mine can be found here: Cannot hide labels 'behind' spinning D3 Globe
For example, the marker in Brazil is still visible in the image linked here: https://i.sstatic.net/WnSfq.png