From 633239ff830a9c72ae88d53329875878a8876e66 Mon Sep 17 00:00:00 2001 From: Matthias Rauter Date: Mon, 27 Feb 2023 09:43:20 +0100 Subject: Update Mapviewer example Removed MapItems and argument parsing for old plugins. Replaced some circles with markers. Updated documentation and resources. Pick-to: 6.5 Change-Id: I2c33d33d52ba2f5c1c81f444e8b414a4349dc505 Reviewed-by: Volker Hilsheimer Reviewed-by: Shawn Rutledge --- examples/location/mapviewer/CMakeLists.txt | 7 +- examples/location/mapviewer/doc/src/mapviewer.qdoc | 14 ++- examples/location/mapviewer/main.cpp | 20 --- examples/location/mapviewer/map/CircleItem.qml | 28 ----- examples/location/mapviewer/map/ImageItem.qml | 32 ----- examples/location/mapviewer/map/MapComponent.qml | 134 ++++++++------------- examples/location/mapviewer/map/PolygonItem.qml | 32 ----- examples/location/mapviewer/map/PolylineItem.qml | 30 ----- examples/location/mapviewer/map/RectangleItem.qml | 29 ----- examples/location/mapviewer/mapviewer.pro | 5 - examples/location/mapviewer/mapviewer.qml | 18 --- examples/location/mapviewer/mapviewer.qrc | 6 +- examples/location/mapviewer/menus/MapPopupMenu.qml | 32 +---- .../location/mapviewer/menus/MarkerPopupMenu.qml | 8 +- examples/location/mapviewer/resources/icon.png | Bin 1859 -> 0 bytes .../location/mapviewer/resources/marker_blue.png | Bin 0 -> 3523 bytes 16 files changed, 68 insertions(+), 327 deletions(-) delete mode 100644 examples/location/mapviewer/map/CircleItem.qml delete mode 100644 examples/location/mapviewer/map/ImageItem.qml delete mode 100644 examples/location/mapviewer/map/PolygonItem.qml delete mode 100644 examples/location/mapviewer/map/PolylineItem.qml delete mode 100644 examples/location/mapviewer/map/RectangleItem.qml delete mode 100644 examples/location/mapviewer/resources/icon.png create mode 100644 examples/location/mapviewer/resources/marker_blue.png diff --git a/examples/location/mapviewer/CMakeLists.txt b/examples/location/mapviewer/CMakeLists.txt index 5db82ee4..e7cea469 100644 --- a/examples/location/mapviewer/CMakeLists.txt +++ b/examples/location/mapviewer/CMakeLists.txt @@ -54,22 +54,17 @@ set(mapviewer_resource_files "forms/RouteListDelegate.qml" "forms/RouteListHeader.qml" "helper.js" - "map/CircleItem.qml" - "map/ImageItem.qml" "map/MapComponent.qml" "map/MapSliders.qml" "map/Marker.qml" "map/MiniMap.qml" - "map/PolygonItem.qml" - "map/PolylineItem.qml" - "map/RectangleItem.qml" "mapviewer.qml" "menus/ItemPopupMenu.qml" "menus/MainMenu.qml" "menus/MapPopupMenu.qml" "menus/MarkerPopupMenu.qml" - "resources/icon.png" "resources/marker.png" + "resources/marker_blue.png" "resources/scale.png" "resources/scale_end.png" ) diff --git a/examples/location/mapviewer/doc/src/mapviewer.qdoc b/examples/location/mapviewer/doc/src/mapviewer.qdoc index 692e4b45..b1d2e01d 100644 --- a/examples/location/mapviewer/doc/src/mapviewer.qdoc +++ b/examples/location/mapviewer/doc/src/mapviewer.qdoc @@ -27,7 +27,7 @@ \li Displaying a map \list \li \l{QtLocation::Map}{Map} - \li \l{QtLocation::MapGestureArea}{MapGestureArea} + \li \l{QtLocation::MapView}{MapView} \li \l[QML]{coordinate} \endlist \li Finding an address @@ -45,13 +45,15 @@ \section1 Displaying a Map - Drawing a map on-screen is accomplished using the Map type, as shown + Drawing a map on-screen is accomplished using the MapView type, as shown below. \snippet mapviewer/map/MapComponent.qml top \snippet mapviewer/map/MapComponent.qml coord \snippet mapviewer/map/MapComponent.qml end + The MapView consists of a \l {MapView::map}{map} and extends it for basic navigation + capabilities. In this example, we give the map an initial center \l [QML]{coordinate} with a set latitude and longitude. We also set the initial zoom level to 50% (halfway between the maximum and minimum). @@ -70,9 +72,9 @@ \snippet mapviewer/map/MapComponent.qml geocodeview - MapItemView uses an object called a "delegate" to act as a template for the + MapItemView uses an object called a \c{delegate} to act as a template for the items it creates. This can contain any map object desired, but in this case - we show a MapCircle: + we show a MapQuickItem that contains an image of a marker: \snippet mapviewer/map/MapComponent.qml pointdel0 \snippet mapviewer/map/MapComponent.qml pointdel1 @@ -86,7 +88,7 @@ \snippet mapviewer/mapviewer.qml geocode0 - Then we set "geocodeModel.query" to the filled in \l [QML]{Address}, + Then we set \c{geocodeModel.query} to the filled in \l [QML]{Address}, and call update() on the GeocodeModel. \snippet mapviewer/map/MapComponent.qml geocode1 @@ -95,7 +97,7 @@ Similar to the GeocodeModel, Qt Location also features the RouteModel type, which allows information about routes (for example driving directions) between two - or more points, to be received and used with a Map. + or more points, to be received and used with a \l{Map}. Here again, we instantiate the RouteModel as a property of our Map: diff --git a/examples/location/mapviewer/main.cpp b/examples/location/mapviewer/main.cpp index cc3a465f..b24bb392 100644 --- a/examples/location/mapviewer/main.cpp +++ b/examples/location/mapviewer/main.cpp @@ -61,26 +61,6 @@ int main(int argc, char *argv[]) QVariantMap parameters; QStringList args(QCoreApplication::arguments()); - // Fetch tokens from the environment, if present - const QByteArray mapboxMapID = qgetenv("MAPBOX_MAP_ID"); - const QByteArray mapboxAccessToken = qgetenv("MAPBOX_ACCESS_TOKEN"); - const QByteArray hereAppID = qgetenv("HERE_APP_ID"); - const QByteArray hereToken = qgetenv("HERE_TOKEN"); - const QByteArray esriToken = qgetenv("ESRI_TOKEN"); - - if (!mapboxMapID.isEmpty()) - parameters["mapbox.map_id"] = QString::fromLocal8Bit(mapboxMapID); - if (!mapboxAccessToken.isEmpty()) { - parameters["mapbox.access_token"] = QString::fromLocal8Bit(mapboxAccessToken); - parameters["mapboxgl.access_token"] = QString::fromLocal8Bit(mapboxAccessToken); - } - if (!hereAppID.isEmpty()) - parameters["here.app_id"] = QString::fromLocal8Bit(hereAppID); - if (!hereToken.isEmpty()) - parameters["here.token"] = QString::fromLocal8Bit(hereToken); - if (!esriToken.isEmpty()) - parameters["esri.token"] = QString::fromLocal8Bit(esriToken); - if (parseArgs(args, parameters)) return 0; if (!args.contains(QStringLiteral("osm.useragent"))) diff --git a/examples/location/mapviewer/map/CircleItem.qml b/examples/location/mapviewer/map/CircleItem.qml deleted file mode 100644 index a5cae752..00000000 --- a/examples/location/mapviewer/map/CircleItem.qml +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -import QtQuick -import QtLocation - -MapCircle { - - color: "#da5546" - border.color: "#330a0a" - border.width: 2 - smooth: true - opacity: 0.75 - - function setGeometry(anchorCoordinate) { - center = anchorCoordinate - } - - function addGeometry(newCoordinate, changeLast){ - radius = center.distanceTo(newCoordinate) - return true - } - - function finishAddGeometry(){ - color = "#46a2da" - border.color = "#190a33" - opacity = 0.25 - } -} diff --git a/examples/location/mapviewer/map/ImageItem.qml b/examples/location/mapviewer/map/ImageItem.qml deleted file mode 100644 index 433b12ef..00000000 --- a/examples/location/mapviewer/map/ImageItem.qml +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -import QtQuick -import QtLocation - -MapQuickItem { //to be used inside MapComponent only - id: imageItem - - anchorPoint.x: testImage.width/2 - anchorPoint.y: testImage.height/2 - - function setGeometry(anchorCoordinate) { - coordinate = anchorCoordinate - } - - function addGeometry(newCoordinate, changeLast){ - var p1 = view.map.fromCoordinate(coordinate, false); - var p2 = view.map.fromCoordinate(newCoordinate, false); - var size = Math.max(Math.abs((p1.x-p2.x)), Math.abs((p1.y-p2.y))); - testImage.scale = Math.max(0.1, size/Math.max(testImage.height, testImage.width))*2 - return true - } - - function finishAddGeometry(){ - } - - sourceItem: Image { - id: testImage - source: "../resources/icon.png" - opacity: 0.7 - } -} diff --git a/examples/location/mapviewer/map/MapComponent.qml b/examples/location/mapviewer/map/MapComponent.qml index 149c0e47..6f887536 100644 --- a/examples/location/mapviewer/map/MapComponent.qml +++ b/examples/location/mapviewer/map/MapComponent.qml @@ -20,7 +20,6 @@ MapView { property alias routeModel: routeModel property alias geocodeModel: geocodeModel property alias slidersExpanded: sliders.expanded - property variant unfinishedItem: 'undefined' signal showGeocodeInfo() signal geocodeFinished() @@ -97,15 +96,6 @@ MapView { view.markers = [] } - function deleteMapItems() - { - var count = view.mapItems.length - for (var i = count-1; i>=0; i--){ - view.map.removeMapItem(view.mapItems[i]) - } - view.mapItems = [] - } - function addMarker() { var count = view.markers.length @@ -117,21 +107,6 @@ MapView { markers.push(marker) } - function addGeoItem(item) - { - var count = view.map.mapItems.length - var co = Qt.createComponent(item+'.qml') - if (co.status === Component.Ready) { - unfinishedItem = co.createObject(map) - unfinishedItem.setGeometry(tapHandler.lastCoordinate) - unfinishedItem.addGeometry(hoverHandler.currentCoordinate, false) - view.map.addMapItem(unfinishedItem) - mapItems.push(unfinishedItem) - } else { - console.log(item + " is not supported right now, please call us later.") - } - } - function deleteMarker(index) { //update list of markers @@ -248,20 +223,9 @@ MapView { var mapCenterPoint = Qt.point(view.map.width / 2.0 - dx, view.map.height / 2.0 - dy); view.map.center = view.map.toCoordinate(mapCenterPoint); - } else if (event.key === Qt.Key_Escape) { - mapview.unfinishedItem.finishAddGeometry() - mapview.unfinishedItem = 'undefined' } } - /* @todo - Binding { - target: map - property: 'center' - value: positionSource.position.coordinate - when: followme - }*/ - PositionSource{ id: positionSource active: followme @@ -271,6 +235,30 @@ MapView { } } + MapQuickItem { + id: mePoisition + parent: view.map + sourceItem: Rectangle { width: 14; height: 14; color: "#251ee4"; border.width: 2; border.color: "white"; smooth: true; radius: 7 } + coordinate: positionSource.position.coordinate + opacity: 1.0 + anchorPoint: Qt.point(sourceItem.width/2, sourceItem.height/2) + visible: followme + } + MapQuickItem { + parent: view.map + sourceItem: Text{ + text: qsTr("You're here!") + color:"#242424" + font.bold: true + styleColor: "#ECECEC" + style: Text.Outline + } + coordinate: positionSource.position.coordinate + anchorPoint: Qt.point(-mePoisition.sourceItem.width * 0.5, mePoisition.sourceItem.height * 1.5) + visible: followme + } + + MapQuickItem { id: poiTheQtComapny parent: view.map @@ -293,7 +281,7 @@ MapView { style: Text.Outline } coordinate: poiTheQtComapny.coordinate - anchorPoint: Qt.point(-poiTheQtComapny.sourceItem.width * 0.5,poiTheQtComapny.sourceItem.height * 1.5) + anchorPoint: Qt.point(-poiTheQtComapny.sourceItem.width * 0.5, poiTheQtComapny.sourceItem.height * 1.5) } MapSliders { @@ -412,29 +400,37 @@ MapView { Component { id: pointDelegate - MapCircle { + MapQuickItem { id: point parent: view.map - radius: 1000 - color: "#46a2da" - border.color: "#190a33" - border.width: 2 - smooth: true - opacity: 0.25 - center: locationData.coordinate - //! [pointdel0] - /* TapHandler { - point.onPositionChanged: { - if (Math.abs(view.map.pressX - parent.x - point.position.x) > view.map.jitterThreshold || - Math.abs(view.map.pressY - parent.y - point.position.y) > view.map.jitterThreshold) { - if (pressed) - parent.radius = parent.center.distanceTo(view.map.toCoordinate(point.position)) - } + coordinate: locationData.coordinate + + sourceItem: Image { + id: pointMarker + source: "../resources/marker_blue.png" + //! [pointdel0] + + Text{ + id: pointText + anchors.bottom: pointMarker.top + anchors.horizontalCenter: pointMarker.horizontalCenter + text: locationData.address.street + ", " + locationData.address.city + color:"#242424" + font.bold: true + styleColor: "#ECECEC" + style: Text.Outline } - onLongPressed: showPointMenu(view.map.toCoordinate(point.position)) - }*/ - //! [pointdel1] + } + smooth: true + autoFadeIn: false + anchorPoint.x: pointMarker.width/4 + anchorPoint.y: pointMarker.height + + TapHandler { + onLongPressed: showPointMenu(point.coordinate) + //! [pointdel1] + } } } //! [pointdel1] @@ -464,19 +460,6 @@ MapView { onTriggered: view.calculateScale() } - HoverHandler { - id: hoverHandler - property variant currentCoordinate - grabPermissions: PointerHandler.CanTakeOverFromItems | PointerHandler.CanTakeOverFromHandlersOfDifferentType - - onPointChanged: { - currentCoordinate = view.map.toCoordinate(hoverHandler.point.position) - if (mapview.unfinishedItem !== 'undefined') - mapview.unfinishedItem.addGeometry(view.map.toCoordinate(hoverHandler.point.position), true) - } - - } - TapHandler { id: tapHandler property variant lastCoordinate @@ -490,18 +473,7 @@ MapView { onSingleTapped: (eventPoint, button) => { if (button === Qt.RightButton) { - if (mapview.unfinishedItem !== 'undefined') { - mapview.unfinishedItem.finishAddGeometry() - mapview.unfinishedItem = 'undefined' - } else - showMainMenu(lastCoordinate) - } else if (button === Qt.LeftButton) { - if (mapview.unfinishedItem !== 'undefined') { - if (mapview.unfinishedItem.addGeometry(view.map.toCoordinate(tapHandler.point.position), false)) { - mapview.unfinishedItem.finishAddGeometry() - mapview.unfinishedItem = 'undefined' - } - } + showMainMenu(lastCoordinate) } } diff --git a/examples/location/mapviewer/map/PolygonItem.qml b/examples/location/mapviewer/map/PolygonItem.qml deleted file mode 100644 index d9a2be99..00000000 --- a/examples/location/mapviewer/map/PolygonItem.qml +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -import QtQuick -import QtLocation - -MapPolygon { - - color: "#da5546" - border.color: "#330a0a" - border.width: 2 - smooth: true - opacity: 0.75 - - function setGeometry(anchorCoordinate){ - addCoordinate(anchorCoordinate) - } - - function addGeometry(newCoordinate, changeLast){ - if (changeLast && path.length > 0) - removeCoordinate(path[path.length-1]) - addCoordinate(newCoordinate) - return false - } - - function finishAddGeometry(){ - if (path.length > 0) - removeCoordinate(path[path.length-1]) - color = "#46a2da" - border.color = "#190a33" - opacity = 0.25 - } -} diff --git a/examples/location/mapviewer/map/PolylineItem.qml b/examples/location/mapviewer/map/PolylineItem.qml deleted file mode 100644 index 727ce973..00000000 --- a/examples/location/mapviewer/map/PolylineItem.qml +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -import QtQuick -import QtLocation - -MapPolyline { - - line.color: "#330a0a" - line.width: 4 - opacity: 0.75 - smooth: true - - function setGeometry(anchorCoordinate){ - addCoordinate(anchorCoordinate) - } - - function addGeometry(newCoordinate, changeLast){ - if (changeLast) - replaceCoordinate(pathLength()-1, newCoordinate) - else - addCoordinate(newCoordinate) - return false - } - - function finishAddGeometry(){ - removeCoordinate(pathLength()-1) - line.color = "#46a2da" - opacity = 0.25 - } -} diff --git a/examples/location/mapviewer/map/RectangleItem.qml b/examples/location/mapviewer/map/RectangleItem.qml deleted file mode 100644 index 85d91a6f..00000000 --- a/examples/location/mapviewer/map/RectangleItem.qml +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause -import QtQuick -import QtLocation - -MapRectangle { - id: mapRectangle - - color: "#da5546" - border.color: "#330a0a" - border.width: 2 - smooth: true - opacity: 0.75 - - function setGeometry(anchorCoordinate) { - topLeft = anchorCoordinate - } - - function addGeometry(newCoordinate, changeLast){ - bottomRight = newCoordinate - return true //finished - } - - function finishAddGeometry(){ - color = "#46a2da" - border.color = "#190a33" - opacity = 0.25 - } -} diff --git a/examples/location/mapviewer/mapviewer.pro b/examples/location/mapviewer/mapviewer.pro index a8a868b8..1013eee9 100644 --- a/examples/location/mapviewer/mapviewer.pro +++ b/examples/location/mapviewer/mapviewer.pro @@ -16,11 +16,6 @@ OTHER_FILES +=mapviewer.qml \ map/MapComponent.qml \ map/MapSliders.qml \ map/Marker.qml \ - map/CircleItem.qml \ - map/RectangleItem.qml \ - map/PolylineItem.qml \ - map/PolygonItem.qml \ - map/ImageItem.qml \ map/MiniMap.qml \ menus/ItemPopupMenu.qml \ menus/MainMenu.qml \ diff --git a/examples/location/mapviewer/mapviewer.qml b/examples/location/mapviewer/mapviewer.qml index 4f9a2907..4e93d9e4 100644 --- a/examples/location/mapviewer/mapviewer.qml +++ b/examples/location/mapviewer/mapviewer.qml @@ -262,24 +262,6 @@ ApplicationWindow { case "deleteMarkers": mapview.deleteMarkers() break - case "deleteItems": - mapview.deleteMapItems() - break - case "drawImage": - mapview.addGeoItem("ImageItem") - break - case "drawRectangle": - mapview.addGeoItem("RectangleItem") - break - case "drawCircle": - mapview.addGeoItem("CircleItem") - break; - case "drawPolyline": - mapview.addGeoItem("PolylineItem") - break; - case "drawPolygonMenu": - mapview.addGeoItem("PolygonItem") - break default: console.log("Unsupported operation:", item) } diff --git a/examples/location/mapviewer/mapviewer.qrc b/examples/location/mapviewer/mapviewer.qrc index 7a7d1f4c..4e30c660 100644 --- a/examples/location/mapviewer/mapviewer.qrc +++ b/examples/location/mapviewer/mapviewer.qrc @@ -4,11 +4,6 @@ map/MapComponent.qml map/MapSliders.qml map/Marker.qml - map/PolylineItem.qml - map/RectangleItem.qml - map/CircleItem.qml - map/PolygonItem.qml - map/ImageItem.qml map/MiniMap.qml forms/Message.qml forms/MessageForm.ui.qml @@ -33,6 +28,7 @@ resources/scale_end.png resources/scale.png resources/marker.png + resources/marker_blue.png resources/icon.png diff --git a/examples/location/mapviewer/menus/MapPopupMenu.qml b/examples/location/mapviewer/menus/MapPopupMenu.qml index cb0c8254..71cf6f48 100644 --- a/examples/location/mapviewer/menus/MapPopupMenu.qml +++ b/examples/location/mapviewer/menus/MapPopupMenu.qml @@ -19,7 +19,7 @@ Menu { onTriggered: itemClicked("getCoordinate") } MenuItem { - text: qsTr("Fit Viewport To Map Items") + text: qsTr("Fit Viewport To Markers") onTriggered: itemClicked("fitViewport") } MenuItem { @@ -27,34 +27,4 @@ Menu { enabled: markersCount > 0 onTriggered: itemClicked("deleteMarkers") } - MenuItem { - text: qsTr("Delete all items") - enabled: mapItemsCount > 0 - onTriggered: itemClicked("deleteItems") - } - - Menu { - title: qsTr("Draw...") - - MenuItem { - text: qsTr("Image") - onTriggered: itemClicked("drawImage") - } - MenuItem { - text: qsTr("Rectangle") - onTriggered: itemClicked("drawRectangle") - } - MenuItem { - text: qsTr("Circle") - onTriggered: itemClicked("drawCircle") - } - MenuItem { - text: qsTr("Polyline") - onTriggered: itemClicked("drawPolyline") - } - MenuItem { - text: qsTr("Polygon") - onTriggered: itemClicked("drawPolygonMenu") - } - } } diff --git a/examples/location/mapviewer/menus/MarkerPopupMenu.qml b/examples/location/mapviewer/menus/MarkerPopupMenu.qml index 525c950c..4cbd2cb5 100644 --- a/examples/location/mapviewer/menus/MarkerPopupMenu.qml +++ b/examples/location/mapviewer/menus/MarkerPopupMenu.qml @@ -22,15 +22,15 @@ Menu { onTriggered: itemClicked("moveMarkerTo") } MenuItem { - text: currentMarker < markersCount-2 ? qsTr("Route to next points") - : qsTr("Route to next point") + text: currentMarker < markersCount-2 ? qsTr("Route to next markers") + : qsTr("Route to next marker") enabled: currentMarker <= markersCount - 2 onTriggered: currentMarker < markersCount-2 ? itemClicked("routeToNextPoints") : itemClicked("routeToNextPoint") } MenuItem { - text: currentMarker < markersCount-2 ? qsTr("Distance to next points") - : qsTr("Distance to next point") + text: currentMarker < markersCount-2 ? qsTr("Distance to next markers") + : qsTr("Distance to next marker") enabled: currentMarker <= markersCount - 2 onTriggered: currentMarker < markersCount-2 ? itemClicked("distanceToNextPoints") : itemClicked("distanceToNextPoint") diff --git a/examples/location/mapviewer/resources/icon.png b/examples/location/mapviewer/resources/icon.png deleted file mode 100644 index 973a5009..00000000 Binary files a/examples/location/mapviewer/resources/icon.png and /dev/null differ diff --git a/examples/location/mapviewer/resources/marker_blue.png b/examples/location/mapviewer/resources/marker_blue.png new file mode 100644 index 00000000..70f0c253 Binary files /dev/null and b/examples/location/mapviewer/resources/marker_blue.png differ -- cgit v1.2.1