Distance shown

3 posts, 2 answers
  1. Answer
    Rich
    Rich avatar
    22 posts
    Member since:
    Feb 2012

    Posted 21 Jan 2014 Link to this post

    Is there a way to find out the scale of the map? For instance how many miles across the map as shown.

    Thanks.
  2. Answer
    Rich
    Rich avatar
    22 posts
    Member since:
    Feb 2012

    Posted 22 Jan 2014 Link to this post

    Hello,

    The map extent() method gives us the outermost north-west and south-east locations. This can be used to calculate the total distance and map scale (if the screen dpi is known).
    This functionality will be readily available in future versions, but for now we need to make the calculations manually:

    function distance(a, b) {    
          // See:
          // http://en.wikipedia.org/wiki/Haversine_formula
          // http://www.movable-type.co.uk/scripts/latlong.html
          
          var R = 6371; // km
          var dLat = rad(b.lat - a.lat);
          var dLon = rad(b.lng - a.lng);
          var latA = rad(a.lat);
          var latB = rad(b.lat);
          
          var h = Math.sin(dLat/2) * Math.sin(dLat/2) +
                  Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(latA) * Math.cos(latB); 
          var c = 2 * Math.atan2(Math.sqrt(h), Math.sqrt(1-h)); 
          var d = R * c;
          
          return d;
        }
        
        function printScale(map) {      
          var map = $("#map").data("kendoMap");
          var extent = map.extent();
          var nw = extent.nw;
          var ne = new Location(nw.lat, extent.se.lng);
          
          $("#status").html(kendo.format("E-W: {0:N0} m", distance(nw, ne)));
        }


    Live demo

    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. Rich
    Rich avatar
    22 posts
    Member since:
    Feb 2012

    Posted 22 Jan 2014 Link to this post

    That is awesome. Thanks that was more than I expected. Also showed me a few things on I didn't know about Kendo Map.

    Rich.
Back to Top