Is it possible to add a map scale?

3 posts, 0 answers
  1. Nick
    Nick avatar
    15 posts
    Member since:
    Nov 2007

    Posted 04 Nov 2014 Link to this post

    Hello guys, I was just wondering if it is possible to add the typical map scale on one of the map corners, showing to the user the current scale used on the map.

    This scale would have change depending on the map zoom level.

    Do you have something similar to this functionality?

    Thanks a lot.

    Best Regards.
  2. T. Tsonev
    Admin
    T. Tsonev avatar
    2772 posts

    Posted 06 Nov 2014 Link to this post

    Hello,

    There's no built in scale control, but the Map provides with the basic info via the extent() method and the Location class.
    For example, we can calculate the total distance (in m) visible across the map mid-line:
    var extent = map.extent();
    var center = map.center();

    var eastCenter = new Location(center.lat, extent.nw.lng);
    var westCenter = new Location(center.lat, extent.se.lng);
    var distance = eastCenter.distanceTo(westCenter);

    We use the midline, as distance can vary wildly because of the curvature of the earth.
    See Understanding Scale and Resolution on (MSDN).

    From there the map scale (m/px) is:
    var width = map.element.width();
    var scale = Math.round(distance / width);


    I've prepared a snippet that demonstrates how this can be displayed on the map.

    Please, file a request for a built-in map scale on our UserVoice portal if you have minute.
    This will help us gauge the overall interest and prioritize.

    I hope this helps.

    Regards,
    T. Tsonev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
  4. Nick
    Nick avatar
    15 posts
    Member since:
    Nov 2007

    Posted 09 Dec 2014 in reply to T. Tsonev Link to this post

    Sorry for the delayed answer, but it works perfectly.

    Thanks a lot.
Back to Top