I have a map drawn in SVG that I use matrix transformations to rotate based on certain mouse events. When I click on parts of the map, I have annotations that are drawn (in a group element separate from the rotated image).
Right now, I can move those annotations with the map when I drag it by just sending the event on to a JavaScript function to do that shift as a separate action. I’d like to do the same sort of thing when I rotate and scale the underlying map, but am unsure how to proceed – obviously I don’t want to rotate the whole annotation image; I just want to shift it to match the updated map. It seems like maybe I need to figure out how to calculate the effects of the map transformation on the X/Y coordinates of a single point and then apply that calculation to the annotation location. I can’t seem to find any resources that might help in figuring out how to do that.
Here’s a blog article that I wrote talking about how I manipulate the underlying map: http://justindthomas.wordpress.com/category/flower-nfa/
The live example in that article doesn’t work right now (I moved the location of the JavaScript files), but it should give some useful context to my question.
I ended up just doing the math by hand. Here’s the function I used for posterity:
For rotate operations I then used:
For scaling, I used a similar strategy.