Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6059633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:44:00+00:00 2026-05-23T08:44:00+00:00

I have a map drawn in SVG that I use matrix transformations to rotate

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:44:01+00:00Added an answer on May 23, 2026 at 8:44 am

    I ended up just doing the math by hand. Here’s the function I used for posterity:

    getRadiusAngle: function(referenceX, referenceY, centerX, centerY) {                
        var width = centerX - referenceX;
        var height = centerY - referenceY;
        var angle, radius;
    
        if(centerY > referenceY) {
            if(centerX > referenceX) {
                angle = Math.PI - Math.atan(Math.abs(height/width));
                radius = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
            } else if (centerX < referenceX) {
                angle = Math.atan(Math.abs(height/width));
                radius = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
            } else if (centerX == referenceX) {
                angle = Math.PI / 2;
                radius = height;
            }
        } else if(centerY < referenceY) {
            if(centerX > referenceX) {
                angle = Math.PI + Math.atan(Math.abs(height/width));
                radius = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
            } else if (centerX < referenceX) {
                angle = (2 * Math.PI) - Math.atan(Math.abs(height/width));
                radius = Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
            } else if (centerX == referenceX) {
                angle = Math.PI * 1.5;
                radius = Math.abs(height);
            }
        } else if(centerY == referenceY) {
            if(centerX > referenceX) {
                angle = Math.PI;
                radius = width;
            } else if (centerX < referenceX) {
                angle = 0;
                radius = Math.abs(width);
            } else if(centerX == referenceX) {
                angle = 0;
                radius = 0;
            }
        }
    
        return({
            "radius": radius, 
            "angle": angle
        })
    },
    

    For rotate operations I then used:

    var calcwidth = annotations[i].getAttribute("calcwidth");
    var matrix = annotations[i].getCTM();
    
    var referenceX = (matrix.e + (calcwidth/2));
    var referenceY = (matrix.f + 32);
    
    var ra = this.getRadiusAngle(referenceX, referenceY, pointerX, pointerY);
    
    var current_angle = ra.angle;
    var radius = ra.radius
    
    var newX, newY;
    if(radius == 0) {
        newX = matrix.e;
        newY = matrix.f;
    } else {      
        var new_angle = current_angle + -radians;  
    
        newX = (pointerX + (radius * Math.cos(new_angle))) - (calcwidth/2);
        newY = (pointerY + -(radius * Math.sin(new_angle))) - 32;
    }
    
    annotations[i].setAttribute("transform", "translate(" 
        + newX + " " + newY + ")");
    

    For scaling, I used a similar strategy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a map for my game, I have a script that on a
I want to have a map that has a homogeneous key type but heterogeneous
I have a Google Map that suddenly stopped working for no apparent reason (I
I have the following: An image - a hand drawn map - of an
basically I am trying to model some map brushes that have the following format:
I have made a map overlay class and have overridden the onTouchEvent method that
I have unsorted map of key value pairs. input = { xa => xavalue,
I have a Map which is to be modified by several threads concurrently. There
I have a map defined like this std::map<some_key_type, std::string::iterator> mIteratorMap; And a huge string
I have a map of a building and I'd like to programmatically highlight specific

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.