1/****************************************************************************
3 * (c) 2009-2024 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
5 * QGroundControl is licensed according to the terms in the file
6 * COPYING.md in the root of the source code directory.
8 ****************************************************************************/
14import QGroundControl.Controls
15import QGroundControl.FlightMap
16import QGroundControl.GeoMap
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, ...).
24 // mapControl contract (parity with FlyViewMap)
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
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
42 // Escape hatch for GeoMap-specific chrome/controls
43 readonly property var geoMap: geoMapControl
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
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
57 _fullViewCameraMode = camera.mode
58 camera.mode = GeoMapCamera.Mode2D
59 camera.distance = camera.distanceForZoomLevel(camera.zoomLevelForDistance(camera.distance) - 3)
61 camera.mode = _fullViewCameraMode
63 geoMapControl.sharedZoom = Qt.binding(() => !root.pipMode)
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)
76 function toCoordinate(point, clipToViewPort) {
77 return geoMapControl.toCoordinate(point, clipToViewPort)
80 function fromCoordinate(coordinate, clipToViewPort) {
81 return geoMapControl.fromCoordinate(coordinate, clipToViewPort)
87 followViewportRect: root.viewportRect
88 followOccluders: root.occluders
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
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) => {
101 if (!globals.guidedControllerFlyView.guidedUIVisible &&
102 (globals.guidedControllerFlyView.showGotoLocation || globals.guidedControllerFlyView.showOrbit ||
103 globals.guidedControllerFlyView.showROI || globals.guidedControllerFlyView.showSetHome ||
104 globals.guidedControllerFlyView.showSetEstimatorOrigin)) {
106 const clickCoord = root.toCoordinate(Qt.point(position.x, position.y), false /* clipToViewPort */)
107 if (!clickCoord.isValid) {
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) })
118 id: mapClickDropPanelComponent
120 FlyViewMapClickDropPanel {
121 gotoIndicator: geoMapControl.gotoIndicator
122 orbitIndicator: geoMapControl.orbitIndicator
126 ObstacleDistanceOverlayMap {
128 showText: !root.pipMode
131 FlyViewGeoMapChrome {
133 geoMap: geoMapControl
134 visible: !root.pipMode
135 buttonsTopMargin: root.chromeTopMargin
136 overlayBottomMargin: root.chromeBottomMargin
141 pipView: root.pipView
142 isDark: _isFullWindowItemDark
148 usePlannedHomePosition: false
149 planMasterController: root.planMasterController
152 // Zoom to a mission downloaded from the vehicle (FlyViewMap parity)
154 target: root.planMasterController ? root.planMasterController.missionController : null
156 function onNewItemsFromVehicle() {
157 const visualItems = root.planMasterController.missionController.visualItems
158 if (visualItems && visualItems.count !== 1) {
159 mapFitFunctions.fitMapViewportToMissionItems()
160 geoMapControl.positionTracker.firstVehiclePositionReceived = true