Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
120
How to get the pixel coordinates of a SymbolElement?
posted

After adding a SymbolElement to a layer, I'd like to determine the on-screen location of that symbol so that I can draw a line to it from a callout displayed near the map.  Is there a way to convert an origin to pixel coordinates that are relative to the viewport?

Thanks in advance!

  • 120
    Suggested Answer
    posted

    I came up with this solution, which meets my needs (given the location of SymbolElement as "origin"):

    Dim pixelX As Integer = CInt((((origin.X - Map1.WindowRect.Left) / (Map1.WindowRect.Right - Map1.WindowRect.Left)) * ((Map1.Margin.Left + Map1.ActualWidth) - Map1.Margin.Left)) + Map1.Margin.Left)
    Dim pixelY As Integer = CInt((((origin.Y - Map1.WindowRect.Top) / (Map1.WindowRect.Bottom - Map1.WindowRect.Top)) * ((Map1.Margin.Top + Map1.ActualHeight) - Map1.Margin.Top)) + Map1.Margin.Top)