[Fixes #98] Automatic calculation of grid location
parent
059c7687ad
commit
15b42b78a3
|
@ -9,7 +9,7 @@ class AntennaAdmin(admin.ModelAdmin):
|
|||
|
||||
|
||||
class StationAdmin(admin.ModelAdmin):
|
||||
list_display = ('name', 'owner', 'lng', 'lat', 'location')
|
||||
list_display = ('name', 'owner', 'lng', 'lat', 'qthlocator')
|
||||
|
||||
|
||||
class SatelliteAdmin(admin.ModelAdmin):
|
||||
|
|
|
@ -7,5 +7,5 @@ class StationForm(forms.ModelForm):
|
|||
class Meta:
|
||||
model = Station
|
||||
fields = ['name', 'image', 'alt',
|
||||
'lat', 'lng', 'antenna', 'online']
|
||||
'lat', 'lng', 'qthlocator', 'antenna', 'online']
|
||||
image = forms.ImageField(required=False)
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('base', '0014_auto_20150209_0846'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='station',
|
||||
name='qthlocator',
|
||||
field=models.CharField(max_length=255, null=True, blank=True),
|
||||
preserve_default=True,
|
||||
),
|
||||
]
|
|
@ -37,6 +37,7 @@ class Station(models.Model):
|
|||
MinValueValidator(-90)])
|
||||
lng = models.FloatField(validators=[MaxValueValidator(180),
|
||||
MinValueValidator(-180)])
|
||||
qthlocator = models.CharField(max_length=255, null=True, blank=True)
|
||||
location = models.CharField(max_length=255, null=True, blank=True)
|
||||
antenna = models.ManyToManyField(Antenna, null=True, blank=True,
|
||||
help_text=('If you want to add a new Antenna '
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/* This script calculates the grid locator based on the Maidenhead
|
||||
* Locator System. It references the longitude and latitude fields
|
||||
* in the Station Add/Edit view, calculating the grid square and adding
|
||||
* that to the location field iff both lat/lon values exist and are
|
||||
* valid. -cshields
|
||||
*/
|
||||
function gridsquare() {
|
||||
var FIELD_IDENTIFIERS = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'H', 'K', 'L', 'M',
|
||||
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
|
||||
|
||||
// starting points, the fields from the Station form
|
||||
var latitude = $('#lat').val();
|
||||
var longitude = $('#lng').val();
|
||||
|
||||
// this gets called any time one of the two lat/long fields
|
||||
// have been changed. We only need to do the work if both
|
||||
// fields have been entered with a proper entry, otherwise
|
||||
// skip the cycles
|
||||
if ((latitude !== '') &&
|
||||
(latitude <= 90) &&
|
||||
(latitude >= -90) &&
|
||||
(longitude !== '') &&
|
||||
(longitude <= 180) &&
|
||||
(longitude >= -180)) {
|
||||
|
||||
// to figure out the individual grid identifiers we make a mess
|
||||
// of the longitude and latitude
|
||||
var working_lon = ((+longitude + 180) % 20);
|
||||
var lon_field = FIELD_IDENTIFIERS[Math.floor((+longitude + 180) / 20)];
|
||||
var lon_square = Math.floor(working_lon / 2);
|
||||
working_lon = Math.floor((working_lon % 2) * 12);
|
||||
var lon_subsquare = FIELD_IDENTIFIERS[working_lon];
|
||||
|
||||
var working_lat = ((+latitude + 90) % 10);
|
||||
var lat_field = FIELD_IDENTIFIERS[Math.floor((+latitude + 90) / 10)];
|
||||
var lat_square = Math.floor(working_lat);
|
||||
working_lat = Math.floor((working_lat - Math.floor(working_lat)) * 24);
|
||||
var lat_subsquare = FIELD_IDENTIFIERS[working_lat];
|
||||
|
||||
// write the result, like EM69uf, to qthlocator field
|
||||
var qthlocator = $('#qthlocator');
|
||||
qthlocator.val('' + lon_field + lat_field + lon_square + lat_square +
|
||||
lon_subsquare.toLowerCase() + lat_subsquare.toLowerCase());
|
||||
}
|
||||
}
|
|
@ -27,16 +27,26 @@
|
|||
<span class="label label-default">Owner</span>
|
||||
<span class="gs-front-data">
|
||||
<a href="{% url 'users:view_user' username=station.owner.username %}">
|
||||
{{ station.owner.get_full_name }}
|
||||
{{ station.owner.displayname }}
|
||||
</a>
|
||||
</span>
|
||||
</div>
|
||||
<div class="gs-front-line">
|
||||
<span class="label label-default">Location</span>
|
||||
<span class="gs-front-data">
|
||||
{{ station.location }}
|
||||
</span>
|
||||
</div>
|
||||
{% if station.qthlocator %}
|
||||
<div class="gs-front-line">
|
||||
<span class="label label-default">QTH Locator</span>
|
||||
<span class="gs-front-data">
|
||||
{{ station.qthlocator }}
|
||||
</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if station.location %}
|
||||
<div class="gs-front-line">
|
||||
<span class="label label-default">Location</span>
|
||||
<span class="gs-front-data">
|
||||
{{ station.location }}
|
||||
</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="gs-front-line">
|
||||
<span class="label label-default">Coordinates</span>
|
||||
<span class="gs-front-data">
|
||||
|
@ -96,4 +106,5 @@
|
|||
{% block javascript %}
|
||||
<script src="{% static 'js/lib/mapbox.js' %}"></script>
|
||||
<script src="{% static 'js/station_view.js' %}"></script>
|
||||
<script src="{% static 'js/gridsquare.js' %}"></script>
|
||||
{% endblock javascript %}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{% extends "base.html" %}
|
||||
{% load tags %}
|
||||
{% load staticfiles %}
|
||||
|
||||
{% block title %}Ground Stations{% endblock %}
|
||||
|
||||
|
@ -17,6 +18,9 @@
|
|||
<thead>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
{% if station.qthlocator %}
|
||||
<th>qthlocator</th>
|
||||
{% endif %}
|
||||
<th>Location</th>
|
||||
<th>Altitude</th>
|
||||
<th>Antenna</th>
|
||||
|
@ -42,6 +46,11 @@
|
|||
{{ station.name }}
|
||||
</a>
|
||||
</td>
|
||||
{% if station.qthlocator %}
|
||||
<td title="{{ station.lat|floatformat:-3 }}, {{ station.lng|floatformat:-3 }}">
|
||||
{{ station.qthlocator }}
|
||||
</td>
|
||||
{% endif %}
|
||||
{% if station.location %}
|
||||
<td title="{{ station.lat|floatformat:-3 }}, {{ station.lng|floatformat:-3 }}">
|
||||
{{ station.location }}
|
||||
|
@ -70,3 +79,7 @@
|
|||
<!-- Station Modal -->
|
||||
{% include 'includes/station_edit.html' %}
|
||||
{% endblock content %}
|
||||
|
||||
{% block javascript %}
|
||||
<script src="{% static 'js/gridsquare.js' %}"></script>
|
||||
{% endblock javascript %}
|
||||
|
|
|
@ -38,23 +38,24 @@
|
|||
<div class="form-group">
|
||||
<label for="lat" class="col-sm-2 control-label">Latitude</label>
|
||||
<div class="col-sm-10">
|
||||
<input value="{{ form.lat.value|default_if_none:"" }}" id="lat" type="text" class="form-control" name="lat" placeholder="Latitude">
|
||||
<input value="{{ form.lat.value|default_if_none:"" }}" id="lat" type="text" class="form-control" name="lat" placeholder="Latitude" onchange="gridsquare()">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="lng" class="col-sm-2 control-label">Longtitude</label>
|
||||
<div class="col-sm-10">
|
||||
<input value="{{ form.lng.value|default_if_none:"" }}" id="lng" type="text" class="form-control" name="lng" placeholder="Longtitude">
|
||||
<input value="{{ form.lng.value|default_if_none:"" }}" id="lng" type="text" class="form-control" name="lng" placeholder="Longtitude" onchange="gridsquare()">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="location" class="col-sm-2 control-label">Location</label>
|
||||
<label for="qthlocator" class="col-sm-2 control-label">QTH Locator</label>
|
||||
<div class="col-sm-10">
|
||||
<input class="form-control"
|
||||
id="location"
|
||||
id="qthlocator"
|
||||
type="text"
|
||||
placeholder="Geocoded location here"
|
||||
disabled>
|
||||
name="qthlocator"
|
||||
value="{{ form.qthlocator.value|default_if_none:"Geocoded gridsquare here" }}"
|
||||
readonly>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
@ -73,7 +74,7 @@
|
|||
<div class="col-sm-offset-2 col-sm-10">
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" name="online" {% if form.online.value %}checked="True"{% endif %}"> Online Ground Station
|
||||
<input type="checkbox" name="online" {% if form.online.value %}checked="True"{% endif %}> Online Ground Station
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -163,3 +163,7 @@
|
|||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
||||
{% block javascript %}
|
||||
<script src="{% static 'js/gridsquare.js' %}"></script>
|
||||
{% endblock javascript %}
|
Loading…
Reference in New Issue