procedure TMainForm.RulerPaint(Sender: TObject);
var
LPt, RPt: TRealPoint;
Dist, V: Double;
Digits: Integer;
Km: Boolean = False;
begin
LPt := MapView.ScreenToLatLon(Ruler.ClientToParent(Point(0, Ruler.Width - 250)));
RPt := MapView.ScreenToLatLon(Ruler.ClientToParent(Point(0, Ruler.Width)));
Dist := mvGeoMath.CalcGeoDistance(LPt.Lat, LPt.Lon, RPt.Lat, RPt.Lon, duMeters);
Km := Dist >= 1000;
if Km then
Dist := Dist * 0.001;
Digits := Trunc(Math.Log10(Dist));
V := Power(10, Digits);
if V + V < Dist then
V := V + V;
Ruler.Width := Round(250 * (V / Dist));
Ruler.Caption := Round(V).ToString + IfThen(Km, ' Km', ' m');
with Ruler do
begin
Canvas.Pen.Color := clBlack;
Canvas.Pen.EndCap := pecFlat;
Canvas.Pen.Width := 3;
Canvas.Polyline([Point(0, 10), Point(0, 1), Point(Width - 1, 1),
Point(Width - 1, 10)]);
end;
end;