Hi!
I'm not too good at explaining things and I'm not an English native speaker, so I hope my explanation is not too confusing.
I'm trying to create a handler for external svg that I have loaded. There will be 4 handler on every corner of it: Delete, Move, Rotate, and Resize. Pretty much like this:
http://take.ms/tWTBA
The first thing I do is to create the first handler on top left corner. I load the main image from external svg:
var mainsvg = Snap("#main-svg");
Snap.load("tablet.svg", function (loadedFragment) {
var g = loadedFragment.select("g");
g.transform(new Snap.matrix().translate(50,50));
mainsvg.append(g);
After that, I created a path:
var path1 = mainsvg.path("m 262.15788,215.18241 -20,-20 14,0 0,-24 -24,0 0,14 -20,-20 20,-20 0,14 24,0 0,-24 -14,0 20,-20 20,20 -14,0 0,24 24,0 0,-14 20,20 -20,20 0,-14 -24,0 0,24 14,0 -20,20 z");
Next, I scale it:
path1.transform(new Snap.matrix().scale(0.2));
Lastly, I count the distance and translate it to top left of the main image:
var distancePathX = g.getBBox().x - 20 - path1.getBBox().x; //20 is the fixed width of the handler
var distancePathY = g.getBBox().y - 20 - path1.getBBox().y; // 20 is the fixed height of the handler
path1.transform(new Snap.matrix().translate(distancePathX, distancePathY));
Only the last transform has the effect. It is translated, but not scaled. Did I use it incorrectly?
By the way, it works if I do it like this:
path1.transform(new Snap.matrix().scale(0.2).translate(distancePathX, distancePathY));
BUT unfortunately, I need to count the distance AFTER it is scaled. By using above code, I can't count the distances.
Does anyone have any idea how to solve this problem?