QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
FlyViewGeoMapAdapter.qml
Go to the documentation of this file.
1/****************************************************************************
2 *
3 * (c) 2009-2024 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 *
5 * QGroundControl is licensed according to the terms in the file
6 * COPYING.md in the root of the source code directory.
7 *
8 ****************************************************************************/
9
10import QtQuick
11import QtPositioning
12
13import QGroundControl
14import QGroundControl.Controls
15import QGroundControl.FlightMap
16import QGroundControl.GeoMap
17
18/// GeoMap-engine drop-in for FlyViewMap: hosts a FlyViewGeoMap and implements
19/// the mapControl contract the Fly View overlays consume (pipState,
20/// isSatelliteMap, toCoordinate/fromCoordinate, zoomLevel, ...).
21Item {
22 id: root
23
24 // mapControl contract (parity with FlyViewMap)
25 property Item pipView
26 property Item pipState: _pipState
27 property var rightPanelWidth
28 property var planMasterController
29 property bool pipMode: false // true: map is shown in a small pip mode
30 property rect viewportRect: Qt.rect(0, 0, width, height) // Map area the vehicle is kept within
31 property var occluders: [] // Rects within the viewport covered by UI
32 property real chromeTopMargin: 0 // Map controls on the right edge start below this
33 property real chromeBottomMargin: 0 // Map overlays on the bottom left stay above this
34 property string mapName
35
36 // The mapControl contract (center, zoomLevel, ...) is implemented by the map itself, see GeoMapView
37 property alias center: geoMapControl.center
38 property alias zoomLevel: geoMapControl.zoomLevel
39 property alias isSatelliteMap: geoMapControl.isSatelliteMap
40 property alias pinchZoomDisabledByVirtualJoysticks: geoMapControl.pinchZoomDisabledByVirtualJoysticks
41
42 // Escape hatch for GeoMap-specific chrome/controls
43 readonly property var geoMap: geoMapControl
44
45 // PiP analog of FlyViewMap._adjustMapZoomForPipMode: pull the camera back
46 // 3 zoom levels in the small window for situational context; the swap-back
47 // re-applies the shared saved zoom. PiP is also too small for a useful
48 // 3D view, so force 2D and restore the previous camera mode with it.
49 property int _fullViewCameraMode: GeoMapCamera.Mode2D
50
51 onPipModeChanged: {
52 const camera = geoMapControl.camera
53 // Pinned for the zoom change below, which must not be saved as the shared zoom, whichever
54 // of this handler and the sharedZoom binding runs first
55 geoMapControl.sharedZoom = !pipMode
56 if (pipMode) {
57 _fullViewCameraMode = camera.mode
58 camera.mode = GeoMapCamera.Mode2D
59 camera.distance = camera.distanceForZoomLevel(camera.zoomLevelForDistance(camera.distance) - 3)
60 } else {
61 camera.mode = _fullViewCameraMode
62 }
63 geoMapControl.sharedZoom = Qt.binding(() => !root.pipMode)
64 }
65
66 // MapFitFunctions contract (FlightMap.setVisibleRegion parity)
67 function setVisibleRegion(region) {
68 geoMapControl.setVisibleRegion(region)
69 // PiP zoom is otherwise never shared: save the fit so the swap back keeps it (FlyViewMap parity)
70 if (pipMode && visible) {
71 const camera = geoMapControl.camera
72 QGroundControl.flightMapZoom = camera.zoomLevelForDistance(camera.distance)
73 }
74 }
75
76 function toCoordinate(point, clipToViewPort) {
77 return geoMapControl.toCoordinate(point, clipToViewPort)
78 }
79
80 function fromCoordinate(coordinate, clipToViewPort) {
81 return geoMapControl.fromCoordinate(coordinate, clipToViewPort)
82 }
83
84 FlyViewGeoMap {
85 id: geoMapControl
86 anchors.fill: parent
87 followViewportRect: root.viewportRect
88 followOccluders: root.occluders
89
90 sharedZoom: !root.pipMode
91 // The PiP window is too small for free camera panning to be useful
92 keepVehicleCentered: root.pipMode || QGroundControl.settingsManager.flyViewSettings.keepMapCenteredOnVehicle.rawValue
93
94 // Guided-action popup on click (FlyViewMap.onMapClicked parity).
95 // Allowed at any tilt: toCoordinate picks the rendered terrain
96 // surface, so the click lands where the user sees it even in 3D.
97 onMapClicked: (position) => {
98 if (root.pipMode) {
99 return
100 }
101 if (!globals.guidedControllerFlyView.guidedUIVisible &&
102 (globals.guidedControllerFlyView.showGotoLocation || globals.guidedControllerFlyView.showOrbit ||
103 globals.guidedControllerFlyView.showROI || globals.guidedControllerFlyView.showSetHome ||
104 globals.guidedControllerFlyView.showSetEstimatorOrigin)) {
105
106 const clickCoord = root.toCoordinate(Qt.point(position.x, position.y), false /* clipToViewPort */)
107 if (!clickCoord.isValid) {
108 return
109 }
110 const windowPosition = root.mapToItem(globals.parent, position.x, position.y)
111 const dropPanel = mapClickDropPanelComponent.createObject(mainWindow, { mapClickCoord: clickCoord, clickRect: Qt.rect(windowPosition.x, windowPosition.y, 0, 0) })
112 dropPanel.open()
113 }
114 }
115 }
116
117 Component {
118 id: mapClickDropPanelComponent
119
120 FlyViewMapClickDropPanel {
121 gotoIndicator: geoMapControl.gotoIndicator
122 orbitIndicator: geoMapControl.orbitIndicator
123 }
124 }
125
126 ObstacleDistanceOverlayMap {
127 mapControl: root
128 showText: !root.pipMode
129 }
130
131 FlyViewGeoMapChrome {
132 anchors.fill: parent
133 geoMap: geoMapControl
134 visible: !root.pipMode
135 buttonsTopMargin: root.chromeTopMargin
136 overlayBottomMargin: root.chromeBottomMargin
137 }
138
139 PipState {
140 id: _pipState
141 pipView: root.pipView
142 isDark: _isFullWindowItemDark
143 }
144
145 MapFitFunctions {
146 id: mapFitFunctions
147 map: root
148 usePlannedHomePosition: false
149 planMasterController: root.planMasterController
150 }
151
152 // Zoom to a mission downloaded from the vehicle (FlyViewMap parity)
153 Connections {
154 target: root.planMasterController ? root.planMasterController.missionController : null
155
156 function onNewItemsFromVehicle() {
157 const visualItems = root.planMasterController.missionController.visualItems
158 if (visualItems && visualItems.count !== 1) {
159 mapFitFunctions.fitMapViewportToMissionItems()
160 geoMapControl.positionTracker.firstVehiclePositionReceived = true
161 }
162 }
163 }
164}