Skip to content

Commit daac0a6

Browse files
authored
Merge pull request #1341 from McGiverGim/fix_flickering_gps
Remove flickering when fix is unstable
2 parents 452bff9 + 4391ea8 commit daac0a6

File tree

5 files changed

+44
-15
lines changed

5 files changed

+44
-15
lines changed

manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@
5353
"js/tabs/map.js",
5454
"/js/libraries/openlayers/ol.css",
5555
"/js/libraries/openlayers/ol.js",
56-
"/images/icons/cf_icon_position.png"]
56+
"/images/icons/cf_icon_position.png",
57+
"/images/icons/cf_icon_position_nofix.png"]
5758
}
5859
]
5960
},

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"js/tabs/map.js",
3030
"/js/libraries/openlayers/ol.css",
3131
"/js/libraries/openlayers/ol.js",
32-
"/images/icons/cf_icon_position.png"
32+
"/images/icons/cf_icon_position.png",
33+
"/images/icons/cf_icon_position_nofix.png"
3334
]
3435
}
3536
]
5.84 KB
Loading

src/js/tabs/gps.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ TABS.gps.initialize = function (callback) {
4242
MSP.send_message(MSPCodes.MSP_GPS_SV_INFO, false, false, update_ui);
4343
}
4444

45+
// To not flicker the divs while the fix is unstable
46+
var gpsWasFixed = false;
47+
4548
function update_ui() {
4649
var lat = GPS_DATA.lat / 10000000;
4750
var lon = GPS_DATA.lon / 10000000;
@@ -81,16 +84,20 @@ TABS.gps.initialize = function (callback) {
8184
if (navigator.onLine) {
8285
$('#connect').hide();
8386

84-
//if(lat != 0 && lon != 0){
85-
if(GPS_DATA.fix){
87+
if (GPS_DATA.fix) {
88+
gpsWasFixed = true;
8689
frame.contentWindow.postMessage(message, '*');
8790
$('#loadmap').show();
8891
$('#waiting').hide();
89-
}else{
92+
} else if (!gpsWasFixed) {
9093
$('#loadmap').hide();
9194
$('#waiting').show();
95+
} else {
96+
message.action = 'nofix';
97+
frame.contentWindow.postMessage(message, '*');
9298
}
9399
}else{
100+
gpsWasFixed = false;
94101
$('#connect').show();
95102
$('#waiting').hide();
96103
$('#loadmap').hide();

src/js/tabs/map.js

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
const DEFAULT_ZOOM = 16,
22
DEFAULT_LON = 0,
33
DEFAULT_LAT = 0,
4-
ICON_IMAGE = '/images/icons/cf_icon_position.png';
4+
ICON_IMAGE = '/images/icons/cf_icon_position.png',
5+
ICON_IMAGE_NOFIX = '/images/icons/cf_icon_position_nofix.png';
56

67
var iconGeometry,
78
map,
89
mapView,
9-
marker;
10+
iconStyle,
11+
iconStyleNoFix,
12+
iconFeature;
1013

1114
window.onload = initializeMap;
1215

@@ -30,17 +33,30 @@ function initializeMap() {
3033
controls: []
3134
});
3235

33-
var iconStyle = new ol.style.Style({
34-
image: new ol.style.Icon(({
35-
anchor: [0.5, 1],
36-
opacity: 1,
37-
scale: 0.5,
38-
src: ICON_IMAGE
39-
}))
36+
var icon = new ol.style.Icon(({
37+
anchor: [0.5, 1],
38+
opacity: 1,
39+
scale: 0.5,
40+
src: ICON_IMAGE
41+
}));
42+
43+
var iconNoFix = new ol.style.Icon(({
44+
anchor: [0.5, 1],
45+
opacity: 1,
46+
scale: 0.5,
47+
src: ICON_IMAGE_NOFIX
48+
}));
49+
50+
iconStyle = new ol.style.Style({
51+
image: icon
52+
});
53+
54+
iconStyleNoFix = new ol.style.Style({
55+
image: iconNoFix
4056
});
4157

4258
iconGeometry = new ol.geom.Point(lonLat);
43-
var iconFeature = new ol.Feature({
59+
iconFeature = new ol.Feature({
4460
geometry: iconGeometry
4561
});
4662

@@ -73,11 +89,15 @@ function processMapEvents(e) {
7389
break;
7490

7591
case 'center':
92+
iconFeature.setStyle(iconStyle);
7693
var center = ol.proj.fromLonLat([e.data.lon, e.data.lat]);
7794
mapView.setCenter(center);
7895
iconGeometry.setCoordinates(center);
7996
break;
8097

98+
case 'nofix':
99+
iconFeature.setStyle(iconStyleNoFix);
100+
break;
81101
}
82102

83103
} catch (e) {

0 commit comments

Comments
 (0)