Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add satellite layer and show map on latlon values #3685

Merged
merged 13 commits into from Dec 23, 2023
16 changes: 12 additions & 4 deletions locales/en/messages.json
Expand Up @@ -2802,10 +2802,6 @@
"gpsMapHead": {
"message": "Current GPS location"
},
"gpsMapHeadHelp": {
"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",
"description": "Help text for gpsHeadMap"
},
"gpsMapMessage1": {
"message": "Please check your internet connection"
},
Expand Down Expand Up @@ -7027,6 +7023,18 @@
"message": "None",
"description": "One of the options selectable for the GPS SBAS system"
},
"gpsMapTypeRoadmap": {
"message": "Roadmap",
"description": "One of the options selectable for the GPS map type"
},
"gpsMapTypeSatellite": {
"message": "Satellite",
"description": "One of the options selectable for the GPS map type"
},
"gpsMapTypeHybrid": {
"message": "Hybrid",
"description": "One of the options selectable for the GPS map type"
},
"dialogFileNameTitle": {
"message": "File name"
},
Expand Down
4 changes: 1 addition & 3 deletions src/css/tabs/gps.less
Expand Up @@ -168,13 +168,11 @@
border-bottom-left-radius: 3px;
border-bottom-right-radius: 3px;
background-color: #D1D1D1;
a {
button {
background-color: white;
border-radius: 4px;
border: 1px var(--subtleAccent) solid;
color: grey;
height: 10px;
width: 10px;
text-align: center;
font-size: 20px;
line-height: 10px;
Expand Down
19 changes: 7 additions & 12 deletions src/js/tabs/gps.js
Expand Up @@ -79,9 +79,6 @@ gps.initialize = async function (callback) {
MSP.send_message(MSPCodes.MSP_RAW_IMU, false, false, update_ui);
}

// To not flicker the divs while the fix is unstable
let gpsWasFixed = false;

// GPS Configuration
const features_e = $('.tab-gps .features');

Expand Down Expand Up @@ -334,32 +331,30 @@ gps.initialize = async function (callback) {
}
}

let gpsFoundPosition = false;

if (navigator.onLine) {
$('#connect').hide();

if (FC.GPS_DATA.fix) {
gpsWasFixed = true;
gpsFoundPosition = !!(lon && lat);

if (gpsFoundPosition) {
(hasMag ? iconStyleMag : iconStyleGPS)
.getImage()
.setRotation(imuHeadingRadians);
iconFeature.setStyle(hasMag ? iconStyleMag : iconStyleGPS);
const center = fromLonLat([lon, lat]);
mapView.setCenter(center);
iconGeometry.setCoordinates(center);

$('#loadmap').show();
$('#waiting').hide();
} else if (!gpsWasFixed) {
$('#loadmap').hide();
$('#waiting').show();
} else {
iconFeature.setStyle(iconStyleNoFix);
}
} else {
gpsWasFixed = false;
set_offline();
}

$('#loadmap').toggle(gpsFoundPosition);
$('#waiting').toggle(!gpsFoundPosition);
}

// enable data pulling
Expand Down
54 changes: 49 additions & 5 deletions src/js/tabs/map.js
@@ -1,11 +1,11 @@
import { View, Map, Feature } from "ol";
import { fromLonLat } from "ol/proj";
import { Tile, Vector as LayerVector } from "ol/layer";
import { OSM, Vector as SourceVector } from "ol/source";
import { OSM, XYZ, Vector as SourceVector } from "ol/source";
import { Icon, Style } from "ol/style";
import { Point } from "ol/geom";

const DEFAULT_ZOOM = 16,
const DEFAULT_ZOOM = 17,
DEFAULT_LON = 0,
DEFAULT_LAT = 0,
ICON_IMAGE_GPS = "/images/icons/cf_icon_position.png",
Expand All @@ -20,12 +20,28 @@ export function initMap() {
zoom: DEFAULT_ZOOM,
});

const osmLayer = new Tile({
source: new OSM(),
});

const googleSatLayer = new Tile({
source: new XYZ({
url: 'https://mt1.google.com/vt/lyrs=s&x={x}&y={y}&z={z}',
}),
});

const googleHybridLayer = new Tile({
source: new XYZ({
url: 'https://mt1.google.com/vt/lyrs=y&x={x}&y={y}&z={z}',
}),
});

const map = new Map({
target: "map",
layers: [
new Tile({
source: new OSM(),
}),
osmLayer,
googleSatLayer,
googleHybridLayer,
],
view: mapView,
controls: [],
Expand Down Expand Up @@ -82,6 +98,34 @@ export function initMap() {

map.addLayer(currentPositionLayer);

// Start with Satellite layer
osmLayer.setVisible(false);
googleHybridLayer.setVisible(false);

$('#Hybrid').on('click', function () {
if (!googleHybridLayer.isVisible()) {
osmLayer.setVisible(false);
googleSatLayer.setVisible(false);
googleHybridLayer.setVisible(true);
}
});

$('#Satellite').on('click', function () {
if (!googleSatLayer.isVisible()) {
osmLayer.setVisible(false);
googleSatLayer.setVisible(true);
googleHybridLayer.setVisible(false);
}
});

$('#Street').on('click', function () {
if (!osmLayer.isVisible()) {
osmLayer.setVisible(true);
googleSatLayer.setVisible(false);
googleHybridLayer.setVisible(false);
}
});

return {
mapView,
iconStyleMag,
Expand Down
11 changes: 8 additions & 3 deletions src/tabs/gps.html
Expand Up @@ -125,7 +125,6 @@
<div class="gui_box grey gps_map">
<div class="gui_box_titlebar" style="margin-bottom: 0px;">
<div class="spacer_box_title" i18n="gpsMapHead"></div>
<div class="helpicon cf_tip" i18n_title="gpsMapHeadHelp"></div>
</div>
<div id="connect" i18n="gpsMapMessage1">
<div class="default_btn" style="width:50px; margin-left:auto; margin-right:auto; float:none;"><a id="check">retry</a></div>
Expand All @@ -135,9 +134,15 @@
</div>
<div id="loadmap">
<div id="map" class="map"> </div>

<div class="controls">
<a href="#" id="zoom_in">+</a>
<a href="#" id="zoom_out">–</a>
<div id="mapview" class="mapview">
<button id="Hybrid">H</button>
<button id="Satellite">S</button>
<button id="Street">R</button>
</div>
<button id="zoom_in">+</button>
<button id="zoom_out">–</button>
</div>
</div>
</div>
Expand Down