KOSMIndoorMap

IndoorMap.qml
1/*
2 SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7import QtQuick
8import QtQuick.Layouts
9import org.kde.kosmindoormap
10import QtQuick.Controls as QQC2
12/** QML item for displaying a train station or airport map. */
13Item {
14 id: mapRoot
15
16 /** Access to map loading status and progress. */
17 property alias mapLoader: map.loader
18 /** Path to a MapCSS style sheet used for rendering the map. */
19 property alias styleSheet: map.styleSheet
20 /** Floor level model. */
21 property alias floorLevels: map.floorLevels
22 /** Access to the view transformation and floor level selection. */
23 property alias view: map.view
24 /** There is something preventing displaying a map. */
25 property alias hasError: map.hasError
26 /** Access to the map data, for feeding into content-specific models. */
27 property alias mapData: map.mapData
28 /** Access to overlay sources. */
29 property alias overlaySources: map.overlaySources
30 /** ISO 3166-1/2 country or region code for opening hours interpretation. */
31 property alias region: map.region
32 /** IANA timezone id for opening hours interpretation. */
33 property alias timeZone: map.timeZone
34 /** Currently hovered element. */
35 property alias hoveredElement: map.hoveredElement
37 /** Emitted when a map element has been picked by clicking/tapping on it. */
38 signal elementPicked(var element);
39 /** Emitted when a map element has been long-pressed. */
40 signal elementLongPressed(var element);
41
42 /** Map an event handler EventPoint to map screen coordinates. */
43 function mapEventPointToScreen(eventPoint) {
44 let root = mapRoot.parent;
45 while (root.parent) { root = root.parent; }
46 return map.mapFromItem(root, eventPoint.scenePosition.x, eventPoint.scenePosition.y);
47 }
48
49 /** Returns the OSM element at the given screen position, if any. */
50 function elementAt(screenPosition) {
51 return map.elementAt(screenPosition.x, screenPosition.y);
52 }
53
54 MapItemImpl {
55 id: map
56 anchors.fill: mapRoot
57 }
58
59 Flickable {
60 id: flickable
61 boundsBehavior: Flickable.StopAtBounds
62 clip: true
63 interactive: !pinchHandler.active
64 contentX: map.view.panX
65 contentY: map.view.panY
66 contentWidth: map.view.panWidth
67 contentHeight: map.view.panHeight
68 anchors.fill: parent
69
70 onContentXChanged: {
71 if (moving) {
72 map.view.panTopLeft(flickable.contentX, flickable.contentY);
73 map.update();
74 }
75 }
76 onContentYChanged: {
77 if (moving) {
78 map.view.panTopLeft(flickable.contentX, flickable.contentY);
79 map.update();
80 }
81 }
82
83 QQC2.ScrollBar.vertical: QQC2.ScrollBar {}
84 QQC2.ScrollBar.horizontal: QQC2.ScrollBar {}
85
86 TapHandler {
87 id: tapHandler
88 acceptedButtons: Qt.LeftButton
89 onTapped: function(eventPoint) {
90 const element = mapRoot.elementAt(mapRoot.mapEventPointToScreen(eventPoint));
91 if (!element.isNull) {
92 elementPicked(element);
93 }
94 }
95 onLongPressed: function() {
96 const element = mapRoot.elementAt(mapRoot.mapEventPointToScreen(tapHandler.point));
97 if (!element.isNull) {
98 elementLongPressed(element);
99 }
100 }
101 }
102 PinchHandler {
103 id: pinchHandler
104 target: null
105 property double initialZoom
106 onActiveChanged: {
107 initialZoom = map.view.zoomLevel
108 }
109 onActiveScaleChanged: {
110 map.view.setZoomLevel(pinchHandler.initialZoom + Math.log2(pinchHandler.activeScale),
111 Qt.point(pinchHandler.centroid.position.x - flickable.contentX, pinchHandler.centroid.position.y - flickable.contentY));
112 }
113 xAxis.enabled: false
114 yAxis.enabled: false
115 minimumRotation: 0.0
116 maximumRotation: 0.0
117 }
119 id: wheelHandler
120 target: null
121 orientation: Qt.Vertical
122 acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad
123 property double initialZoom: 0.0
124 onActiveChanged: {
125 wheelHandler.initialZoom = map.view.zoomLevel
126 wheelHandler.rotation = 0;
127 }
128 onRotationChanged: {
129 // same scale as in qquickmapgestrurearea.cpp
130 map.view.setZoomLevel(wheelHandler.initialZoom + 0.05 * wheelHandler.rotation,
131 Qt.point(wheelHandler.point.position.x - flickable.contentX, wheelHandler.point.position.y - flickable.contentY));
132 }
133 }
134 }
135
136 Connections {
137 target: map.view
138 function onTransformationChanged() {
139 flickable.contentX = map.view.panX;
140 flickable.contentY = map.view.panY;
141 }
142 }
143
144 QQC2.BusyIndicator {
145 anchors.centerIn: parent
146 running: map.loader.isLoading
147 }
148
149 QQC2.Label {
150 anchors.fill: parent
151 text: map.errorMessage
152 visible: map.hasError
153 wrapMode: Text.WordWrap
154 horizontalAlignment: Qt.AlignHCenter
155 verticalAlignment: Qt.AlignVCenter
156 }
157}
@ Text
maximum width before wrapping
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:20:03 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.