mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Show correct miles value on the map
This commit is contained in:
parent
b3e8155e43
commit
042696caeb
3 changed files with 13 additions and 6 deletions
File diff suppressed because one or more lines are too long
|
|
@ -41,7 +41,8 @@ class MapController < ApplicationController
|
||||||
distance_km = Geocoder::Calculations.distance_between(
|
distance_km = Geocoder::Calculations.distance_between(
|
||||||
[_1[0], _1[1]], [_2[0], _2[1]], units: :km
|
[_1[0], _1[1]], [_2[0], _2[1]], units: :km
|
||||||
)
|
)
|
||||||
total_distance_meters += distance_km * 1000 # Convert km to meters
|
|
||||||
|
total_distance_meters += distance_km
|
||||||
end
|
end
|
||||||
|
|
||||||
total_distance_meters.round
|
total_distance_meters.round
|
||||||
|
|
|
||||||
|
|
@ -122,10 +122,16 @@ export default class extends BaseController {
|
||||||
},
|
},
|
||||||
onAdd: (map) => {
|
onAdd: (map) => {
|
||||||
const div = L.DomUtil.create('div', 'leaflet-control-stats');
|
const div = L.DomUtil.create('div', 'leaflet-control-stats');
|
||||||
const distance = this.element.dataset.distance || '0';
|
let distance = parseInt(this.element.dataset.distance) || 0;
|
||||||
const pointsNumber = this.element.dataset.points_number || '0';
|
const pointsNumber = this.element.dataset.points_number || '0';
|
||||||
|
|
||||||
|
// Convert distance to miles if user prefers miles (assuming backend sends km)
|
||||||
|
if (this.distanceUnit === 'mi') {
|
||||||
|
distance = distance * 0.621371; // km to miles conversion
|
||||||
|
}
|
||||||
|
|
||||||
const unit = this.distanceUnit === 'mi' ? 'mi' : 'km';
|
const unit = this.distanceUnit === 'mi' ? 'mi' : 'km';
|
||||||
div.innerHTML = `${distance} ${unit} | ${pointsNumber} points`;
|
div.innerHTML = `${distance.toFixed(1)} ${unit} | ${pointsNumber} points`;
|
||||||
div.style.backgroundColor = 'white';
|
div.style.backgroundColor = 'white';
|
||||||
div.style.padding = '0 5px';
|
div.style.padding = '0 5px';
|
||||||
div.style.marginRight = '5px';
|
div.style.marginRight = '5px';
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue