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

Fix map view feature #1258

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions console_backend/src/cli_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ pub struct CliOptions {
#[clap(long)]
pub show_file_connection: bool,

/// Enable map.
#[clap(long)]
pub enable_map: bool,

/// Enable ntrip client
#[clap(long)]
pub enable_ntrip: bool,
Expand Down
2 changes: 1 addition & 1 deletion console_backend/src/tabs/baseline_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl BaselineTab {
/// # Parameters
/// - `mode_string`: The mode string to attempt to prepare data for frontend.
/// - `update_current`: Indicating whether the current solution should be updated by
/// this modes last n/e entry.
/// this modes last n/e entry.
fn _synchronize_plot_data_by_mode(&mut self, mode_string: &str, update_current: bool) {
let mode_idx = match self.mode_strings.iter().position(|x| *x == *mode_string) {
Some(idx) => idx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ impl SolutionPositionTab {
/// # Parameters
/// - `mode_string`: The mode string to attempt to prepare data for frontend.
/// - `update_current`: Indicating whether the current solution should be updated by
/// this modes last lat/lon entry.
/// this modes last lat/lon entry.
fn _synchronize_plot_data_by_mode(&mut self, mode_string: &str, update_current: bool) {
let idx = match self.mode_strings.iter().position(|x| x == mode_string) {
Some(idx) => idx,
Expand Down
1 change: 0 additions & 1 deletion resources/Constants/Globals.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ QtObject {
property int initialSubTabIndex: 0 // Signals
property bool showCsvLog: false
property bool showFileio: false
property bool enableMap: false
property int height: 600
property int minimumHeight: 600
property int width: 1000
Expand Down
12 changes: 2 additions & 10 deletions resources/SolutionTab.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import "SolutionTabComponents" as SolutionTabComponents
MainTab {
id: solutionTab

subTabNames: Globals.enableMap ? ["Position", "Velocity", "Map"] : ["Position", "Velocity"]
subTabNames: ["Position", "Velocity", "Map"]
curSubTabIndex: 0

SplitView {
Expand All @@ -57,15 +57,7 @@ MainTab {
SolutionTabComponents.SolutionVelocityTab {
}

Rectangle {
width: parent.width
height: parent.height
Loader {
sourceComponent: Globals.enableMap ? solutionMap : null
}
}

property Component solutionMap: SolutionTabComponents.SolutionMapTab {
SolutionTabComponents.SolutionMapTab {
}
}
}
Expand Down
40 changes: 32 additions & 8 deletions resources/web/map/js/trajectory_raw.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@ import mapboxGlStyleSwitcher from 'https://cdn.skypack.dev/mapbox-gl-style-switc

const lines = ["#FF0000", "#FF00FF", "#00FFFF", "#0000FF", "#00FF00", "#000000"];
const LNG_KM = 111.320, LAT_KM = 110.574;
const mapContainer = 'map';
const mapStyle = "mapbox://styles/mapbox/light-v11?optimize=true";
const mapCenter = [-122.486052, 37.830348]; // Initial focus coordinate
const mapZoom = 16;
const mapPerformanceMetricsCollection = false;

function decode(r){var n=r,t=[0,10,13,34,38,92],e=new Uint8Array(1.75*n.length|0),f=0,o=0,a=0;function i(r){o|=(r<<=1)>>>a,8<=(a+=7)&&(e[f++]=o,o=r<<7-(a-=8)&255)}for(var u=0;u<n.length;u++){var c,d=n.charCodeAt(u);127<d?(7!=(c=d>>>8&7)&&i(t[c]),i(127&d)):i(d)}r=new Uint8Array(e,0,f);var s=new TextDecoder().decode(r);while (s.slice(-1)=="\x00") s=s.slice(0,-1); return s;}

mapboxgl.accessToken = decode("@ACCESS_TOKEN@");
var map = new mapboxgl.Map({
container: 'map',
style: "mapbox://styles/mapbox/light-v11?optimize=true",
center: [-122.486052, 37.830348], // Initial focus coordinate
zoom: 16,
performanceMetricsCollection: false,
container: mapContainer,
style: mapStyle,
center: mapCenter,
zoom: mapZoom,
performanceMetricsCollection: mapPerformanceMetricsCollection,
});

var focusCurrent = false;
Expand Down Expand Up @@ -130,7 +135,9 @@ function setupLayers() {
}

function syncCrumbCoords(){
map.getSource('breadcrumb').setData({
let breadcrumb = map.getSource('breadcrumb');
if (breadcrumb === undefined) return;
breadcrumb.setData({
type: 'Feature',
geometry: {
type: 'LineString',
Expand All @@ -142,10 +149,12 @@ function syncCrumbCoords(){
function syncLayers() {
// sync route datas with stored points
for (let i = 0; i < lines.length; i++) {
map.getSource(`route${i}`).setData(data[i]);
let route = map.getSource(`route${i}`);
if (route !== undefined) route.setData(data[i]);
}
// clear protection, since its only one point and temporary
map.getSource('prot').setData({
let prot = map.getSource('prot');
if (prot !== undefined) prot.setData({
type: 'FeatureCollection',
features: []
});
Expand Down Expand Up @@ -239,3 +248,18 @@ map.on('load', () => {
console.log("loaded");
setupLayers();
});

map.on('error', () => {
if (mapboxgl.accessToken != "@ACCESS_TOKEN@") {
console.log("Attempting to use local environment variable MAPBOX_TOKEN");
mapboxgl.accessToken = "@ACCESS_TOKEN@";
map.remove();
map = new mapboxgl.Map({
container: mapContainer,
style: mapStyle,
center: mapCenter,
zoom: mapZoom,
performanceMetricsCollection: mapPerformanceMetricsCollection,
});
}
});
30 changes: 10 additions & 20 deletions swiftnav_console/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

from PySide6.QtWidgets import QApplication, QSplashScreen # type: ignore

from PySide6.QtCore import QObject, QUrl, QThread, QTimer, Slot, Signal, Qt, QLocale
from PySide6.QtCore import QLoggingCategory, QObject, QUrl, QThread, QTimer, Slot, Signal, Qt, QLocale
from PySide6 import QtCharts # pylint: disable=unused-import

from PySide6 import QtQml, QtCore
Expand Down Expand Up @@ -166,6 +166,8 @@
solution_velocity_update,
)

from .solution_map import SolutionMap

from .status_bar import (
status_bar_update,
StatusBarData,
Expand Down Expand Up @@ -258,9 +260,6 @@

capnp.remove_import_hook() # pylint: disable=no-member

MAP_ENABLED = [False]
SolutionMap = QObject


class BackendMessageReceiver(QObject): # pylint: disable=too-many-instance-attributes
_request_quit: Signal = Signal()
Expand Down Expand Up @@ -356,8 +355,7 @@ def _process_message_buffer(self, buffer):
data = settings_table_update()
SettingsTableEntries.post_data_update(data)
ConnectionData.post_connection_state_update(app_state)
if MAP_ENABLED[0]:
SolutionMap.clear()
SolutionMap.clear()
elif m.which == Message.Union.ConnectionNotification:
data = m.connectionNotification.message
ConnectionData.post_connection_message_update(data)
Expand All @@ -372,10 +370,9 @@ def _process_message_buffer(self, buffer):
data[Keys.AVAILABLE_UNITS][:] = m.solutionPositionStatus.availableUnits
data[Keys.SOLUTION_LINE] = m.solutionPositionStatus.lineData

if MAP_ENABLED[0]:
SolutionMap.send_pos(m.solutionPositionStatus)
SolutionMap.send_pos(m.solutionPositionStatus)
SolutionPositionPoints.post_data_update(data)
elif m.which == Message.Union.SolutionProtectionLevel and MAP_ENABLED[0]:
elif m.which == Message.Union.SolutionProtectionLevel:
SolutionMap.send_prot_lvl(m.solutionProtectionLevel)
elif m.which == Message.Union.SolutionTableStatus:
data = solution_table_update()
Expand Down Expand Up @@ -670,9 +667,6 @@ def handle_cli_arguments(args: argparse.Namespace, globals_: QObject):
globals_.setProperty("width", args.width) # type: ignore
if args.show_file_connection:
globals_.setProperty("showFileConnection", True) # type: ignore
if args.enable_map:
globals_.setProperty("enableMap", True) # type: ignore
MAP_ENABLED[0] = True
if args.enable_ntrip:
globals_.setProperty("enableNtrip", True) # type: ignore
try:
Expand Down Expand Up @@ -733,7 +727,6 @@ def main(passed_args: Optional[Tuple[str, ...]] = None) -> int:
parser.add_argument("--record-capnp-recording", action="store_true")
parser.add_argument("--debug-with-no-backend", action="store_true")
parser.add_argument("--show-fileio", action="store_true")
parser.add_argument("--enable-map", action="store_true")
parser.add_argument("--show-file-connection", action="store_true")
parser.add_argument("--no-prompts", action="store_true")
parser.add_argument("--use-opengl", action="store_true")
Expand Down Expand Up @@ -775,12 +768,15 @@ def main(passed_args: Optional[Tuple[str, ...]] = None) -> int:
found_help_arg = True
args_main, _ = parser.parse_known_args(passed_args)
if args_main.no_high_dpi:
QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_Use96Dpi) # type: ignore
QtCore.QCoreApplication.setAttribute(Qt.AA_Use96Dpi) # type: ignore
if args_main.qmldebug:
sys.argv.append("-qmljsdebugger=port:10002,block")
debug = QQmlDebuggingEnabler() # pylint: disable=unused-variable

QLocale.setDefault(QLocale.c())
# Silence webengine context logging.
web_engine_context_log = QLoggingCategory("qt.webenginecontext") # type: ignore
web_engine_context_log.setFilterRules("*.info=false")
QtCore.QCoreApplication.setAttribute(QtCore.Qt.ApplicationAttribute.AA_ShareOpenGLContexts)
QtCore.QCoreApplication.setAttribute(QtCore.Qt.ApplicationAttribute.AA_UseDesktopOpenGL)
QtWebEngineQuick.initialize()
Expand All @@ -795,12 +791,6 @@ def main(passed_args: Optional[Tuple[str, ...]] = None) -> int:
QQuickStyle.setStyle("Material")
# We specifically *don't* want the RobotoCondensed-Bold.ttf font so we get the right look when bolded.

if MAP_ENABLED[0]:
global SolutionMap # pylint: disable=global-statement
from .solution_map import SolutionMap as SolutionMap_ # pylint: disable=import-outside-toplevel

SolutionMap = SolutionMap_ # type: ignore

qmlRegisterType(ConnectionData, "SwiftConsole", 1, 0, "ConnectionData") # type: ignore
qmlRegisterType(AdvancedImuPoints, "SwiftConsole", 1, 0, "AdvancedImuPoints") # type: ignore
qmlRegisterType(AdvancedMagnetometerPoints, "SwiftConsole", 1, 0, "AdvancedMagnetometerPoints") # type: ignore
Expand Down
Loading