Home > Net >  Get geospatial coordinates a path projected with D3.js
Get geospatial coordinates a path projected with D3.js

Time:03-25

I have successfully project an SVG world map and some other shapes onto a sphere using D3.js.

I can easily map points to the sphere, but I don't yet have the other way around. From a mouse event, I'd like to derive the lat/lng or just the general angles at the pointer.

Before I go down the math rabbit hole, is there something built into D3.js to handle the inverted mapping? Or an existing solution otherwise?

CodePudding user response:

Assuming you are using this library, you could try the invert() method

For newer versions, as of v6 at least:

//in click or other mouse event handler
const coords = projection.invert(d3.pointer(event, this));
  • Related