add location picker so set receiver location

This commit is contained in:
Jakob Ketterl 2020-03-29 21:40:29 +02:00
parent 29566430a6
commit f0ef5bb371
4 changed files with 37 additions and 2 deletions

View File

@ -5,6 +5,9 @@
<link rel="shortcut icon" type="image/x-icon" href="static/favicon.ico" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="static/css/admin.css" />
<script src="static/lib/jquery-3.2.1.min.js"></script>
<script src="https://unpkg.com/location-picker/dist/location-picker.min.js"></script>
<script src="static/settings.js"></script>
<meta charset="utf-8">
</head>
<body>

View File

@ -14,3 +14,7 @@ body {
.buttons {
text-align: right;
}
.row .map-input {
margin: 15px 15px 0;
}

23
htdocs/settings.js Normal file
View File

@ -0,0 +1,23 @@
$(function(){
$(".map-input").each(function(el) {
var $el = $(this);
var field_id = $el.attr("for");
var $lat = $('#' + field_id + '-lat');
var $lon = $('#' + field_id + '-lon');
$.getScript("https://maps.googleapis.com/maps/api/js?key=" + $el.data("key")).done(function(){
$el.css("height", "200px");
var lp = new locationPicker($el.get(0), {
lat: parseFloat($lat.val()),
lng: parseFloat($lon.val())
}, {
zoom: 7
});
google.maps.event.addListener(lp.map, 'idle', function(event){
var pos = lp.getMarkerPosition();
$lat.val(pos.lat);
$lon.val(pos.lng);
});
});
})
});

View File

@ -1,5 +1,6 @@
from abc import ABC, abstractmethod
from owrx.service import ServiceDetector
from owrx.config import Config
class Input(ABC):
@ -81,13 +82,17 @@ class FloatInput(NumberInput):
class LocationInput(Input):
def render_input(self, value):
# TODO make this work and pretty
return """
<div class="row">
{inputs}
</div>
<div class="row">
<div class="col map-input" data-key="{key}" for="{id}"></div>
</div>
""".format(
inputs="".join(self.render_sub_input(value, id) for id in ["lat", "lon"])
id=self.id,
inputs="".join(self.render_sub_input(value, id) for id in ["lat", "lon"]),
key=Config.get()["google_maps_api_key"],
)
def render_sub_input(self, value, id):