5import QGroundControl.Controls
6import QGroundControl.FlightMap
7import QGroundControl.GeoMap
9/// GeoMap that speaks the interface of the QtLocation FlightMap, so the views and controls written against
10/// FlightMap (center, zoomLevel, toCoordinate/fromCoordinate, setVisibleRegion, isSatelliteMap, ...) work unchanged.
11/// It also keeps the map view shared with the other views (QGroundControl.flightMapPosition/flightMapZoom) and can
12/// show the camera controls and map scale itself. Views add their own content on top.
16 // Writable like FlightMap's: assignments move the camera, camera moves are echoed back
18 property real zoomLevel: 0
20 /// false: the zoom is neither restored from nor saved to the shared view, and survives resizes untouched.
21 /// For a map that has its own zoom, such as a small picture-in-picture one.
22 property bool sharedZoom: true
24 /// Camera controls (2D/3D toggle and compass), optionally followed by the map scale, at the top left
25 property bool showControls: false
26 property bool showScale: false
27 property real controlsLeftMargin: ScreenTools.defaultFontPixelWidth * 0.75
28 property real controlsTopMargin: ScreenTools.defaultFontPixelWidth * 0.75
30 readonly property bool isSatelliteMap: _mapTypeSetting.indexOf("Satellite") > -1 || _mapTypeSetting.indexOf("Hybrid") > -1
32 readonly property string _mapTypeSetting: QGroundControl.settingsManager.flightMapSettings.mapType.rawValue
34 // Breaks the center/zoomLevel <-> camera cycle: camera moves echo into them and must not be written back
35 property bool _echoingCamera: false
37 // Screen point -> coordinate of the rendered terrain surface under it, invalid on a sky pick.
38 // clipToViewPort is accepted for FlightMap parity and ignored: every caller passes false.
39 function toCoordinate(point, clipToViewPort) {
40 return root.surfaceCoordinateAt(point)
43 // Coordinate -> screen point; an invalid or behind-the-camera coordinate projects off-screen.
44 // clipToViewPort is ignored as in toCoordinate.
45 function fromCoordinate(coordinate, clipToViewPort) {
46 const screenPos = root.scene.screenPositionFor(coordinate)
47 return (screenPos === undefined) ? Qt.point(-1, -1) : screenPos
50 // MapFitFunctions contract
51 function setVisibleRegion(region) {
52 root.fitToRegion(region)
55 // Zoom level to distance depends on the viewport size, so this also runs on every resize
56 function _applyZoomLevel() {
57 if (!_viewportValid()) {
60 root.camera.distance = root.camera.distanceForZoomLevel(root.zoomLevel)
63 function _viewportValid() {
64 const size = root.camera.viewportSize
65 return size.width > 0 && size.height > 0
68 function _echoCameraCenter() {
70 center = root.camera.center
71 _echoingCamera = false
74 function _echoCameraZoom() {
75 if (!_viewportValid()) {
79 zoomLevel = root.camera.zoomLevelForDistance(root.camera.distance)
80 _echoingCamera = false
83 function _restoreSharedView() {
84 root.camera.center = QGroundControl.flightMapPosition
86 zoomLevel = QGroundControl.flightMapZoom
91 if (_echoingCamera || !center || !center.isValid) {
94 root.camera.center = center
98 if (!_echoingCamera) {
109 // Back from a map with its own zoom: the shared zoom applies again
110 onSharedZoomChanged: {
112 zoomLevel = QGroundControl.flightMapZoom
119 function onCenterChanged() {
120 root._echoCameraCenter()
121 // Hidden: don't overwrite the position another view is sharing
123 QGroundControl.flightMapPosition = root.camera.center
127 function onDistanceChanged() {
128 root._echoCameraZoom()
129 if (root.visible && root.sharedZoom && root._viewportValid()) {
130 QGroundControl.flightMapZoom = root.zoomLevel
134 function onVerticalFieldOfViewChanged() {
135 root._echoCameraZoom()
138 function onViewportSizeChanged() {
139 if (root.sharedZoom) {
140 root._applyZoomLevel()
142 root._echoCameraZoom()
148 x: root.controlsLeftMargin
149 y: root.controlsTopMargin
150 z: 1 // Above the content that views add, so a marker under a control does not take its clicks
151 active: root.showControls || root.showScale
152 visible: !ScreenTools.isTinyScreen
154 sourceComponent: Row {
155 spacing: ScreenTools.defaultFontPixelWidth * 0.75
159 visible: root.showControls
163 anchors.verticalCenter: parent.verticalCenter
166 // The scale is ill-defined under the 3D tilt; isTopDown keeps it hidden until the 3D->2D tilt animation lands
167 visible: root.showScale && root.camera.mode === GeoMapCamera.Mode2D && root.camera.isTopDown
172 Component.onCompleted: {