I'm loading a couple of SVG images and everything works except for one of those SVG files because I need to use it 3 times, the second time I try to use it I get this error:
TypeError: image.select(...) is null
So image.select("path") stops working after I've used this path once.
function other(x, y, active, style) {
var image = externalData["other"];
var shape = image.select("path").attr(style);
shape.attr({"opacity": active});
if (style.opacity != undefined) {
shape.attr({"opacity": style.opacity});
}
var scale = 0.9;
var w = shape.getBBox().width*scale;
var h = shape.getBBox().height*scale;
var x = x-w/2;
var y = y-(86*scale)/2;
var m = new Snap.Matrix();
m.translate(x, y);
m.scale(scale, scale);
shape.transform(m);
return shape
}
How can I make image.select("path") work every time and when it's done have the path visible in 3 places on the canvas?
Also, I need to load the all the SVG files before I execute the rest of the Snap code.
One solution might be to load the SVG three individual times and have externalData["other1"], externalData["other2"], externalData["other3"]. But I'd like my "other" function to access the path through a single interface (externalData["other"]), and even though right now I only have to use it 3 times I might in the future need to use it 4 times or 16 times, etc.
So how can I create a "new instance" of the Snap load data on each use of its path so it works every time?
I'm using Snap.svg 0.3.0
Snap load code:
var i = 0;
var data = ["/dep/svg/ruach.svg",
"/dep/svg/jechidah.svg",
"/dep/svg/other.svg"];
function loadImage(link) {
Snap.load(link, function(image) {
var linkSplit = link.split("/");
var filename = linkSplit[linkSplit.length-1];
var label = filename.split(".")[0];
externalData[label] = image;
i += 1;
if (i == data.length) tree("#flower");
});
}
for (link in data) {
loadImage(data[link]);
}