1 // GPS status and window
3 // Requires js-storage and jquery be loaded prior
5 // dragorn@kismetwireless.net
6 // MIT/GPL License (pick one); the web ui code is licensed more
7 // freely than GPL to reflect the generally MIT-licensed nature
8 // of the web/jquery environment
12 var local_uri_prefix = "";
13 if (typeof(KISMET_URI_PREFIX) !== 'undefined')
14 local_uri_prefix = KISMET_URI_PREFIX;
20 var options = base_options;
32 // Last time from the server
39 var gps_popup_content =
41 style: 'padding: 2px;'
46 style: 'padding-bottom: 2px;'
56 $('<td>').html('Time')
67 $('<td>').html('Location')
78 $('<td>').html('Speed')
89 $('<td>').html('Heading')
100 $('<td>').html('Altitude')
110 // Close the alert panel if we click outside it
111 var close_dialog_outside = function(e) {
113 (e != null && $(e.target).closest('#gpsdialog').length == 0)) {
115 if (dialog != null) {
120 // Remove the handler
121 $('body').off('click', close_dialog_outside);
123 // Don't pass the click on
124 e.stopImmediatePropagation();
128 var open_dialog = function(e) {
129 if (dialog != null) {
130 close_dialog_outside(e);
132 e.stopImmediatePropagation();
136 var fullscreen = false;
139 //var nominal_h = ($(window).height() / 3) * 2;
144 if ($(window).width() < 450) {
145 nominal_w = $(window).width() - 5;
146 nominal_h = $(window).height() - 5;
154 "autoposition": "RIGHT"
159 // Position under the element
160 var off_y = (nominal_h / 2) + (element.outerHeight() / 2) + 3;
162 // left-ish of the icon
163 var off_x = (nominal_w / 5) * 2;
166 // Where the outer border lands
167 var outerborder = off_x + (nominal_w / 2);
178 if (last_gps == null ||
180 (last_gps['kismet.common.location.valid'] == 0) ||
181 (last_gps['kismet.common.location.fix'] < 2))) {
182 $('#gpsstatus', gps_popup_content).html('No GPS available');
183 $('#time', gps_popup_content).html('n/a');
184 $('#location', gps_popup_content).html('n/a');
185 $('#speed', gps_popup_content).html('n/a');
186 $('#heading', gps_popup_content).html('n/a');
187 $('#altitude', gps_popup_content).html('n/a');
191 $('.kg-header-close', gps_popup_content).show();
201 content: gps_popup_content,
204 $("body").on("click", close_dialog_outside);
206 e.stopImmediatePropagation();
209 var gps_refresh = function(data) {
210 if (kismet.getStorage('kismet.ui.gps.icon') === 'False') {
216 if (kismet.getStorage('kismet.ui.gps.text') === 'False') {
222 data = kismet.sanitizeObject(data);
228 d = new Date(last_gps['kismet.common.location.time_sec']*1000).toISOString();
233 if (last_gps['kismet.common.location.valid'] != 0 &&
234 last_gps['kismet.common.location.fix'] >= 2) {
235 if (last_gps['kismet.common.location.fix'] == 2) {
236 $('#gpsstatus', gps_popup_content).html('GPS locked (2d)');
237 $('#altitude', gps_popup_content).html('n/a');
239 $('#gpsstatus', gps_popup_content).html('GPS locked (3d)');
240 $('#altitude', gps_popup_content).html(kismet_ui.renderDistance(last_gps['kismet.common.location.alt'] / 1000, 0));
243 $('#time', gps_popup_content).html(d);
244 $('#location', gps_popup_content).html(last_gps['kismet.common.location.geopoint'][1] + " x " + last_gps['kismet.common.location.geopoint'][0]);
245 $('#speed', gps_popup_content).html(kismet_ui.renderSpeed(last_gps['kismet.common.location.speed']));
246 $('#heading', gps_popup_content).html(last_gps['kismet.common.location.heading']);
248 $('#gpsstatus', gps_popup_content).html('No GPS available');
249 $('#time', gps_popup_content).html('n/a');
250 $('#location', gps_popup_content).html('n/a');
251 $('#speed', gps_popup_content).html('n/a');
252 $('#heading', gps_popup_content).html('n/a');
253 $('#altitude', gps_popup_content).html('n/a');
256 if (last_gps == null ||
257 (last_gps != null && last_gps['kismet.common.location.valid'] == 0) ||
258 (last_gps != null && last_gps['kismet.common.location.fix'] < 2)) {
259 gpsicon.removeClass('kg-icon-3d');
260 gpsicon.removeClass('kg-icon-2d');
261 element.tooltipster('content', 'GPS connection lost...');
263 gpstext.addClass('gpstext_lost');
264 gpstext.html("<b>No GPS</b>");
267 } else if (last_gps['kismet.common.location.fix'] == 2) {
268 gpsicon.removeClass('kg-icon-3d');
269 gpsicon.addClass('kg-icon-2d');
270 element.tooltipster('content', 'GPS fix' + last_gps['kismet.common.location.geopoint'][1] + ' x ' +
271 last_gps['kismet.common.location.geopoint'][0]);
273 gpstext.removeClass('gpstext_lost');
274 gpstext.html(kismet.censorLocation(last_gps['kismet.common.location.geopoint'][1]) + " x " +
275 kismet.censorLocation(last_gps['kismet.common.location.geopoint'][0]));
276 } else if (last_gps['kismet.common.location.fix'] == 3) {
277 gpsicon.removeClass('kg-icon-2d');
278 gpsicon.addClass('kg-icon-3d');
279 element.tooltipster('content', 'GPS fix ' +
280 last_gps['kismet.common.location.geopoint'][1] + ' x ' +
281 last_gps['kismet.common.location.geopoint'][0] + ' ' +
282 kismet_ui.renderDistance(last_gps['kismet.common.location.alt'] / 1000, 0));
284 gpstext.removeClass('gpstext_lost');
285 gpstext.html(kismet.censorLocation(last_gps['kismet.common.location.geopoint'][1]) + " x " +
286 kismet.censorLocation(last_gps['kismet.common.location.geopoint'][0]));
290 $.fn.gps = function(data, inopt) {
291 // Get the stored value if one exists
292 storage = Storages.localStorage;
296 element.addClass('kg-top-icon');
298 options = $.extend(base_options, inopt);
300 gpsicon = $('i.icon', this);
301 if (gpsicon.length == 0) {
303 class: "icon fa fa-crosshairs kg-icon-base"
307 gpstext = $('span.gpstext', this);
308 if (gpstext.length == 0) {
309 gpstext = $('<span>', {
314 gpsclick = $('a.gpsbutton', this);
316 if (gpsclick.length != 0) {
320 gpsclick = $('<a>', {
324 .on('click', open_dialog);
326 if (kismet.getStorage('kismet.ui.gps.icon') === 'False') {
330 if (kismet.getStorage('kismet.ui.gps.text') === 'False') {
334 gpsclick.append(gpstext);
335 gpsclick.append(gpsicon);
337 element.append(gpsclick);
339 element.tooltipster({
343 $.get(local_uri_prefix + "gps/location.json")
344 .done(function(data) {
348 kismet_ui_base.SubscribeEventbus("GPS_LOCATION", [], function(data) {