Skip to content

Commit 0669e78

Browse files
xssfoxTheSkorm
authored andcommitted
blueman group (update position even if chase car mode not active #396)
1 parent ac7e6c6 commit 0669e78

File tree

2 files changed

+79
-88
lines changed

2 files changed

+79
-88
lines changed

js/app.js

Lines changed: 75 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -355,89 +355,83 @@ var positionUpdateHandle = function(position) {
355355
}
356356
}
357357

358-
//navigator.geolocation.getCurrentPosition(function(position) {
359-
var lat = position.coords.latitude;
360-
var lon = position.coords.longitude;
361-
var alt = (position.coords.altitude) ? position.coords.altitude : 0;
362-
var accuracy = (position.coords.accuracy) ? position.coords.accuracy : 0;
363-
var speed = (position.coords.speed) ? position.coords.speed : 0;
364-
365-
// constantly update 'last updated' field, and display friendly time since last update
366-
if(!GPS_ts) {
367-
GPS_ts = parseInt(position.timestamp/1000);
368-
369-
setInterval(function() {
370-
var delta_ts = parseInt(Date.now()/1000) - GPS_ts;
371-
372-
// generate friendly timestamp
373-
var hours = Math.floor(delta_ts / 3600);
374-
var minutes = Math.floor(delta_ts / 60) % 60;
375-
var ts_str = (delta_ts >= 60) ?
376-
((hours)?hours+'h ':'') +
377-
((minutes)?minutes+'m':'') +
378-
' ago'
379-
: 'just now';
380-
$('#cc_timestamp').text(ts_str);
381-
}, 30000);
382-
383-
$('#cc_timestamp').text('just now');
384-
}
358+
var lat = position.coords.latitude;
359+
var lon = position.coords.longitude;
360+
var alt = (position.coords.altitude) ? position.coords.altitude : 0;
361+
var accuracy = (position.coords.accuracy) ? position.coords.accuracy : 0;
362+
var speed = (position.coords.speed) ? position.coords.speed : 0;
363+
364+
// constantly update 'last updated' field, and display friendly time since last update
365+
if(!GPS_ts) {
366+
GPS_ts = parseInt(position.timestamp/1000);
367+
368+
setInterval(function() {
369+
var delta_ts = parseInt(Date.now()/1000) - GPS_ts;
370+
371+
// generate friendly timestamp
372+
var hours = Math.floor(delta_ts / 3600);
373+
var minutes = Math.floor(delta_ts / 60) % 60;
374+
var ts_str = (delta_ts >= 60) ?
375+
((hours)?hours+'h ':'') +
376+
((minutes)?minutes+'m':'') +
377+
' ago'
378+
: 'just now';
379+
$('#cc_timestamp').text(ts_str);
380+
}, 30000);
381+
382+
$('#cc_timestamp').text('just now');
383+
}
385384

386-
// save position and update only if different is available
387-
if(CHASE_timer < (new Date()).getTime() &&
388-
(
389-
GPS_lat != lat ||
390-
GPS_lon != lon ||
391-
GPS_alt != alt ||
392-
GPS_speed != speed
393-
)
385+
// save position and update only if different is available
386+
if(CHASE_timer < (new Date()).getTime() &&
387+
(
388+
GPS_lat != lat ||
389+
GPS_lon != lon ||
390+
GPS_alt != alt ||
391+
GPS_speed != speed
394392
)
395-
{
396-
GPS_lat = lat;
397-
GPS_lon = lon;
398-
GPS_alt = alt;
399-
GPS_speed = speed;
400-
GPS_ts = parseInt(position.timestamp/1000);
401-
$('#cc_timestamp').text('just now');
402-
403-
// update look angles once we get position
404-
if(follow_vehicle !== null && vehicles[follow_vehicle] !== undefined) {
405-
update_lookangles(follow_vehicle);
406-
}
393+
)
394+
{
395+
GPS_lat = lat;
396+
GPS_lon = lon;
397+
GPS_alt = alt;
398+
GPS_speed = speed;
399+
GPS_ts = parseInt(position.timestamp/1000);
400+
$('#cc_timestamp').text('just now');
401+
402+
// update look angles once we get position
403+
if(follow_vehicle !== null && vehicles[follow_vehicle] !== undefined) {
404+
update_lookangles(follow_vehicle);
405+
}
407406

408-
if(CHASE_enabled) {
409-
ChaseCar.updatePosition(callsign, position);
410-
CHASE_timer = (new Date()).getTime() + 15000;
411-
}
407+
if(CHASE_enabled) {
408+
ChaseCar.updatePosition(callsign, position);
409+
CHASE_timer = (new Date()).getTime() + 15000;
412410
}
413-
else { return; }
414-
415-
// add/update marker on the map (sondehub.js)
416-
updateCurrentPosition(lat, lon);
417-
418-
// round the coordinates
419-
lat = parseInt(lat * 10000)/10000; // 4 decimal places (11m accuracy at equator)
420-
lon = parseInt(lon * 10000)/10000; // 4 decimal places
421-
speed = parseInt(speed * 10)/10; // 1 decimal place
422-
accuracy = parseInt(accuracy);
423-
alt = parseInt(alt);
424-
425-
// dispaly them in the top right corner
426-
$('#app_name b').html(lat + '<br/>' + lon);
427-
428-
// update chase car interface
429-
$('#cc_lat').text(lat);
430-
$('#cc_lon').text(lon);
431-
$('#cc_alt').text(alt + " m");
432-
$('#cc_accuracy').text(accuracy + " m");
433-
$('#cc_speed').text(speed + " m/s");
434-
/*
435-
},
436-
function() {
437-
// when there is no location
438-
$('#app_name b').html('mobile<br/>tracker');
439-
});
440-
*/
411+
}
412+
413+
414+
// add/update marker on the map (sondehub.js)
415+
updateCurrentPosition(lat, lon);
416+
417+
// round the coordinates
418+
lat = parseInt(lat * 10000)/10000; // 4 decimal places (11m accuracy at equator)
419+
lon = parseInt(lon * 10000)/10000; // 4 decimal places
420+
speed = parseInt(speed * 10)/10; // 1 decimal place
421+
accuracy = parseInt(accuracy);
422+
alt = parseInt(alt);
423+
424+
// dispaly them in the top right corner
425+
$('#app_name b').html(lat + '<br/>' + lon);
426+
427+
// update chase car interface
428+
$('#cc_lat').text(lat);
429+
$('#cc_lon').text(lon);
430+
$('#cc_alt').text(alt + " m");
431+
$('#cc_accuracy').text(accuracy + " m");
432+
$('#cc_speed').text(speed + " m/s");
433+
434+
441435
};
442436

443437
var twoZeroPad = function(n) {
@@ -703,7 +697,6 @@ $(window).ready(function() {
703697
field.removeAttr('disabled');
704698
e.removeClass('on').addClass('off');
705699

706-
if(navigator.geolocation) navigator.geolocation.clearWatch(CHASE_enabled);
707700
CHASE_enabled = null;
708701
//CHASE_enabled = false;
709702

@@ -731,8 +724,7 @@ $(window).ready(function() {
731724
ChaseCar.updatePosition(callsign, { coords: { latitude: GPS_lat, longitude: GPS_lon, altitude: GPS_alt, speed: GPS_speed }});
732725
}
733726

734-
if(navigator.geolocation) CHASE_enabled = navigator.geolocation.watchPosition(positionUpdateHandle, positionUpdateError);
735-
//CHASE_enabled = true;
727+
CHASE_enabled = true;
736728

737729
// hide the blue man
738730
if(currentPosition && currentPosition.marker) map.removeLayer(currentPosition.marker);
@@ -986,10 +978,7 @@ $(window).ready(function() {
986978
});
987979

988980
navigator.geolocation.getCurrentPosition(positionUpdateHandle);
989-
// check for location update every 30sec
990-
//setInterval(positionUpdateHandle, 30000);
991-
// immediatelly check for position
992-
//positionUpdateHandle();
981+
if(navigator.geolocation) navigator.geolocation.watchPosition(positionUpdateHandle, positionUpdateError);
993982
}
994983

995984
// weather feature

js/sondehub.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4519,8 +4519,10 @@ function updateCurrentPosition(lat, lon) {
45194519
} else {
45204520
currentPosition.lat = lat;
45214521
currentPosition.lon = lon;
4522-
currentPosition.marker.addTo(map);
4523-
currentPosition.marker.setLatLng(latlng);
4522+
if (!CHASE_enabled){
4523+
currentPosition.marker.addTo(map);
4524+
currentPosition.marker.setLatLng(latlng);
4525+
}
45244526
}
45254527
}
45264528

0 commit comments

Comments
 (0)