diff --git a/tabs/gps.js b/tabs/gps.js index f26c16b8..60d3a13a 100644 --- a/tabs/gps.js +++ b/tabs/gps.js @@ -15,6 +15,18 @@ TABS.gps.initialize = function (callback) { MSP.send_message(MSP_codes.MSP_STATUS, false, false, load_html); + function set_online(){ + $('#connect').hide(); + $('#waiting').show(); + $('#loadmap').show(); + } + + function set_offline(){ + $('#connect').show(); + $('#waiting').hide(); + $('#loadmap').hide(); + } + function process_html() { // translate to user-selected languageconsole.log('Online'); localize(); @@ -54,13 +66,29 @@ TABS.gps.initialize = function (callback) { $('td', row).eq(1).text(GPS_DATA.quality[i]); $('td', row).eq(2).find('progress').val(GPS_DATA.cno[i]); } + + var message = { + action: 'center', + lat: lat, + lon: lon, + }; + + var frame = document.getElementById('map'); + if(lat != 0 && lon != 0){ + frame.contentWindow.postMessage(message, '*'); + $('#waiting').hide(); + $('#loadmap').show(); + }else{ + $('#loadmap').hide(); + $('#waiting').show(); + } } // enable data pulling GUI.interval_add('gps_pull', function gps_update() { // avoid usage of the GPS commands until a GPS sensor is detected for targets that are compiled without GPS support. if (!have_sensor(CONFIG.activeSensors, 'gps')) { - return; + //return; } get_raw_gps_data(); @@ -75,30 +103,19 @@ TABS.gps.initialize = function (callback) { //check for internet connection on load if (navigator.onLine) { console.log('Online'); - $('#connect').hide(); - $('#waiting').show(); - $('#loadmap').show(); - + set_online(); } else { console.log('Offline'); - $('#connect').show(); - $('#waiting').hide(); - $('#loadmap').hide(); - + set_offline(); } $("#check").on('click',function(){ if (navigator.onLine) { console.log('Online'); - $('#connect').hide(); - $('#waiting').show(); - $('#loadmap').show(); - + set_online(); } else { console.log('Offline'); - $('#connect').show(); - $('#waiting').hide(); - $('#loadmap').hide(); + set_offline(); } }); @@ -107,17 +124,17 @@ TABS.gps.initialize = function (callback) { $('#zoom_in').click(function() { console.log('zoom in'); var message = { - action: 'zoom_in', - }; - frame.contentWindow.postMessage(message, '*'); + action: 'zoom_in', + }; + frame.contentWindow.postMessage(message, '*'); }); $('#zoom_out').click(function() { console.log('zoom out'); - var message = { - action: 'zoom_out' - }; - frame.contentWindow.postMessage(message, '*'); + var message = { + action: 'zoom_out' + }; + frame.contentWindow.postMessage(message, '*'); }); GUI.content_ready(callback); diff --git a/tabs/map.html b/tabs/map.html index 5597dd90..2e8ba73c 100644 --- a/tabs/map.html +++ b/tabs/map.html @@ -29,6 +29,8 @@ zoom--; map.setZoom(zoom); break; + case 'center': + map.setCenter(new google.maps.LatLng(e.data.lat, e.data.lon)); } } catch (e) { console.log('message error');