How to fix a Canvas to a LocationRect (given two Lat-Lon corners)?

2 posts, 0 answers
  1. ezhuang
    ezhuang avatar
    1 posts
    Member since:
    Aug 2015

    Posted 31 Jul 2015 Link to this post

    I have a Canvas, and its NW and SE corners' Lat-Lon (basically a LocationRect). Is there a way to fix this Canvas to the appropriate locations on the map?

    The Canvas will be automatically resized and shifted for any zoom and pan movements on the map control.

  2. Martin Ivanov
    Martin Ivanov avatar
    1442 posts

    Posted 04 Aug 2015 Link to this post

    Hello Eric,

    You can draw the Canvas based on given NW and SE coordinates using the following approach:
    • Convert the Locations to Point objects which represents the Locations' positions on the screen relative to the map. You can do that using the Location's GetPoint) method.
      Location nw = new Location(0, 0);
      Point topLeft = nw.GetPoint(this.RadMap3);
    • Calculate the size of the canvas based on Points' X and Y and set it to the Canvas Element. 
    Here is an example for this approach:
    private void SetCanvasSize()
        var nw = new Location(0, 0);
        var se = new Location(-50, 100);
        var topLeft = nw.GetPoint(this.RadMap3);
        var bottomRight = se.GetPoint(this.RadMap3);
        canvas.Width = bottomRight.X - topLeft.X;
        canvas.Height = bottomRight.Y - topLeft.Y;
        MapLayer.SetLocation(this.canvas, nw);       

    Please give it a try and let me know if it works for you.

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top