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

KDE's Doxygen guidelines are available online.