Merge pull request #1406 from AndreasK79/qrb_calc

Qrb calculator added
这个提交包含在:
Andreas Kristiansen 2022-02-16 16:41:25 +01:00 提交者 GitHub
当前提交 9f89696e28
找不到此签名对应的密钥
GPG 密钥 ID: 4AEE18F83AFDEB23
共有 6 个文件被更改,包括 413 次插入0 次删除

查看文件

@ -0,0 +1,65 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
Data lookup functions used within Cloudlog
*/
class Qrbcalc extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('user_model');
if(!$this->user_model->authorize(2)) { $this->session->set_flashdata('notice', 'You\'re not allowed to do that!'); redirect('dashboard'); }
}
public function index() {
$data['page_title'] = "QRB Calculator";
$this->load->model('stations');
$data['station_locator'] = $this->stations->find_gridsquare();
$this->load->view('qrbcalc/index', $data);
}
public function calculate() {
$locator1 = $this->input->post("locator1");
$locator2 = $this->input->post("locator2");
if ($this->session->userdata('user_measurement_base') == NULL) {
$measurement_base = $this->config->item('measurement_base');
}
else {
$measurement_base = $this->session->userdata('user_measurement_base');
}
switch ($measurement_base) {
case 'M':
$var_dist = " miles";
break;
case 'N':
$var_dist = " nautic miles";
break;
case 'K':
$var_dist = " kilometers";
break;
}
$this->load->library('Qra');
$data['result'] = $this->qra->bearing($locator1, $locator2, $measurement_base);
$data['distance'] = $this->qra->distance($locator1, $locator2, $measurement_base) . $var_dist;
$data['bearing'] = $this->qra->get_bearing($locator1, $locator2) . "&#186;";
$latlng1 = $this->qra->qra2latlong($locator1);
$latlng2 = $this->qra->qra2latlong($locator2);
$latlng1[0] = number_format((float)$latlng1[0], 3, '.', '');;
$latlng1[1] = number_format((float)$latlng1[1], 3, '.', '');;
$latlng2[0] = number_format((float)$latlng2[0], 3, '.', '');;
$latlng2[1] = number_format((float)$latlng2[1], 3, '.', '');;
$data['latlng1'] = $latlng1;
$data['latlng2'] = $latlng2;
header('Content-Type: application/json');
echo json_encode($data);
}
}

查看文件

@ -60,6 +60,16 @@ class Qra {
// Return the distance
return $total_distance;
}
/*
* Function returns just the bearing
* Input locator1 and locator2
*/
function get_bearing($tx, $rx) {
$my = qra2latlong($tx);
$stn = qra2latlong($rx);
return get_bearing($my[0], $my[1], $stn[0], $stn[1]);
}
}
function distance($lat1, $lon1, $lat2, $lon2, $unit = 'M') {

查看文件

@ -5,6 +5,8 @@
<script src="<?php echo base_url(); ?>assets/js/bootstrap.bundle.js"></script>
<script src="<?php echo base_url(); ?>assets/js/jquery.jclock.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/leaflet/leaflet.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/leaflet/L.Maidenhead.qrb.js"></script>
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/leaflet/leaflet.geodesic.js"></script>
<script type="text/javascript" src="<?php echo base_url() ;?>assets/js/radiohelpers.js"></script>
<script type="text/javascript" src="<?php echo base_url() ;?>assets/js/darkmodehelpers.js"></script>
<script src="<?php echo base_url(); ?>assets/js/bootstrapdialog/js/bootstrap-dialog.min.js"></script>
@ -421,8 +423,114 @@ document.onkeyup = function(e) {
if (e.altKey && e.which == 76) {
spawnLookupModal();
}
if (e.altKey && e.which == 81) {
spawnQrbCalculator();
}
};
function spawnQrbCalculator() {
$.ajax({
url: base_url + 'index.php/qrbcalc',
type: 'post',
success: function (html) {
BootstrapDialog.show({
title: 'Compute QRB and QTF',
size: BootstrapDialog.SIZE_WIDE,
cssClass: 'lookup-dialog',
nl2br: false,
message: html,
onshown: function(dialog) {
},
buttons: [{
label: 'Close',
action: function (dialogItself) {
dialogItself.close();
}
}]
});
}
});
}
function calculateQrb(form) {
let locator1 = form.locator1.value;
let locator2 = form.locator2.value;
$(".qrbalert").remove();
if (validateLocator(locator1) && validateLocator(locator2)) {
$.ajax({
url: base_url+'index.php/qrbcalc/calculate',
type: 'post',
data: {'locator1': locator1,
'locator2': locator2},
success: function (html) {
var result = "<h5>Negative latitudes are south of the equator, negative longitudes are west of Greenwich. <br/>";
result += ' ' + locator1.toUpperCase() + ' Latitude = ' + html['latlng1'][0] + ' Longitude = ' + html['latlng1'][1] + '<br/>';
result += ' ' + locator2.toUpperCase() + ' Latitude = ' + html['latlng2'][0] + ' Longitude = ' + html['latlng2'][1] + '<br/>';
result += 'Distance between ' + locator1.toUpperCase() + ' and ' + locator2.toUpperCase() + ' is ' + html['distance'] + '.<br />';
result += 'The bearing is ' + html['bearing'] + '.</h5>';
$(".qrbResult").html(result);
newpath(html['latlng1'], html['latlng2'], locator1, locator2);
}
});
} else {
$('.qrbResult').html('<div class="qrbalert alert alert-danger" role="alert">Error in locators. Please check.</div>');
}
}
function validateLocator(locator) {
if(locator.length < 4 && !(/^[a-rA-R]{2}[0-9]{2}[a-xA-X]{0,2}[0-9]{0,2}[a-xA-X]{0,2}$/.test(locator))) {
return false;
}
return true;
}
function newpath(latlng1, latlng2, locator1, locator2) {
// If map is already initialized
var container = L.DomUtil.get('mapqrb');
if(container != null){
container._leaflet_id = null;
}
const map = new L.map('mapqrb').setView([30, 0], 1.5);
var maidenhead = L.maidenheadqrb().addTo(map);
var osmUrl='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
var osmAttrib='Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors';
var osm = new L.TileLayer(osmUrl, {minZoom: 1, maxZoom: 9, attribution: osmAttrib});
var redIcon = L.icon({
iconUrl: icon_dot_url,
iconSize: [10, 10], // size of the icon
});
map.addLayer(osm);
var marker = L.marker([latlng1[0], latlng1[1]], {closeOnClick: false, autoClose: false}).addTo(map).bindPopup(locator1);
var marker2 = L.marker([latlng2[0], latlng2[1]], {closeOnClick: false, autoClose: false}).addTo(map).bindPopup(locator2);
const multiplelines = [];
multiplelines.push(
new L.LatLng(latlng1[0], latlng1[1]),
new L.LatLng(latlng2[0], latlng2[1])
)
const geodesic = L.geodesic(multiplelines, {
weight: 3,
opacity: 1,
color: 'red',
wrap: false,
steps: 100
}).addTo(map);
}
// This displays the dialog with the form and it's where the resulttable is displayed
function spawnLookupModal() {
$.ajax({

查看文件

@ -0,0 +1,25 @@
<form class="form col-md-12" enctype="multipart/form-data">
<div class="form-group row">
<div class="col-md-2 control-label" for="input">Locator 1</div>
<div class="col-md-4">
<input class="form-control input-group-sm" id="locator1" type="text" name="locator1" placeholder="" value="<?php if ($station_locator != "0") echo $station_locator; ?>" aria-label="locator1">
</div>
</div>
<div class="form-group row">
<div class="col-md-2 control-label" for="input">Locator 2</div>
<div class="col-md-4">
<input class="form-control input-group-sm" id="locator2" type="text" name="locator2" placeholder="" aria-label="locator2">
</div>
</div>
<div class="form-group row">
<label class="col-md-2 control-label" for="button1id"></label>
<div class="col-md-4">
<button id="button2id" type="reset" name="button2id" class="btn-sm btn-warning">Reset</button>
<button id="button1id" type="button" onclick="calculateQrb(this.form);" name="button1id" class="btn-sm btn-primary">Calculate</button>
</div>
</div>
</form>
<div class="qrbResult"></div>
<div id="mapqrb" style="Height: 500px"></div>

查看文件

@ -0,0 +1,189 @@
/*
* L.Maidenhead displays a Maidenhead Locator of lines on the map.
*/
L.MaidenheadQrb = L.LayerGroup.extend({
options: {
// Line and label color
color: 'rgba(255, 0, 0, 0.4)',
// Redraw on move or moveend
redraw: 'move'
},
initialize: function (options) {
L.LayerGroup.prototype.initialize.call(this);
L.Util.setOptions(this, options);
},
onAdd: function (map) {
this._map = map;
var grid = this.redraw(map);
this._map.on('viewreset '+ this.options.redraw, function () {
grid.redraw(map);
});
this.eachLayer(map.addLayer, map);
},
onRemove: function (map) {
// remove layer listeners and elements
map.off('viewreset '+ this.options.redraw, this.map);
this.eachLayer(this.removeLayer, this);
},
redraw: function (map) {
var d3 = new Array(20, 10, 10, 1, 1, 1, 1, 1, 1, 1, 1 / 24, 1 / 24, 1 / 24, 1 / 24, 1 / 24, 1 / 240, 1 / 240, 1 / 240, 1 / 240, 1 / 240 / 24, 1 / 240 / 24);
var lat_cor = new Array(0, 8, 8, 8, 8, 1.7, 6, 8, 8, 8, 1.4, 2.5, 3, 3.5, 4, 4, 3.5, 3.5, 3, 1.8, 1.6);
var bounds = map.getBounds();
var zoom = map.getZoom();
var unit = d3[zoom];
var lcor = lat_cor[zoom];
var w = bounds.getWest();
var e = bounds.getEast();
var n = bounds.getNorth();
var s = bounds.getSouth();
if (zoom==1) {var c = 2;} else {var c = 0.1;}
if (n > 85) n = 85;
if (s < -85) s = -85;
var left = Math.floor(w/(unit*2))*(unit*2);
var right = Math.ceil(e/(unit*2))*(unit*2);
var top = Math.ceil(n/unit)*unit;
var bottom = Math.floor(s/unit)*unit;
this.eachLayer(this.removeLayer, this);
for (var lon = left; lon < right; lon += (unit*2)) {
for (var lat = bottom; lat < top; lat += unit) {
var bounds = [[lat,lon],[lat+unit,lon+(unit*2)]];
if (zoom < 2 || zoom > 4) {
this.addLayer(this._getLabel(lon+unit-(unit/lcor),lat+(unit/2)+(unit/lcor*c), map));
}
if (zoom < 3 ) {
this.addLayer(L.rectangle(bounds, {className: 'grid-rectangle', color: this.options.color, weight: 1, fill:false, interactive: false}));
}
if (zoom < 3 || zoom > 5) {
this.addLayer(L.rectangle(bounds, {className: 'grid-rectangle', color: this.options.color, weight: 1, fill:false, interactive: false}));
}
if (zoom < 3 || zoom > 5) {
this.addLayer(this._getLabel(lon+unit-(unit/lcor),lat+(unit/2)+(unit/lcor*c), map));
}
}
}
// Added this to print fields and field name, while still showing worked/confirmed gridsquares
if (zoom < 5 && zoom > 2) {
unit = 10;
var left = Math.floor(w / (unit * 2)) * (unit * 2);
var right = Math.ceil(e / (unit * 2)) * (unit * 2);
var top = Math.ceil(n / unit) * unit;
var bottom = Math.floor(s / unit) * unit;
for (var lon = left; lon < right; lon += (unit * 2)) {
for (var lat = bottom; lat < top; lat += unit) {
var bounds = [[lat, lon], [lat + unit, lon + (unit * 2)]];
this.addLayer(L.rectangle(bounds, {
className: 'grid-rectangle',
color: this.options.color,
weight: 1,
fill: false,
interactive: false
}));
this.addLayer(this._getLabel2(lon + unit - (unit / lcor), lat + (unit / 2) + (unit / lcor * c), map));
}
}
}
return this;
},
_getLabel: function(lon,lat, map) {
var title_size = new Array(0, 10, 14, 16, 6, 13, 14, 16, 24, 36, 12, 14, 20, 36, 60, 12, 20, 36, 60, 12, 24);
var zoom = map.getZoom();
var size = title_size[zoom]+'px';
var title = '<span class="grid-text" style="cursor: default;"><font style="color:'+this.options.color+'; font-size:'+size+'; font-weight: 900; ">' + this._getLocator(lon,lat, map) + '</font></span>';
var myIcon = L.divIcon({className: 'my-div-icon', html: title});
var marker = L.marker([lat,lon], {icon: myIcon}, clickable=false);
return marker;
},
_getLocator: function(lon,lat, map) {
var ydiv_arr=new Array(10, 1, 1/24, 1/240, 1/240/24);
var d1 = "ABCDEFGHIJKLMNOPQR".split("");
var d2 = "ABCDEFGHIJKLMNOPQRSTUVWX".split("");
var d4 = new Array(0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5);
var locator = "";
var x = lon;
var y = lat;
var precision = d4[map.getZoom()];
while (x < -180) {x += 360;}
while (x > 180) {x -=360;}
x = x + 180;
y = y + 90;
locator = locator + d1[Math.floor(x/20)] + d1[Math.floor(y/10)];
for (var i=0; i<4; i=i+1) {
if (precision > i+1) {
rlon = x%(ydiv_arr[i]*2);
rlat = y%(ydiv_arr[i]);
if ((i%2)==0) {
locator += Math.floor(rlon/(ydiv_arr[i+1]*2)) +""+ Math.floor(rlat/(ydiv_arr[i+1]));
} else {
locator += d2[Math.floor(rlon/(ydiv_arr[i+1]*2))] +""+ d2[Math.floor(rlat/(ydiv_arr[i+1]))];
}
}
}
return locator;
},
/*
Need this for the field printing, while showing worked/confirmed grids
*/
_getLabel2: function(lon,lat, map) {
var title_size = new Array(0, 10, 12, 16, 20, 26, 26, 16, 24, 36, 12, 14, 20, 36, 60, 12, 20, 36, 60, 12, 24);
var zoom = map.getZoom();
var size = title_size[zoom]+'px';
var title = '<span class="grid-text" style="cursor: default;"><font style="color:'+this.options.color+'; font-size:'+size+'; font-weight: 900; ">' + this._getLocator2(lon,lat, map) + '</font></span>';
var myIcon = L.divIcon({className: 'my-div-icon', html: title});
var marker = L.marker([lat,lon], {icon: myIcon}, clickable=false);
return marker;
},
/*
Need this for the field printing, while showing worked/confirmed grids
*/
_getLocator2: function(lon,lat, map) {
var ydiv_arr=new Array(10, 1, 1/24, 1/240, 1/240/24);
var d1 = "ABCDEFGHIJKLMNOPQR".split("");
var d2 = "ABCDEFGHIJKLMNOPQRSTUVWX".split("");
var d4 = new Array(0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5);
var locator = "";
var x = lon;
var y = lat;
var precision = d4[map.getZoom()];
while (x < -180) {x += 360;}
while (x > 180) {x -=360;}
x = x + 180;
y = y + 90;
locator = locator + d1[Math.floor(x/20)] + d1[Math.floor(y/10)];
for (var i=0; i<4; i=i+1) {
if (precision > i+1) {
rlon = x%(ydiv_arr[i]*2);
rlat = y%(ydiv_arr[i]);
if ((i%2)==0) {
locator += Math.floor(rlon/(ydiv_arr[i+1]*2)) +""+ Math.floor(rlat/(ydiv_arr[i+1]));
} else {
locator += d2[Math.floor(rlon/(ydiv_arr[i+1]*2))] +""+ d2[Math.floor(rlat/(ydiv_arr[i+1]))];
}
}
}
return locator;
},
});
L.maidenheadqrb = function (options) {
return new L.MaidenheadQrb(options);
};

文件差异因一行或多行过长而隐藏