openwebrx-clone/htdocs/lib/settings/MapInput.js

23 lines
796 B
JavaScript
Raw Normal View History

2021-02-15 19:19:43 +00:00
$.fn.mapInput = function() {
this.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);
});
});
});
};