1

I'm trying to save a Polymaps map consisting of a json layer as an image file using canvg as described here. The problem I'm running into is that when I try to construct the svg string using the XML serializer, the contents of the sub-elements are not included in the string. These elements are where the geographical information is stored, so my svg string doesn't contain the necessary information to draw the map onto the canvas.

Any idea why this is happening or how to include all the svg sub-elements in the svg string?

Community
  • 1
  • 1
edodge
  • 31
  • 5

1 Answers1

2

Came back to this problem after some time and I believe I've solved it.

Polymaps will only allow you to access the map's "g" sub-elements containing the geographical information (in my case uploaded from a json file) within the "load" and "show" functions. While looping over the last map feature within the "load" or "show" function, walk up the svg DOM (feature.parentNode.parentNode.parentNode.parentNode in my case). Then use the XML serializer to extract the string. You will have to convert CSS map styling to inline if you want to fully preserve the map styling within the extracted string.

edodge
  • 31
  • 5