[Maps] Distance is now shown in the unit set in user settings

This commit is contained in:
Andreas Kristiansen
2024-07-22 09:06:28 +02:00
parent 2a31612f06
commit e4cf607b30
2 changed files with 38 additions and 6 deletions

View File

@@ -7,6 +7,17 @@
var base_url = "<?php echo base_url(); ?>"; // Base URL
var site_url = "<?php echo site_url(); ?>"; // Site URL
let measurement_base = 'K';
<?php
if ($this->session->userdata('user_measurement_base') == NULL) {
?>
measurement_base = '<?php echo $this->config->item('measurement_base'); ?>';
<?php }
else { ?>
measurement_base = '<?php echo $this->session->userdata('user_measurement_base'); ?>';
<?php }
?>
var icon_dot_url = "<?php echo base_url();?>assets/images/dot.png";
@@ -134,7 +145,7 @@ if($this->session->userdata('user_id') != null) {
<?php if ($this->config->item('special_callsign') == true && $this->uri->segment(1) == "dashboard") { ?>
<script type="text/javascript" src="<?php echo base_url() ;?>assets/js/sections/operator.js"></script>
<script>
<?php
<?php
# Set some variables for better readability
$op_call = $this->session->userdata('operator_callsign');
$account_call = $this->session->userdata('user_callsign');
@@ -142,14 +153,14 @@ if($this->session->userdata('user_id') != null) {
// JS variable which is used in operator.js
let sc_account_call = '<?php echo $account_call; ?>'
<?php
<?php
# if the operator call and the account call is the same we show the dialog (except for admins!)
if ($op_call == $account_call && $user_type != '99') { ?>
// load the dialog with javascript
displayOperatorDialog();
<?php } ?>
</script>
<?php } ?>

View File

@@ -69,8 +69,29 @@ function onMapMove(event) {
$('#locator').html(locator);
var distance = bearingDistance(homegrid, locator);
let unit;
switch (measurement_base) {
case 'M':
distance.distance = distance.distance * 3959;
unit = 'mi';
break;
case 'K':
distance.distance = distance.distance * 6371;
unit = 'km';
break;
case 'N':
distance.distance = distance.distance * 3440;
unit = 'nmi';
break;
default:
distance.distance = distance.distance * 6371;
unit = 'km';
break;
}
$('#bearing').html(distance.deg + ' deg');
$('#distance').html(Math.round(distance.km * 10) / 10 + ' km');
$('#distance').html(Math.round(distance.distance * 10) / 10 + ' ' +unit);
};
function onMapClick(event) {
@@ -140,7 +161,7 @@ const bearingDistance = (from, to) => {
}
return {
km: b * 6371,
distance: b,
deg: calcAngle(fromCoords, toCoords)
};
};