|
| 1 | +/*************************************************************************** |
| 2 | + qgsquickpositionmarker.qml |
| 3 | + -------------------------------------- |
| 4 | + Date : Dec 2017 |
| 5 | + Copyright : (C) 2017 by Peter Petrik |
| 6 | + Email : zilolv at gmail dot com |
| 7 | + *************************************************************************** |
| 8 | + * * |
| 9 | + * This program is free software; you can redistribute it and/or modify * |
| 10 | + * it under the terms of the GNU General Public License as published by * |
| 11 | + * the Free Software Foundation; either version 2 of the License, or * |
| 12 | + * (at your option) any later version. * |
| 13 | + * * |
| 14 | + ***************************************************************************/ |
| 15 | + |
| 16 | +import QtQuick 2.3 |
| 17 | +import QtQuick.Controls 2.2 |
| 18 | +import QtQml 2.2 |
| 19 | +import QtGraphicalEffects 1.0 |
| 20 | +import QgsQuick 0.1 as QgsQuick |
| 21 | + |
| 22 | +/** |
| 23 | + * \brief Graphical representation of physical location on the map. |
| 24 | + * |
| 25 | + * Source position and accuracy taken from PositionKit is drawn as a marker on the map. |
| 26 | + * Marker is grayed out when position is not available. When PositionKit support reading of the accuracy, |
| 27 | + * the circle is drawn around the marker. PositionKit must be connected, for example GPS position source from QgsQuickPositionKit. |
| 28 | + */ |
| 29 | +Item { |
| 30 | + id: positionMarker |
| 31 | + property int size: 48 * QgsQuick.Utils.dp |
| 32 | + |
| 33 | + /** |
| 34 | + * Utils for handling position. |
| 35 | + */ |
| 36 | + property QgsQuick.PositionKit positionKit |
| 37 | + |
| 38 | + /** |
| 39 | + * Color of the marker when position is known. |
| 40 | + */ |
| 41 | + property color baseColor: "darkblue" |
| 42 | + /** |
| 43 | + * Color of the marker when position is unknown (e.g. GPS signal lost). |
| 44 | + */ |
| 45 | + property color unavailableColor: "gray" |
| 46 | + |
| 47 | + /** |
| 48 | + * Whether circle representing accuracy of the position should be rendered. |
| 49 | + */ |
| 50 | + property bool withAccuracy: true |
| 51 | + |
| 52 | + /** |
| 53 | + * Icon for position marker. |
| 54 | + */ |
| 55 | + property var markerIcon: QgsQuick.Utils.getThemeIcon("ic_navigation_black") |
| 56 | + |
| 57 | + /** |
| 58 | + * Source position accuracy circle-shaped indicator around positionMarker. |
| 59 | + */ |
| 60 | + Rectangle { |
| 61 | + id: accuracyIndicator |
| 62 | + visible: withAccuracy && |
| 63 | + positionKit.hasPosition && |
| 64 | + (positionKit.accuracy > 0) && |
| 65 | + (accuracyIndicator.width > positionMarker.size / 2.0) |
| 66 | + x: positionKit.screenPosition.x - width/2 |
| 67 | + y: positionKit.screenPosition.y - height/2 |
| 68 | + width:positionKit.screenAccuracy |
| 69 | + height: accuracyIndicator.width |
| 70 | + color: baseColor |
| 71 | + border.color: "black" |
| 72 | + border.width: 3 * QgsQuick.Utils.dp |
| 73 | + radius: width*0.5 |
| 74 | + opacity: 0.1 |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Position marker. |
| 79 | + */ |
| 80 | + Rectangle { |
| 81 | + id: navigationMarker |
| 82 | + property int borderWidth: 2 * QgsQuick.Utils.dp |
| 83 | + width: positionMarker.size + 20 * QgsQuick.Utils.dp |
| 84 | + height: width |
| 85 | + color: "white" |
| 86 | + border.color: baseColor |
| 87 | + border.width: borderWidth |
| 88 | + radius: width*0.5 |
| 89 | + antialiasing: true |
| 90 | + x: positionKit.screenPosition.x - width/2 |
| 91 | + y: positionKit.screenPosition.y - height/2 |
| 92 | + |
| 93 | + Image { |
| 94 | + id: navigation |
| 95 | + source: positionMarker.markerIcon |
| 96 | + fillMode: Image.PreserveAspectFit |
| 97 | + rotation: positionKit.direction |
| 98 | + anchors.centerIn: parent |
| 99 | + width: positionMarker.size |
| 100 | + height: width |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * Makes positionMarker (navigation) grey if position is unknown. |
| 105 | + */ |
| 106 | + ColorOverlay { |
| 107 | + anchors.fill: navigation |
| 108 | + source: navigation |
| 109 | + color: positionKit.hasPosition ? baseColor : unavailableColor |
| 110 | + rotation: positionKit.direction |
| 111 | + visible: !(positionKit.hasPosition) |
| 112 | + } |
| 113 | + } |
| 114 | +} |
| 115 | + |
0 commit comments