diff options
author | Michal Klocek <michal.klocek@theqtcompany.com> | 2015-02-20 16:16:31 +0100 |
---|---|---|
committer | Alex Blasche <alexander.blasche@theqtcompany.com> | 2015-04-14 06:47:18 +0000 |
commit | 243be754315c052a5626a640be9eca4f7055704e (patch) | |
tree | 1eba9d5fea7d6033be5d9d45d9f610e3ebf16c84 /examples/location/mapviewer/map | |
parent | ee1deee9a2293a82829efc724ad448aa9a210ae1 (diff) | |
download | qtlocation-243be754315c052a5626a640be9eca4f7055704e.tar.gz |
Clean up files in mapviewer example.
Rename files, move the subdirectories, remove
obsolete dependencies to location examples plugin.
Conflicts:
examples/location/mapviewer/mapviewer.pro
Change-Id: Id85dfffc32761eb9d2999b8e07b87f9912700659
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'examples/location/mapviewer/map')
-rw-r--r-- | examples/location/mapviewer/map/CircleItem.qml | 58 | ||||
-rw-r--r-- | examples/location/mapviewer/map/ImageItem.qml | 61 | ||||
-rw-r--r-- | examples/location/mapviewer/map/MapComponent.qml | 589 | ||||
-rw-r--r-- | examples/location/mapviewer/map/Marker.qml | 116 | ||||
-rw-r--r-- | examples/location/mapviewer/map/MiniMap.qml | 80 | ||||
-rw-r--r-- | examples/location/mapviewer/map/PolygonItem.qml | 63 | ||||
-rw-r--r-- | examples/location/mapviewer/map/PolylineItem.qml | 56 | ||||
-rw-r--r-- | examples/location/mapviewer/map/RectangleItem.qml | 74 |
8 files changed, 1097 insertions, 0 deletions
diff --git a/examples/location/mapviewer/map/CircleItem.qml b/examples/location/mapviewer/map/CircleItem.qml new file mode 100644 index 00000000..cc5e6faa --- /dev/null +++ b/examples/location/mapviewer/map/CircleItem.qml @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.0 +import QtLocation 5.3 + +//TODO: remove/refactor me when items are integrated + +MapCircle { + + color: "yellow" + border.color: "red" + border.width: 5 + smooth: true + opacity: 0.5 + + function setGeometry(markers, index){ + center.latitude = markers[index].coordinate.latitude + center.longitude = markers[index].coordinate.longitude + radius= center.distanceTo(markers[index + 1].coordinate) + } +} diff --git a/examples/location/mapviewer/map/ImageItem.qml b/examples/location/mapviewer/map/ImageItem.qml new file mode 100644 index 00000000..9b213406 --- /dev/null +++ b/examples/location/mapviewer/map/ImageItem.qml @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.0; +import QtLocation 5.3 + +MapQuickItem { //to be used inside MapComponent only + id: imageItem + + MouseArea { + anchors.fill: parent + drag.target: parent + } + + function setGeometry(markers, index) { + coordinate.latitude = markers[index].coordinate.latitude + coordinate.longitude = markers[index].coordinate.longitude + } + + 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 new file mode 100644 index 00000000..c6855864 --- /dev/null +++ b/examples/location/mapviewer/map/MapComponent.qml @@ -0,0 +1,589 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.4 +import QtQuick.Controls 1.3 +import QtLocation 5.3 +import QtPositioning 5.2 +import "../helper.js" as Helper + +//! [top] +Map { + id: map + //! [top] + property variant markers + property variant mapItems + property int markerCounter: 0 // counter for total amount of markers. Resets to 0 when number of markers = 0 + property int currentMarker + property int lastX : -1 + property int lastY : -1 + property int pressX : -1 + property int pressY : -1 + property int jitterThreshold : 30 + property bool followme: false + property variant scaleLengths: [5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000, 200000, 500000, 1000000, 2000000] + //! [routemodel0] + property RouteQuery routeQuery: RouteQuery {} + + property RouteModel routeModel: RouteModel { + plugin : map.plugin + query: routeQuery + //! [routemodel0] + + //! [routemodel1] + onStatusChanged: { + if (status == RouteModel.Ready) { + switch (count) { + case 0: + // technically not an error + map.routeError() + break + case 1: + showRouteList() + break + } + } else if (status == RouteModel.Error) { + map.routeError() + } + } + //! [routemodel1] + + //! [routemodel2] + + //! [routemodel2] + //! [routemodel3] + } + //! [routemodel3] + + //! [geocodemodel0] + property GeocodeModel geocodeModel: GeocodeModel { + //! [geocodemodel0] + //! [geocodemodel0 body] + plugin: map.plugin + onStatusChanged: { + if ((status == GeocodeModel.Ready) || (status == GeocodeModel.Error)) + map.geocodeFinished() + } + onLocationsChanged: + { + if (count == 1) { + map.center.latitude = get(0).coordinate.latitude + map.center.longitude = get(0).coordinate.longitude + } + } + //! [geocodemodel0 body] + //! [geocodemodel1] + } + //! [geocodemodel1] + + signal showGeocodeInfo() + signal geocodeFinished() + signal routeError() + signal coordinatesCaptured(double latitude, double longitude) + signal showMainMenu(variant coordinate) + signal showMarkerMenu(variant coordinate) + signal showRouteMenu(variant coordinate) + signal showPointMenu(variant coordinate) + signal showRouteList() + + function geocodeMessage() + { + var street, district, city, county, state, countryCode, country, postalCode, latitude, longitude, text + latitude = Math.round(geocodeModel.get(0).coordinate.latitude * 10000) / 10000 + longitude =Math.round(geocodeModel.get(0).coordinate.longitude * 10000) / 10000 + street = geocodeModel.get(0).address.street + district = geocodeModel.get(0).address.district + city = geocodeModel.get(0).address.city + county = geocodeModel.get(0).address.county + state = geocodeModel.get(0).address.state + countryCode = geocodeModel.get(0).address.countryCode + country = geocodeModel.get(0).address.country + postalCode = geocodeModel.get(0).address.postalCode + + text = "<b>Latitude:</b> " + latitude + "<br/>" + text +="<b>Longitude:</b> " + longitude + "<br/>" + "<br/>" + if (street) text +="<b>Street: </b>"+ street + " <br/>" + if (district) text +="<b>District: </b>"+ district +" <br/>" + if (city) text +="<b>City: </b>"+ city + " <br/>" + if (county) text +="<b>County: </b>"+ county + " <br/>" + if (state) text +="<b>State: </b>"+ state + " <br/>" + if (countryCode) text +="<b>Country code: </b>"+ countryCode + " <br/>" + if (country) text +="<b>Country: </b>"+ country + " <br/>" + if (postalCode) text +="<b>PostalCode: </b>"+ postalCode + " <br/>" + return text + } + + function calculateScale() + { + var coord1, coord2, dist, text, f + f = 0 + coord1 = map.toCoordinate(Qt.point(0,scale.y)) + coord2 = map.toCoordinate(Qt.point(0+scaleImage.sourceSize.width,scale.y)) + dist = Math.round(coord1.distanceTo(coord2)) + + if (dist === 0) { + // not visible + } else { + for (var i = 0; i < scaleLengths.length-1; i++) { + if (dist < (scaleLengths[i] + scaleLengths[i+1]) / 2 ) { + f = scaleLengths[i] / dist + dist = scaleLengths[i] + break; + } + } + if (f === 0) { + f = dist / scaleLengths[i] + dist = scaleLengths[i] + } + } + + text = Helper.formatDistance(dist) + scaleImage.width = (scaleImage.sourceSize.width * f) - 2 * scaleImageLeft.sourceSize.width + scaleText.text = text + } + + function deleteMarkers() + { + var count = map.markers.length + for (var i = 0; i<count; i++){ + map.removeMapItem(map.markers[i]) + map.markers[i].destroy() + } + map.markers = [] + markerCounter = 0 + } + + function deleteMapItems() + { + var count = map.mapItems.length + for (var i = 0; i<count; i++){ + map.removeMapItem(map.mapItems[i]) + map.mapItems[i].destroy() + } + map.mapItems = [] + } + + function addMarker() + { + var count = map.markers.length + markerCounter++ + var marker = Qt.createQmlObject ('Marker {}', map) + map.addMapItem(marker) + marker.z = map.z+1 + marker.coordinate = mouseArea.lastCoordinate + + //update list of markers + var myArray = new Array() + for (var i = 0; i<count; i++){ + myArray.push(markers[i]) + } + myArray.push(marker) + markers = myArray + } + + function addGeoItem(item) + { + var count = map.mapItems.length + var co = Qt.createComponent(item+'.qml') + if (co.status == Component.Ready) { + var o = co.createObject(map) + o.setGeometry(map.markers, currentMarker) + map.addMapItem(o) + //update list of items + var myArray = new Array() + for (var i = 0; i<count; i++){ + myArray.push(mapItems[i]) + } + myArray.push(o) + mapItems = myArray + + } else { + console.log(item + " is not supported right now, please call us later.") + } + } + + function deleteMarker(index) + { + //update list of markers + var myArray = new Array() + var count = map.markers.length + for (var i = 0; i<count; i++){ + if (index != i) myArray.push(map.markers[i]) + } + + map.removeMapItem(map.markers[index]) + map.markers[index].destroy() + map.markers = myArray + if (markers.length == 0) markerCounter = 0 + } + + function calculateRoute(){ + routeQuery.clearWaypoints(); + for (var i = currentMarker; i< map.markers.length; i++){ + routeQuery.addWaypoint(markers[i].coordinate) + } + routeQuery.travelModes = RouteQuery.CarTravel + routeQuery.routeOptimizations = RouteQuery.ShortestRoute + routeQuery.setFeatureWeight(0, 0) + routeModel.update(); + } + + //! [coord] + center { + latitude: 59.9485 + longitude: 10.7686 + } + //! [coord] + + // Enable pinch gestures to zoom in and out + gesture.flickDeceleration: 3000 + gesture.enabled: true + onCopyrightLinkActivated: Qt.openUrlExternally(link) + + onCenterChanged:{ + scaleTimer.restart() + if (map.followme) + if (map.center != positionSource.position.coordinate) map.followme = false + } + + onZoomLevelChanged:{ + scaleTimer.restart() + if (map.followme) map.center = positionSource.position.coordinate + } + + onWidthChanged:{ + scaleTimer.restart() + } + + onHeightChanged:{ + scaleTimer.restart() + } + + Component.onCompleted: { + markers = new Array(); + mapItems = new Array(); + } + + Keys.onPressed: { + if ((event.key == Qt.Key_Plus) || (event.key == Qt.Key_VolumeUp)) { + map.zoomLevel += 1 + } else if ((event.key == Qt.Key_Minus) || (event.key == Qt.Key_VolumeDown)){ + map.zoomLevel -= 1 + } + } + + /* @todo + Binding { + target: map + property: 'center' + value: positionSource.position.coordinate + when: followme + }*/ + + PositionSource{ + id: positionSource + active: followme + + onPositionChanged: { + map.center = positionSource.position.coordinate + } + } + + MapQuickItem { + id: poiTheQtComapny + sourceItem: Rectangle { width: 14; height: 14; color: "#1c94fc"; border.width: 2; border.color: "#242424"; smooth: true; radius: 7 } + coordinate { + latitude: 59.9485 + longitude: 10.7686 + } + opacity:0.7 + anchorPoint.x: sourceItem.width/2 + anchorPoint.y: sourceItem.height/2 + } + + MapQuickItem { + sourceItem: Text{ + text: "The Qt Company" + color:"#242424" + font.bold: true + styleColor: "#ECECEC" + style: Text.Outline + } + coordinate: poiTheQtComapny.coordinate + anchorPoint.x: -poiTheQtComapny.sourceItem.width * 0.5 + anchorPoint.y: poiTheQtComapny.sourceItem.height * 1.5 + } + + + Slider { + id: zoomSlider; + z: map.z + 3 + minimumValue: map.minimumZoomLevel; + maximumValue: map.maximumZoomLevel; + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: parent.right + anchors.bottomMargin: 15 + anchors.rightMargin: 10 + anchors.leftMargin: 90 + value: map.zoomLevel + onValueChanged: { + map.zoomLevel = value + map.state="" + } + } + + Component { + id: routeDelegate + + MapRoute { + id: route + route: routeData + line.color: routeMouseArea.containsMouse ? "lime" : "red" + line.width: 5 + smooth: true + opacity: 0.8 + //! [routedelegate0] + MouseArea { + id: routeMouseArea + anchors.fill: parent + hoverEnabled: false + property variant lastCoordinate + + onPressed : { + map.lastX = mouse.x + parent.x + map.lastY = mouse.y + parent.y + map.pressX = mouse.x + parent.x + map.pressY = mouse.y + parent.y + lastCoordinate = map.toCoordinate(Qt.point(mouse.x, mouse.y)) + } + + onPositionChanged: { + if (Math.abs(map.pressX - parent.x- mouse.x ) > map.jitterThreshold || + Math.abs(map.pressY - parent.y -mouse.y ) > map.jitterThreshold) { + map.state = "" + } + if ((mouse.button == Qt.LeftButton) & (map.state == "")) { + map.lastX = mouse.x + parent.x + map.lastY = mouse.y + parent.y + } + } + + onPressAndHold:{ + if (Math.abs(map.pressX - parent.x- mouse.x ) < map.jitterThreshold + && Math.abs(map.pressY - parent.y - mouse.y ) < map.jitterThreshold) { + showRouteMenu(lastCoordinate); + } + } + } + } + //! [routedelegate1] + } + //! [routedelegate1] + + //! [pointdel0] + Component { + id: pointDelegate + + MapCircle { + id: point + radius: 1000 + color: circleMouseArea.containsMouse ? "lime" : "red" + opacity: 0.6 + center: locationData.coordinate + //! [pointdel0] + MouseArea { + anchors.fill:parent + id: circleMouseArea + hoverEnabled: false + property variant lastCoordinate + + onPressed : { + map.lastX = mouse.x + parent.x + map.lastY = mouse.y + parent.y + map.pressX = mouse.x + parent.x + map.pressY = mouse.y + parent.y + lastCoordinate = map.toCoordinate(Qt.point(mouse.x, mouse.y)) + } + + onPositionChanged: { + if (Math.abs(map.pressX - parent.x- mouse.x ) > map.jitterThreshold || + Math.abs(map.pressY - parent.y -mouse.y ) > map.jitterThreshold) { + map.state = "" + if (pressed) parent.radius = parent.center.distanceTo( + map.toCoordinate(Qt.point(mouse.x, mouse.y))) + } + if ((mouse.button == Qt.LeftButton) & (map.state == "")) { + map.lastX = mouse.x + parent.x + map.lastY = mouse.y + parent.y + } + } + + onPressAndHold:{ + if (Math.abs(map.pressX - parent.x- mouse.x ) < map.jitterThreshold + && Math.abs(map.pressY - parent.y - mouse.y ) < map.jitterThreshold) { + showPointMenu(lastCoordinate); + } + } + } + //! [pointdel1] + } + } + //! [pointdel1] + + //! [routeview] + MapItemView { + model: routeModel + delegate: routeDelegate + autoFitViewport: true + } + //! [routeview] + + //! [geocodeview] + MapItemView { + model: geocodeModel + delegate: pointDelegate + } + //! [geocodeview] + + Item {//scale + id: scale + parent: zoomSlider.parent + visible: scaleText.text != "0 m" + z: map.z + 2 + opacity: 0.6 + anchors { + bottom: zoomSlider.top; + bottomMargin: 8; + left: zoomSlider.left + } + Image { + id: scaleImageLeft + source: "../resources/scale_end.png" + anchors.bottom: parent.bottom + anchors.left: parent.left + } + Image { + id: scaleImage + source: "../resources/scale.png" + anchors.bottom: parent.bottom + anchors.left: scaleImageLeft.right + } + Image { + id: scaleImageRight + source: "../resources/scale_end.png" + anchors.bottom: parent.bottom + anchors.left: scaleImage.right + } + Text { + id: scaleText + color: "#004EAE" + horizontalAlignment: Text.AlignHCenter + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.bottomMargin: 3 + text: "0 m" + font.pixelSize: 14 + } + Component.onCompleted: { + map.calculateScale(); + } + } + + Timer { + id: scaleTimer + interval: 100 + running: false + repeat: false + onTriggered: { + map.calculateScale() + } + } + + MouseArea { + id: mouseArea + property variant lastCoordinate + anchors.fill: parent + + onPressed : { + map.lastX = mouse.x + map.lastY = mouse.y + map.pressX = mouse.x + map.pressY = mouse.y + lastCoordinate = map.toCoordinate(Qt.point(mouse.x, mouse.y)) + // if (mouse.button == Qt.MiddleButton) + // addMarker() + } + + onPositionChanged: { + if (map.state != "PopupMenu" || + Math.abs(map.pressX - mouse.x ) > map.jitterThreshold || + Math.abs(map.pressY - mouse.y ) > map.jitterThreshold) { + map.state = "" + } + if ((mouse.button == Qt.LeftButton) & (map.state == "")) { + // if ((map.lastX != -1) && (map.lastY != -1)) { + // var dx = mouse.x - map.lastX + // var dy = mouse.y - map.lastY + // map.pan(-dx, -dy) + // } + map.lastX = mouse.x + map.lastY = mouse.y + } + } + + onDoubleClicked: { + map.center = map.toCoordinate(Qt.point(mouse.x, mouse.y)) + if (mouse.button == Qt.LeftButton){ + map.zoomLevel += 1 + } else if (mouse.button == Qt.RightButton) map.zoomLevel -= 1 + lastX = -1 + lastY = -1 + } + + onPressAndHold:{ + if (Math.abs(map.pressX - mouse.x ) < map.jitterThreshold + && Math.abs(map.pressY - mouse.y ) < map.jitterThreshold) { + showMainMenu(lastCoordinate); + } + } + } + //! [end] +} +//! [end] diff --git a/examples/location/mapviewer/map/Marker.qml b/examples/location/mapviewer/map/Marker.qml new file mode 100644 index 00000000..192fdd80 --- /dev/null +++ b/examples/location/mapviewer/map/Marker.qml @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0; +import QtLocation 5.3 + +//! [mqi-top] +MapQuickItem { + id: marker +//! [mqi-top] + property alias lastMouseX: markerMouseArea.lastX + property alias lastMouseY: markerMouseArea.lastY + +//! [mqi-anchor] + anchorPoint.x: image.width/4 + anchorPoint.y: image.height + + sourceItem: Image { + id: image +//! [mqi-anchor] + source: markerMouseArea.containsMouse ? (markerMouseArea.pressed ? "../resources/marker_selected.png" :"../resources/marker_hovered.png") : "../resources/marker.png" + MouseArea { + id: markerMouseArea + property int pressX : -1 + property int pressY : -1 + property int jitterThreshold : 10 + property int lastX: -1 + property int lastY: -1 + anchors.fill: parent + hoverEnabled : false + drag.target: marker + preventStealing: true + + onPressed : { + map.pressX = mouse.x + map.pressY = mouse.y + map.currentMarker = -1 + for (var i = 0; i< map.markers.length; i++){ + if (marker == map.markers[i]){ + map.currentMarker = i + break + } + } + map.state = "" + } + + onPressAndHold:{ + if (Math.abs(map.pressX - mouse.x ) < map.jitterThreshold + && Math.abs(map.pressY - mouse.y ) < map.jitterThreshold) { + var p = map.fromCoordinate(marker.coordinate) + lastX = p.x + lastY = p.y + map.showMarkerMenu(marker.coordinate) + } + } + } + + Text{ + id: number + y: image.height/4 + color: "white" + font.bold: true + font.pixelSize: 14 + width:27 + horizontalAlignment: Text.AlignHCenter + Component.onCompleted: { + text = map.markerCounter + } + } + +//! [mqi-closeimage] + } +//! [mqi-closeimage] + + Component.onCompleted: coordinate = map.toCoordinate(Qt.point(markerMouseArea.mouseX, + markerMouseArea.mouseY)); +//! [mqi-close] +} +//! [mqi-close] diff --git a/examples/location/mapviewer/map/MiniMap.qml b/examples/location/mapviewer/map/MiniMap.qml new file mode 100644 index 00000000..fbd000ef --- /dev/null +++ b/examples/location/mapviewer/map/MiniMap.qml @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtLocation 5.3 + +Rectangle{ + id: miniMapRect + width: 152 + height: 152 + anchors.right: (parent) ? parent.right : undefined + anchors.rightMargin: 10 + anchors.top: (parent) ? parent.top : undefined + anchors.topMargin: 10 + color: "#242424" + Map { + id: miniMap + anchors.top: parent.top + anchors.topMargin: 1 + anchors.left: parent.left + anchors.leftMargin: 1 + width: 150 + height: 150 + zoomLevel: (map.zoomLevel > minimumZoomLevel + 3) ? minimumZoomLevel + 3 : 2.5 + center: map.center + plugin: map.plugin + gesture.enabled: false + + MapRectangle { + color: "#44ff0000" + border.width: 1 + border.color: "red" + topLeft { + latitude: miniMap.center.latitude + 5 + longitude: miniMap.center.longitude - 5 + } + bottomRight { + latitude: miniMap.center.latitude - 5 + longitude: miniMap.center.longitude + 5 + } + } + } +} diff --git a/examples/location/mapviewer/map/PolygonItem.qml b/examples/location/mapviewer/map/PolygonItem.qml new file mode 100644 index 00000000..0d72f9d7 --- /dev/null +++ b/examples/location/mapviewer/map/PolygonItem.qml @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.0 +import QtLocation 5.3 + +//TODO: remove me when items are integrated + +MapPolygon { + + color: "green" + border.color: "darkgreen" + border.width: 4 + smooth: true + opacity: 0.5 + + function setGeometry(markers, index){ + for (var i = index; i<markers.length; i++){ + addCoordinate(markers[i].coordinate) + } + } + MouseArea { + anchors.fill:parent + id: mousearea + drag.target: parent + } +} diff --git a/examples/location/mapviewer/map/PolylineItem.qml b/examples/location/mapviewer/map/PolylineItem.qml new file mode 100644 index 00000000..efb05d39 --- /dev/null +++ b/examples/location/mapviewer/map/PolylineItem.qml @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.0 +import QtLocation 5.3 + +//TODO: remove/refactor me when items are integrated + +MapPolyline { + line.color: "blue" + line.width: 4 + opacity: 0.7 + smooth: true + + function setGeometry(markers, index){ + for (var i = index; i<markers.length; i++){ + addCoordinate(markers[i].coordinate) + } + } +} diff --git a/examples/location/mapviewer/map/RectangleItem.qml b/examples/location/mapviewer/map/RectangleItem.qml new file mode 100644 index 00000000..21a60e98 --- /dev/null +++ b/examples/location/mapviewer/map/RectangleItem.qml @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.0 +import QtLocation 5.3 + +MapRectangle { + id: mapRectangle + + color: mousearea.containsMouse ? "lime" : "red" + opacity: 0.5 + border.width: 2.0 + + function setGeometry(markers, index){ + topLeft.latitude = Math.max(markers[index].coordinate.latitude, markers[index + 1].coordinate.latitude) + topLeft.longitude = Math.min(markers[index].coordinate.longitude, markers[index + 1].coordinate.longitude) + bottomRight.latitude = Math.min(markers[index].coordinate.latitude, markers[index + 1].coordinate.latitude) + bottomRight.longitude = Math.max(markers[index].coordinate.longitude, markers[index + 1].coordinate.longitude) + } + + Binding { + target: mapRectangle + property: 'border.width' + value: 60 + + when: ((topLeft.latitude == -27.1144) && + (topLeft.longitude == 152.6594) && + (bottomRight.latitude == -27.7434) && + (bottomRight.longitude == 153.3021)) + } + + MouseArea { + anchors.fill:parent + id: mousearea + hoverEnabled: false + drag.target: parent + } +} |