This is a migrated thread and some comments may be shown as answers.

Is it possible to add a map scale?

2 Answers 108 Views
Map
This is a migrated thread and some comments may be shown as answers.
ITServices
Top achievements
Rank 1
ITServices asked on 04 Nov 2014, 09:26 AM
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 Answers, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 06 Nov 2014, 10:20 AM
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!
 
0
ITServices
Top achievements
Rank 1
answered on 09 Dec 2014, 05:04 PM
Sorry for the delayed answer, but it works perfectly.

Thanks a lot.
Tags
Map
Asked by
ITServices
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
ITServices
Top achievements
Rank 1
Share this question
or