Reputation: 21
I would like to load an external SVG file, and I tried the demo for the svg.import.js plugin.
But it failed to load this file: http://upload.wikimedia.org/wikipedia/commons/5/57/Chess_Maurizio_Monge_Fantasy_wk.svg
I need to load files like this and I cannot modify them.
What is the problem here?
Magnus
Upvotes: 2
Views: 6778
Reputation: 2577
The svg.import.js plugin is obsolete as of SVG.js v2 and up, as stated here:
https://github.com/svgdotjs/svg.import.js#warning
This is now built-in with the draw.svg()
method. Here is an example in the docs:
https://svgdotjs.github.io/importing-exporting
However, you will need to load the SVG data, not a url. You can however load an external file using ajax and pass the file's contents to the SVG.js instance. Something like:
var ajax = new XMLHttpRequest()
ajax.open('GET', 'your/file.svg', true)
ajax.send()
ajax.onload = function(e) {
draw.svg(ajax.responseText)
}
Note: if you are loading files from Inkscape, it's safer to use the Plain SVG format.
Upvotes: 6