0

My objective here is to allow users to specify territories or regions given a background world-map overlay, which is an SVG generated from GeoJSON data using D3. I have done the part where the territories' points are pinpointed by the user, and an SVG is generated. This works well.

Now I would like to save the territory's coordinates, using the background map's projection, scale and translation. I saw a lot of documentation about translating GeoJSON data to SVG s, but nothing about the other way. Is it even possible ?

Bruno Pérel
  • 575
  • 6
  • 21
  • if you have all the points drawn on the SVG, you can use the projection.invert function to convert the x,y co-ordinates back to lat/longs. – Ben Lyall Nov 16 '14 at 12:22

1 Answers1

1

Thanks Ben Lyall, eventually I used the native SVG functions getTotalLength() and getPointAtLength() to convert my path to an array of top/left positions (in pixels), then d3's projection.invert() to translate them into coordinates.

Bruno Pérel
  • 575
  • 6
  • 21