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
7pragma ValueTypeBehavior: Addressable
8
9import QtQuick
10import QtQuick.Layouts
11import org.kde.kosmindoormap
12import QtQuick.Controls as QQC2
13
14/** QML item for displaying a train station or airport map. */
15Item {
16 id: mapRoot
17
18 /** Access to map loading status and progress. */
19 property alias mapLoader: map.loader
20 /** Path to a MapCSS style sheet used for rendering the map. */
21 property alias styleSheet: map.styleSheet
22 /** Floor level model. */
23 property alias floorLevels: map.floorLevels
24 /** Access to the view transformation and floor level selection. */
25 property alias view: map.view
26 /** There is something preventing displaying a map. */
27 property alias hasError: map.hasError
28 /** Access to the map data, for feeding into content-specific models. */
29 property alias mapData: map.mapData
30 /** Access to overlay sources. */
31 property alias overlaySources: map.overlaySources
32 /** ISO 3166-1/2 country or region code for opening hours interpretation. */
33 property alias region: map.region
34 /** IANA timezone id for opening hours interpretation. */
35 property alias timeZone: map.timeZone
36 /** Currently hovered element. */
37 property alias hoveredElement: map.hoveredElement
38
39 /** Emitted when a map element has been picked by clicking/tapping on it.
40 * @deprecated Use tapped() instead.
41 */
42 signal elementPicked(var element);
43 /** Emitted when a map element has been long-pressed.
44 * @deprecated Use longPressed() instead.
45 */
46 signal elementLongPressed(var element);
47
48 /** Emitted on a tap or click event on the map. */
49 signal tapped(mapPointerEvent event);
50 /** Emitted on a long press event on the map. */
51 signal longPressed(mapPointerEvent event);
52
53 /** Map an event handler EventPoint to map screen coordinates. */
54 function mapEventPointToScreen(eventPoint) {
55 let root = mapRoot.parent;
56 while (root.parent) { root = root.parent; }
57 return map.mapFromItem(root, eventPoint.scenePosition.x, eventPoint.scenePosition.y);
58 }
59 /** Map an event handler EventPoint to geo coordinates. */
60 function mapEventPointToGeo(eventPoint) {
61 return map.view.mapSceneToGeoPoint(map.view.mapScreenToScene(mapRoot.mapEventPointToScreen(eventPoint)));
62 }
63
64 /** Returns the OSM element at the given screen position, if any. */
65 function elementAt(screenPosition) {
66 return map.elementAt(screenPosition.x, screenPosition.y);
67 }
68
69 MapItemImpl {
70 id: map
71 anchors.fill: mapRoot
72 }
73
74 Flickable {
75 id: flickable
76 boundsBehavior: Flickable.StopAtBounds
77 clip: true
78 interactive: !pinchHandler.active
79 contentX: map.view.panX
80 contentY: map.view.panY
81 contentWidth: map.view.panWidth
82 contentHeight: map.view.panHeight
83 anchors.fill: parent
84
85 onContentXChanged: {
86 if (moving) {
87 map.view.panTopLeft(flickable.contentX, flickable.contentY);
88 map.update();
89 }
90 }
91 onContentYChanged: {
92 if (moving) {
93 map.view.panTopLeft(flickable.contentX, flickable.contentY);
94 map.update();
95 }
96 }
97
98 QQC2.ScrollBar.vertical: QQC2.ScrollBar {}
99 QQC2.ScrollBar.horizontal: QQC2.ScrollBar {}
100
101 TapHandler {
102 id: tapHandler
103 acceptedButtons: Qt.LeftButton | Qt.RightButton
104 onTapped: (eventPoint, button) => {
105 const ev = {
106 element: mapRoot.elementAt(mapRoot.mapEventPointToScreen(eventPoint)),
107 geoPosition: mapRoot.mapEventPointToGeo(eventPoint),
108 screenPosition: mapRoot.mapEventPointToScreen(eventPoint),
109 button: button,
110 modifiers: tapHandler.point.modifiers,
111 } as mapPointerEvent;
112 if (!ev.element.isNull) {
113 elementPicked(ev.element);
114 }
115 mapRoot.tapped(ev);
116 }
117 onLongPressed: function() {
118 const ev = {
119 element: mapRoot.elementAt(mapRoot.mapEventPointToScreen(tapHandler.point)),
120 geoPosition: mapRoot.mapEventPointToGeo(tapHandler.point),
121 screenPosition: mapRoot.mapEventPointToScreen(tapHandler.point),
122 button: tapHandler.point.pressedButtons,
123 modifiers: tapHandler.point.modifiers,
124 } as mapPointerEvent;
125 if (!ev.element.isNull) {
126 elementLongPressed(ev.element);
127 }
128 mapRoot.longPressed(ev);
129 }
130 }
131 PinchHandler {
132 id: pinchHandler
133 target: null
134 property double initialZoom
135 onActiveChanged: {
136 initialZoom = map.view.zoomLevel
137 }
138 onActiveScaleChanged: {
139 map.view.setZoomLevel(pinchHandler.initialZoom + Math.log2(pinchHandler.activeScale),
140 Qt.point(pinchHandler.centroid.position.x - flickable.contentX, pinchHandler.centroid.position.y - flickable.contentY));
141 }
142 xAxis.enabled: false
143 yAxis.enabled: false
144 minimumRotation: 0.0
145 maximumRotation: 0.0
146 }
148 id: wheelHandler
149 target: null
150 orientation: Qt.Vertical
151 acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad
152 property double initialZoom: 0.0
153 onActiveChanged: {
154 wheelHandler.initialZoom = map.view.zoomLevel
155 wheelHandler.rotation = 0;
156 }
157 onRotationChanged: {
158 // same scale as in qquickmapgestrurearea.cpp
159 map.view.setZoomLevel(wheelHandler.initialZoom + 0.05 * wheelHandler.rotation,
160 Qt.point(wheelHandler.point.position.x - flickable.contentX, wheelHandler.point.position.y - flickable.contentY));
161 }
162 }
163 }
164
165 Connections {
166 target: map.view
167 function onTransformationChanged() {
168 flickable.contentX = map.view.panX;
169 flickable.contentY = map.view.panY;
170 }
171 }
172
173 QQC2.BusyIndicator {
174 anchors.centerIn: parent
175 running: map.loader.isLoading
176 }
177
178 QQC2.Label {
179 anchors.fill: parent
180 text: map.errorMessage
181 visible: map.hasError
182 wrapMode: Text.WordWrap
183 horizontalAlignment: Qt.AlignHCenter
184 verticalAlignment: Qt.AlignVCenter
185 }
186}
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 Fri Jul 26 2024 11:57:46 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.