8import QGroundControl.Controls
9import QGroundControl.FlightMap
11/// QGCMapCircle map visuals
15 property var mapControl ///< Map control to place item in
16 property var mapCircle ///< QGCMapCircle object
17 property bool interactive: mapCircle ? mapCircle.interactive : 0 /// true: user can manipulate polygon
18 property color interiorColor: "transparent"
19 property real interiorOpacity: 0.95
20 property int borderWidth: 3
21 property color borderColor: QGroundControl.globalPalette.mapMissionTrajectory
22 property bool centerDragHandleVisible: true
23 property bool radiusLabelVisible: false
24 property real _radius: mapCircle ? mapCircle.radius.rawValue : 0
26 property var _circleComponent
27 property var _topRotationIndicatorComponent
28 property var _bottomRotationIndicatorComponent
29 property var _dragHandlesComponent
31 function addVisuals() {
32 if (!_circleComponent) {
33 _circleComponent = circleComponent.createObject(mapControl)
34 mapControl.addMapItem(_circleComponent)
36 if (!_topRotationIndicatorComponent) {
37 _topRotationIndicatorComponent = rotationIndicatorComponent.createObject(mapControl, { "topIndicator": true })
38 _bottomRotationIndicatorComponent = rotationIndicatorComponent.createObject(mapControl, { "topIndicator": false })
39 mapControl.addMapItem(_topRotationIndicatorComponent)
40 mapControl.addMapItem(_bottomRotationIndicatorComponent)
44 function removeVisuals() {
45 if (_circleComponent) {
46 _circleComponent.destroy()
47 _circleComponent = undefined
49 if (_topRotationIndicatorComponent) {
50 _topRotationIndicatorComponent.destroy()
51 _bottomRotationIndicatorComponent.destroy()
52 _topRotationIndicatorComponent = undefined
53 _bottomRotationIndicatorComponent = undefined
57 function addDragHandles() {
58 if (!_dragHandlesComponent) {
59 _dragHandlesComponent = dragHandlesComponent.createObject(mapControl)
63 function removeDragHandles() {
64 if (_dragHandlesComponent) {
65 _dragHandlesComponent.destroy()
66 _dragHandlesComponent = undefined
70 function updateInternalComponents() {
84 Component.onCompleted: {
85 updateInternalComponents()
88 Component.onDestruction: {
93 onInteractiveChanged: updateInternalComponents()
94 onVisibleChanged: updateInternalComponents()
97 id: rotationIndicatorComponent
100 visible: mapCircle.showRotation
101 property bool topIndicator: true
103 property real _rotationRadius: _radius
105 function updateCoordinate() {
106 coordinate = mapCircle.center.atDistanceAndAzimuth(_radius, topIndicator ? 0 : 180)
109 Component.onCompleted: updateCoordinate()
111 on_RotationRadiusChanged: updateCoordinate()
115 function onCenterChanged() { updateCoordinate() }
119 width: ScreenTools.defaultFontPixelHeight
120 height: ScreenTools.defaultFontPixelHeight
121 anchors.centerIn: parent
123 transform: Rotation {
126 angle: (mapCircle.clockwiseRotation ? 0 : 180) + (topIndicator ? 180 : 0)
131 strokeColor: borderColor
132 fillColor: borderColor
135 PathLine { x: width; y: width }
136 PathLine { x: width; y: 0 }
137 PathLine { x: 0; y: width / 2 }
142 onClicked: mapCircle.clockwiseRotation = !mapCircle.clockwiseRotation
143 visible: mapCircle.interactive
154 opacity: interiorOpacity
155 border.color: borderColor
156 border.width: borderWidth
157 center: mapCircle.center
163 id: dragHandleComponent
167 anchorPoint.x: dragHandle.width / 2
168 anchorPoint.y: dragHandle.height / 2
169 z: QGroundControl.zOrderMapItems + 2
173 width: dragHandle.width + labelControl.width
174 height: dragHandle.height
178 width: ScreenTools.defaultFontPixelHeight * 1.5
189 bottom: dragHandle.top
190 bottomMargin: ScreenTools.defaultFontPixelHeight * 0.25
191 horizontalCenter: dragHandle.horizontalCenter
193 height: dragHandle.height
194 width: labelText.width + (ScreenTools.defaultFontPixelHeight * 0.25 * 2)
199 visible: _root.radiusLabelVisible
205 anchors.centerIn: labelControl
208 text: QGroundControl.unitsConversion.metersToAppSettingsHorizontalDistanceUnits(_radius).toFixed(0) +
209 " " + QGroundControl.unitsConversion.appSettingsHorizontalDistanceUnitsString
210 verticalAlignment: Text.AlignVCenter
211 visible: labelControl.visible
218 id: centerDragAreaComponent
220 MissionItemIndicatorDrag {
221 mapControl: _root.mapControl
223 onItemCoordinateChanged: mapCircle.center = itemCoordinate
228 id: radiusDragAreaComponent
230 MissionItemIndicatorDrag {
231 mapControl: _root.mapControl
233 onItemCoordinateChanged: mapCircle.radius.rawValue = mapCircle.center.distanceTo(itemCoordinate)
238 id: dragHandlesComponent
241 property var centerDragHandle
242 property var centerDragArea
243 property var radiusDragHandle
244 property var radiusDragArea
245 property var radiusDragCoord: QtPositioning.coordinate()
246 property var circleCenterCoord: mapCircle.center
247 property real circleRadius: _radius
249 function calcRadiusDragCoord() {
250 radiusDragCoord = mapCircle.center.atDistanceAndAzimuth(circleRadius, 90)
253 onCircleCenterCoordChanged: calcRadiusDragCoord()
254 onCircleRadiusChanged: calcRadiusDragCoord()
256 Component.onCompleted: {
257 calcRadiusDragCoord()
258 radiusDragHandle = dragHandleComponent.createObject(mapControl)
259 radiusDragHandle.coordinate = Qt.binding(function() { return radiusDragCoord })
260 mapControl.addMapItem(radiusDragHandle)
261 radiusDragArea = radiusDragAreaComponent.createObject(mapControl, { "itemIndicator": radiusDragHandle, "itemCoordinate": radiusDragCoord } )
262 centerDragHandle = dragHandleComponent.createObject(mapControl, { "visible": _root.centerDragHandleVisible })
263 centerDragHandle.coordinate = Qt.binding(function() { return circleCenterCoord })
264 mapControl.addMapItem(centerDragHandle)
265 centerDragArea = centerDragAreaComponent.createObject(mapControl, { "itemIndicator": centerDragHandle, "itemCoordinate": circleCenterCoord, "visible": _root.centerDragHandleVisible })
268 Component.onDestruction: {
269 centerDragHandle.destroy()
270 centerDragArea.destroy()
271 radiusDragHandle.destroy()
272 radiusDragArea.destroy()