Skip to content

Commit d72b42a

Browse files
haslinghuischmelevskij
authored andcommitted
Add satellite layer and show map on latlon values (betaflight#3685)
* Add satellite layer and show map on latlon values * Use controls * Hide all layers initially except OSM * Remove debug location * Add some layer tag and update switching * Remove debug * Remove layerGroup * Remove commented code * Remove maxzoom * Remove bloat and increase default zoom level * Use buttons instead of anchors * Remove class * Remove unused messages
1 parent 255dd6f commit d72b42a

File tree

5 files changed

+63
-27
lines changed

5 files changed

+63
-27
lines changed

locales/en/messages.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2802,10 +2802,6 @@
28022802
"gpsMapHead": {
28032803
"message": "Current GPS location"
28042804
},
2805-
"gpsMapHeadHelp": {
2806-
"message": "Show GPS location on the map. Use mouse scroll button to zoom in and out.<br>The location icon shows the north direction when the magnetometer is in use",
2807-
"description": "Help text for gpsHeadMap"
2808-
},
28092805
"gpsMapMessage1": {
28102806
"message": "Please check your internet connection"
28112807
},

src/css/tabs/gps.less

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,11 @@
168168
border-bottom-left-radius: 3px;
169169
border-bottom-right-radius: 3px;
170170
background-color: #D1D1D1;
171-
a {
171+
button {
172172
background-color: white;
173173
border-radius: 4px;
174174
border: 1px var(--subtleAccent) solid;
175175
color: grey;
176-
height: 10px;
177-
width: 10px;
178176
text-align: center;
179177
font-size: 20px;
180178
line-height: 10px;

src/js/tabs/gps.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,6 @@ gps.initialize = async function (callback) {
7979
MSP.send_message(MSPCodes.MSP_RAW_IMU, false, false, update_ui);
8080
}
8181

82-
// To not flicker the divs while the fix is unstable
83-
let gpsWasFixed = false;
84-
8582
// GPS Configuration
8683
const features_e = $('.tab-gps .features');
8784

@@ -334,32 +331,30 @@ gps.initialize = async function (callback) {
334331
}
335332
}
336333

334+
let gpsFoundPosition = false;
335+
337336
if (navigator.onLine) {
338337
$('#connect').hide();
339338

340-
if (FC.GPS_DATA.fix) {
341-
gpsWasFixed = true;
339+
gpsFoundPosition = !!(lon && lat);
342340

341+
if (gpsFoundPosition) {
343342
(hasMag ? iconStyleMag : iconStyleGPS)
344343
.getImage()
345344
.setRotation(imuHeadingRadians);
346345
iconFeature.setStyle(hasMag ? iconStyleMag : iconStyleGPS);
347346
const center = fromLonLat([lon, lat]);
348347
mapView.setCenter(center);
349348
iconGeometry.setCoordinates(center);
350-
351-
$('#loadmap').show();
352-
$('#waiting').hide();
353-
} else if (!gpsWasFixed) {
354-
$('#loadmap').hide();
355-
$('#waiting').show();
356349
} else {
357350
iconFeature.setStyle(iconStyleNoFix);
358351
}
359352
} else {
360-
gpsWasFixed = false;
361353
set_offline();
362354
}
355+
356+
$('#loadmap').toggle(gpsFoundPosition);
357+
$('#waiting').toggle(!gpsFoundPosition);
363358
}
364359

365360
// enable data pulling

src/js/tabs/map.js

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { View, Map, Feature } from "ol";
22
import { fromLonLat } from "ol/proj";
33
import { Tile, Vector as LayerVector } from "ol/layer";
4-
import { OSM, Vector as SourceVector } from "ol/source";
4+
import { OSM, XYZ, Vector as SourceVector } from "ol/source";
55
import { Icon, Style } from "ol/style";
66
import { Point } from "ol/geom";
77

8-
const DEFAULT_ZOOM = 16,
8+
const DEFAULT_ZOOM = 17,
99
DEFAULT_LON = 0,
1010
DEFAULT_LAT = 0,
1111
ICON_IMAGE_GPS = "/images/icons/cf_icon_position.png",
@@ -20,12 +20,28 @@ export function initMap() {
2020
zoom: DEFAULT_ZOOM,
2121
});
2222

23+
const osmLayer = new Tile({
24+
source: new OSM(),
25+
});
26+
27+
const googleSatLayer = new Tile({
28+
source: new XYZ({
29+
url: 'https://mt1.google.com/vt/lyrs=s&x={x}&y={y}&z={z}',
30+
}),
31+
});
32+
33+
const googleHybridLayer = new Tile({
34+
source: new XYZ({
35+
url: 'https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}',
36+
}),
37+
});
38+
2339
const map = new Map({
2440
target: "map",
2541
layers: [
26-
new Tile({
27-
source: new OSM(),
28-
}),
42+
osmLayer,
43+
googleSatLayer,
44+
googleHybridLayer,
2945
],
3046
view: mapView,
3147
controls: [],
@@ -82,6 +98,34 @@ export function initMap() {
8298

8399
map.addLayer(currentPositionLayer);
84100

101+
// Start with Satellite layer
102+
osmLayer.setVisible(false);
103+
googleHybridLayer.setVisible(false);
104+
105+
$('#Hybrid').on('click', function () {
106+
if (!googleHybridLayer.isVisible()) {
107+
osmLayer.setVisible(false);
108+
googleSatLayer.setVisible(false);
109+
googleHybridLayer.setVisible(true);
110+
}
111+
});
112+
113+
$('#Satellite').on('click', function () {
114+
if (!googleSatLayer.isVisible()) {
115+
osmLayer.setVisible(false);
116+
googleSatLayer.setVisible(true);
117+
googleHybridLayer.setVisible(false);
118+
}
119+
});
120+
121+
$('#Street').on('click', function () {
122+
if (!osmLayer.isVisible()) {
123+
osmLayer.setVisible(true);
124+
googleSatLayer.setVisible(false);
125+
googleHybridLayer.setVisible(false);
126+
}
127+
});
128+
85129
return {
86130
mapView,
87131
iconStyleMag,

src/tabs/gps.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@
125125
<div class="gui_box grey gps_map">
126126
<div class="gui_box_titlebar" style="margin-bottom: 0px;">
127127
<div class="spacer_box_title" i18n="gpsMapHead"></div>
128-
<div class="helpicon cf_tip" i18n_title="gpsMapHeadHelp"></div>
129128
</div>
130129
<div id="connect" i18n="gpsMapMessage1">
131130
<div class="default_btn" style="width:50px; margin-left:auto; margin-right:auto; float:none;"><a id="check">retry</a></div>
@@ -135,9 +134,13 @@
135134
</div>
136135
<div id="loadmap">
137136
<div id="map" class="map"> </div>
137+
138138
<div class="controls">
139-
<a href="#" id="zoom_in">+</a>
140-
<a href="#" id="zoom_out"></a>
139+
<button id="Hybrid">H</button>
140+
<button id="Satellite">S</button>
141+
<button id="Street">R</button>
142+
<button id="zoom_in">+</button>
143+
<button id="zoom_out"></button>
141144
</div>
142145
</div>
143146
</div>

0 commit comments

Comments
 (0)