Raphael JS: how to find path of an SVG image?

前端 未结 1 1699
长情又很酷
长情又很酷 2021-02-03 15:46

Using GIMP I have obtained path of each continent in http://upload.wikimedia.org/wikipedia/commons/9/95/Continents.svg but now I am not able to figure out how to convert this SV

1条回答
  •  失恋的感觉
    2021-02-03 16:14

    First of all, you're working with vectors, so you're likely to get better results in inkscape ('the open source Adobe Illustrator') than gimp ('the open source Adobe Photoshop').

    A good first step would be import it into Inkscape, use whatever Inkscape's equivalent of Illustrator's path simplify tool is (assuming low file size is more important than the very high level of detail in most wikipedia SVG maps - be careful that it doesn't break country borders), and export as SVG. You might also want to give each country shape an appropriate ID (e.g. country name or country code) within Inkscape if they don't already have one already, to save time later.

    Then to turn that into Raphael logic, there's three options:

    1. Use Ready Set Raphael (rsr) which is a free SVG to raphael converter web service. Unless rsr has been updated since I wrote this, you'll probably want to tidy up the resulting code:

      • Putting it all in a set that works, by putting paper.setStart(); before and var world = paper.setFinish(); after the block of paths (don't forget to substitute paper for whatever you're using).
      • Replace-all away all the duplicated .attr()s except for any that set id, then apply attr()s like fill and stroke to the set, rather than each individual element.
      • Store your paths in an object for easy access by name. Makes working with Raphael so much easier.
    2. Use some other SVG to Raphael converter or importer (e.g. this one). I don't know if these are any good, I've personally had better experiences with Ready Set Raphael.

    3. Just do it by hand. This can be as simple as copying and pasting the string from d="lots of co-ordinates" from each SVG path into something like var someCountry = paper.path("lots of co-ordinates"); someSet.push(someCountry);. It will be time consuming since there are so many countries (170 or so) but the extra control might save time in the long run.

    And don't forget to learn from examples.

    0 讨论(0)
提交回复
热议问题