diff options
author | Michal Klocek <michal.klocek@theqtcompany.com> | 2015-02-20 17:23:18 +0100 |
---|---|---|
committer | Michal Klocek <michal.klocek@theqtcompany.com> | 2015-04-13 14:54:56 +0000 |
commit | ee1deee9a2293a82829efc724ad448aa9a210ae1 (patch) | |
tree | bff50cd2732bb7d786cdd0a082137317553b191c /examples/location/mapviewer | |
parent | b384ac3b83ead4593b03594a5ef3d4d82fae8959 (diff) | |
download | qtlocation-ee1deee9a2293a82829efc724ad448aa9a210ae1.tar.gz |
Reformat mapviewer example code.
Make code to follow qml coding conventions.
Use switch instead of if-else statement.
Add helper.js with common functions.
Change-Id: Iba989d3677fa428b45609f24a82b26ef7cefe675
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'examples/location/mapviewer')
-rw-r--r-- | examples/location/mapviewer/Geocode.qml | 1 | ||||
-rw-r--r-- | examples/location/mapviewer/Locale.qml | 1 | ||||
-rw-r--r-- | examples/location/mapviewer/MainMenu.qml | 18 | ||||
-rw-r--r-- | examples/location/mapviewer/MapPopupMenu.qml | 1 | ||||
-rw-r--r-- | examples/location/mapviewer/ReverseGeocode.qml | 1 | ||||
-rw-r--r-- | examples/location/mapviewer/RouteAddress.qml | 75 | ||||
-rw-r--r-- | examples/location/mapviewer/RouteList.qml | 42 | ||||
-rw-r--r-- | examples/location/mapviewer/RouteListDelegate.qml | 6 | ||||
-rw-r--r-- | examples/location/mapviewer/RouteListHeader.qml | 6 | ||||
-rw-r--r-- | examples/location/mapviewer/content/map/MapComponent.qml | 551 | ||||
-rw-r--r-- | examples/location/mapviewer/helper.js | 79 | ||||
-rw-r--r-- | examples/location/mapviewer/mapviewer.qml | 525 | ||||
-rw-r--r-- | examples/location/mapviewer/mapviewerwrapper.qrc | 1 |
13 files changed, 672 insertions, 635 deletions
diff --git a/examples/location/mapviewer/Geocode.qml b/examples/location/mapviewer/Geocode.qml index 5aeb6fcd..55e94fc0 100644 --- a/examples/location/mapviewer/Geocode.qml +++ b/examples/location/mapviewer/Geocode.qml @@ -46,7 +46,6 @@ import "forms" //! [geocode0] GeocodeForm { //! [geocode0] - property variant address signal showPlace(variant address) signal closeForm() diff --git a/examples/location/mapviewer/Locale.qml b/examples/location/mapviewer/Locale.qml index 55da3a24..14fa1b9d 100644 --- a/examples/location/mapviewer/Locale.qml +++ b/examples/location/mapviewer/Locale.qml @@ -43,7 +43,6 @@ import QtPositioning 5.2 import "forms" LocaleForm { - property string locale signal selectLanguage(string language) signal closeForm() diff --git a/examples/location/mapviewer/MainMenu.qml b/examples/location/mapviewer/MainMenu.qml index b8af3b6b..31c4a53b 100644 --- a/examples/location/mapviewer/MainMenu.qml +++ b/examples/location/mapviewer/MainMenu.qml @@ -43,7 +43,6 @@ import QtQuick.Controls 1.3 import QtLocation 5.3 MenuBar { - property variant providerMenu: providerMenu property variant mapTypeMenu: mapTypeMenu property variant toolsMenu: toolsMenu @@ -59,14 +58,16 @@ MenuBar { id: providerMenu title: qsTr("Provider") - function createMenu(plugins){ + function createMenu(plugins) + { clear() for (var i = 0; i < plugins.length; i++) { createProviderMenuItem(plugins[i]); } } - function createProviderMenuItem(provider){ + function createProviderMenuItem(provider) + { var item = addItem(provider); item.checkable = true; item.triggered.connect(function(){selectProvider(provider)}) @@ -77,7 +78,8 @@ MenuBar { id: mapTypeMenu title: qsTr("MapType") - function createMenu(map){ + function createMenu(map) + { clear() for (var i = 0; i<map.supportedMapTypes.length; i++) { createMapTypeMenuItem(map.supportedMapTypes[i]).checked = @@ -85,7 +87,8 @@ MenuBar { } } - function createMapTypeMenuItem(mapType){ + function createMapTypeMenuItem(mapType) + { var item = addItem(mapType.name); item.checkable = true; item.triggered.connect(function(){selectMapType(mapType)}) @@ -95,11 +98,12 @@ MenuBar { Menu { id: toolsMenu - title: qsTr("Tools") property bool isFollowMe: false; property bool isMiniMap: false; + title: qsTr("Tools") - function createMenu(map){ + function createMenu(map) + { clear() if (map.plugin.supportsGeocoding(Plugin.ReverseGeocodingFeature)) { addItem(qsTr("Reverse geocode")).triggered.connect(function(){selectTool("RevGeocode")}) diff --git a/examples/location/mapviewer/MapPopupMenu.qml b/examples/location/mapviewer/MapPopupMenu.qml index daa388ce..4bb9e0a2 100644 --- a/examples/location/mapviewer/MapPopupMenu.qml +++ b/examples/location/mapviewer/MapPopupMenu.qml @@ -47,7 +47,6 @@ Menu { property int mapItemsCount signal itemClicked(string item) - function update() { clear() addItem(qsTr("Add Marker")).triggered.connect(function(){itemClicked("addMarker")}) diff --git a/examples/location/mapviewer/ReverseGeocode.qml b/examples/location/mapviewer/ReverseGeocode.qml index 51269d12..f5ac9a9e 100644 --- a/examples/location/mapviewer/ReverseGeocode.qml +++ b/examples/location/mapviewer/ReverseGeocode.qml @@ -44,7 +44,6 @@ import "forms" //Reverse Geocode Dialog ReverseGeocodeForm { - property string title; property variant coordinate signal showPlace(variant coordinate) diff --git a/examples/location/mapviewer/RouteAddress.qml b/examples/location/mapviewer/RouteAddress.qml index 58480633..a040abc3 100644 --- a/examples/location/mapviewer/RouteAddress.qml +++ b/examples/location/mapviewer/RouteAddress.qml @@ -44,7 +44,6 @@ import QtPositioning 5.3 import "forms" RouteAddressForm { - property alias plugin : tempGeocodeModel.plugin; property variant fromAddress; property variant toAddress; @@ -52,6 +51,43 @@ RouteAddressForm { signal showRoute(variant startCoordinate,variant endCoordinate) signal closeForm() + goButton.onClicked: { + tempGeocodeModel.reset() + fromAddress.country = fromCountry.text + fromAddress.street = fromStreet.text + fromAddress.city = fromCity.text + toAddress.country = toCountry.text + toAddress.street = toStreet.text + toAddress.city = toCity.text + tempGeocodeModel.startCoordinate = QtPositioning.coordinate() + tempGeocodeModel.endCoordinate = QtPositioning.coordinate() + tempGeocodeModel.query = fromAddress + tempGeocodeModel.update(); + goButton.enabled = false; + } + + clearButton.onClicked: { + fromStreet.text = "" + fromCity.text = "" + fromCountry.text = "" + toStreet.text = "" + toCity.text = "" + toCountry.text = "" + } + + cancelButton.onClicked: { + closeForm() + } + + Component.onCompleted: { + fromStreet.text = fromAddress.street + fromCity.text = fromAddress.city + fromCountry.text = fromAddress.country + toStreet.text = toAddress.street + toCity.text = toAddress.city + toCountry.text = toAddress.country + } + GeocodeModel { id: tempGeocodeModel @@ -104,41 +140,4 @@ RouteAddressForm { } } } - - goButton.onClicked: { - tempGeocodeModel.reset() - fromAddress.country = fromCountry.text - fromAddress.street = fromStreet.text - fromAddress.city = fromCity.text - toAddress.country = toCountry.text - toAddress.street = toStreet.text - toAddress.city = toCity.text - tempGeocodeModel.startCoordinate = QtPositioning.coordinate() - tempGeocodeModel.endCoordinate = QtPositioning.coordinate() - tempGeocodeModel.query = fromAddress - tempGeocodeModel.update(); - goButton.enabled = false; - } - - clearButton.onClicked: { - fromStreet.text = "" - fromCity.text = "" - fromCountry.text = "" - toStreet.text = "" - toCity.text = "" - toCountry.text = "" - } - - cancelButton.onClicked: { - closeForm() - } - - Component.onCompleted: { - fromStreet.text = fromAddress.street - fromCity.text = fromAddress.city - fromCountry.text = fromAddress.country - toStreet.text = toAddress.street - toCity.text = toAddress.city - toCountry.text = toAddress.country - } } diff --git a/examples/location/mapviewer/RouteList.qml b/examples/location/mapviewer/RouteList.qml index ff32d747..d9a26b6c 100644 --- a/examples/location/mapviewer/RouteList.qml +++ b/examples/location/mapviewer/RouteList.qml @@ -40,15 +40,14 @@ import QtQuick 2.4 import QtQuick.Controls 1.3 +import "helper.js" as Helper ListView { property variant routeModel property string totalTravelTime property string totalDistance - signal closeForm() - id: listView interactive: true model: ListModel { id: routeList } @@ -75,44 +74,11 @@ ListView { for (var i = 0; i < routeModel.get(0).segments.length; i++) { routeList.append({ "instruction": routeModel.get(0).segments[i].maneuver.instructionText, - "distance": formatDistance(routeModel.get(0).segments[i].maneuver.distanceToNextInstruction) + "distance": Helper.formatDistance(routeModel.get(0).segments[i].maneuver.distanceToNextInstruction) }); } } - totalTravelTime = routeModel.count == 0 ? "" : formatTime(routeModel.get(0).travelTime) - totalDistance = routeModel.count == 0 ? "" : formatDistance(routeModel.get(0).distance) - } - - function formatTime(sec){ - var value = sec - var seconds = value % 60 - value /= 60 - value = (value > 1) ? Math.round(value) : 0 - var minutes = value % 60 - value /= 60 - value = (value > 1) ? Math.round(value) : 0 - var hours = value - if (hours > 0) value = hours + "h:"+ minutes + "m" - else value = minutes + "min" - return value - } - - function formatDistance(meters) - { - var dist = Math.round(meters) - if (dist > 1000 ){ - if (dist > 100000){ - dist = Math.round(dist / 1000) - } - else{ - dist = Math.round(dist / 100) - dist = dist / 10 - } - dist = dist + " km" - } - else{ - dist = dist + " m" - } - return dist + totalTravelTime = routeModel.count == 0 ? "" : Helper.formatTime(routeModel.get(0).travelTime) + totalDistance = routeModel.count == 0 ? "" : Helper.formatDistance(routeModel.get(0).distance) } } diff --git a/examples/location/mapviewer/RouteListDelegate.qml b/examples/location/mapviewer/RouteListDelegate.qml index 5b68269a..16dca34a 100644 --- a/examples/location/mapviewer/RouteListDelegate.qml +++ b/examples/location/mapviewer/RouteListDelegate.qml @@ -44,14 +44,14 @@ import QtQuick.Layouts 1.1 Item { id: root - width: parent.width - height: indexLabel.height * 2 - property bool checked: false property alias routeInstruction: instructionLabel property alias routeDistance: distanceLabel property alias routeIndex: indexLabel + width: parent.width + height: indexLabel.height * 2 + RowLayout { spacing: 10 anchors.left: parent.left diff --git a/examples/location/mapviewer/RouteListHeader.qml b/examples/location/mapviewer/RouteListHeader.qml index 96e065e0..a907214f 100644 --- a/examples/location/mapviewer/RouteListHeader.qml +++ b/examples/location/mapviewer/RouteListHeader.qml @@ -42,11 +42,10 @@ import QtQuick 2.4 import QtQuick.Controls 1.3 Item { - - width: parent.width - height: tabTitle.height * 3.0 property alias travelTime: travelTimeLabel property alias distance: distanceLabel + width: parent.width + height: tabTitle.height * 3.0 Rectangle { id: tabRectangle @@ -81,6 +80,5 @@ Item { anchors.right: parent.right anchors.verticalCenter: parent.verticalCenter } - } } diff --git a/examples/location/mapviewer/content/map/MapComponent.qml b/examples/location/mapviewer/content/map/MapComponent.qml index afe95c0f..eea6b86f 100644 --- a/examples/location/mapviewer/content/map/MapComponent.qml +++ b/examples/location/mapviewer/content/map/MapComponent.qml @@ -41,11 +41,228 @@ 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 - zoomLevel: (maximumZoomLevel - minimumZoomLevel)/2 + //! [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 { @@ -57,26 +274,39 @@ Map { // Enable pinch gestures to zoom in and out gesture.flickDeceleration: 3000 gesture.enabled: true + onCopyrightLinkActivated: Qt.openUrlExternally(link) -//! [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 - signal showMainMenu(variant coordinate) - signal showMarkerMenu(variant coordinate) - signal showRouteMenu(variant coordinate) - signal showPointMenu(variant coordinate) - signal showRouteList() + onCenterChanged:{ + scaleTimer.restart() + if (map.followme) + if (map.center != positionSource.position.coordinate) map.followme = false + } - 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] - signal requestLocale() + 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 { @@ -86,8 +316,6 @@ Map { when: followme }*/ - onCopyrightLinkActivated: Qt.openUrlExternally(link) - PositionSource{ id: positionSource active: followme @@ -101,8 +329,8 @@ Map { 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 + latitude: 59.9485 + longitude: 10.7686 } opacity:0.7 anchorPoint.x: sourceItem.width/2 @@ -141,72 +369,6 @@ Map { } } -//! [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) - - Component.onCompleted: { - markers = new Array(); - mapItems = new Array(); - } - -//! [routedelegate0] Component { id: routeDelegate @@ -217,7 +379,7 @@ Map { line.width: 5 smooth: true opacity: 0.8 -//! [routedelegate0] + //! [routedelegate0] MouseArea { id: routeMouseArea anchors.fill: parent @@ -234,7 +396,7 @@ Map { onPositionChanged: { if (Math.abs(map.pressX - parent.x- mouse.x ) > map.jitterThreshold || - Math.abs(map.pressY - parent.y -mouse.y ) > map.jitterThreshold) { + Math.abs(map.pressY - parent.y -mouse.y ) > map.jitterThreshold) { map.state = "" } if ((mouse.button == Qt.LeftButton) & (map.state == "")) { @@ -246,16 +408,16 @@ Map { onPressAndHold:{ if (Math.abs(map.pressX - parent.x- mouse.x ) < map.jitterThreshold && Math.abs(map.pressY - parent.y - mouse.y ) < map.jitterThreshold) { - showRouteMenu(lastCoordinate); + showRouteMenu(lastCoordinate); } } } } -//! [routedelegate1] + //! [routedelegate1] } -//! [routedelegate1] + //! [routedelegate1] -//! [pointdel0] + //! [pointdel0] Component { id: pointDelegate @@ -265,7 +427,7 @@ Map { color: circleMouseArea.containsMouse ? "lime" : "red" opacity: 0.6 center: locationData.coordinate -//! [pointdel0] + //! [pointdel0] MouseArea { anchors.fill:parent id: circleMouseArea @@ -282,7 +444,7 @@ Map { onPositionChanged: { if (Math.abs(map.pressX - parent.x- mouse.x ) > map.jitterThreshold || - Math.abs(map.pressY - parent.y -mouse.y ) > 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))) @@ -300,25 +462,25 @@ Map { } } } -//! [pointdel1] + //! [pointdel1] } } -//! [pointdel1] + //! [pointdel1] -//! [routeview] + //! [routeview] MapItemView { model: routeModel delegate: routeDelegate autoFitViewport: true } -//! [routeview] + //! [routeview] -//! [geocodeview] + //! [geocodeview] MapItemView { model: geocodeModel delegate: pointDelegate } -//! [geocodeview] + //! [geocodeview] Item {//scale id: scale @@ -374,25 +536,6 @@ Map { } } - 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() - } - MouseArea { id: mouseArea property variant lastCoordinate @@ -410,8 +553,8 @@ Map { onPositionChanged: { if (map.state != "PopupMenu" || - Math.abs(map.pressX - mouse.x ) > map.jitterThreshold || - Math.abs(map.pressY - mouse.y ) > map.jitterThreshold) { + 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 == "")) { @@ -439,166 +582,8 @@ Map { && Math.abs(map.pressY - mouse.y ) < map.jitterThreshold) { showMainMenu(lastCoordinate); } - } - } - - - 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 - } - } - - 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 = 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(); - } - - function roundNumber(number, digits) { - var multiple = Math.pow(10, digits); - return Math.round(number * multiple) / multiple; - } - - function formatTime(sec){ - var value = sec - var seconds = value % 60 - value /= 60 - value = (value > 1) ? Math.round(value) : 0 - var minutes = value % 60 - value /= 60 - value = (value > 1) ? Math.round(value) : 0 - var hours = value - if (hours > 0) value = hours + "h:"+ minutes + "m" - else value = minutes + "min" - return value - } - - function formatDistance(meters) - { - var dist = Math.round(meters) - if (dist > 1000 ){ - if (dist > 100000){ - dist = Math.round(dist / 1000) - } - else{ - dist = Math.round(dist / 100) - dist = dist / 10 - } - dist = dist + " km" - } - else{ - dist = dist + " m" - } - return dist - } - -//! [end] + //! [end] } //! [end] diff --git a/examples/location/mapviewer/helper.js b/examples/location/mapviewer/helper.js new file mode 100644 index 00000000..4ef445a6 --- /dev/null +++ b/examples/location/mapviewer/helper.js @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +function roundNumber(number, digits) +{ + var multiple = Math.pow(10, digits); + return Math.round(number * multiple) / multiple; +} + +function formatTime(sec) +{ + var value = sec + var seconds = value % 60 + value /= 60 + value = (value > 1) ? Math.round(value) : 0 + var minutes = value % 60 + value /= 60 + value = (value > 1) ? Math.round(value) : 0 + var hours = value + if (hours > 0) value = hours + "h:"+ minutes + "m" + else value = minutes + "min" + return value +} + +function formatDistance(meters) +{ + var dist = Math.round(meters) + if (dist > 1000 ){ + if (dist > 100000){ + dist = Math.round(dist / 1000) + } + else{ + dist = Math.round(dist / 100) + dist = dist / 10 + } + dist = dist + " km" + } + else{ + dist = dist + " m" + } + return dist +} diff --git a/examples/location/mapviewer/mapviewer.qml b/examples/location/mapviewer/mapviewer.qml index d5ad89e1..338c717a 100644 --- a/examples/location/mapviewer/mapviewer.qml +++ b/examples/location/mapviewer/mapviewer.qml @@ -43,14 +43,10 @@ import QtQuick.Controls 1.3 import QtLocation 5.3 import QtPositioning 5.2 import "content/map" +import "helper.js" as Helper ApplicationWindow { id: appWindow - title: qsTr("Mapviewer") - height: 640 - width: 360 - visible: true - property variant map property variant minimap property variant parameters @@ -59,203 +55,8 @@ ApplicationWindow { property variant fromCoordinate: QtPositioning.coordinate(59.9483, 10.7695) property variant toCoordinate: QtPositioning.coordinate(59.9645, 10.671) - Address { - id :fromAddress - street: "Sandakerveien 116" - city: "Oslo" - country: "Norway" - state : "" - postalCode: "0484" - } - - Address { - id: toAddress - street: "Holmenkollveien 140" - city: "Oslo" - country: "Norway" - postalCode: "0791" - } - - menuBar: MainMenu { - id: mainMenu - - onSelectProvider: { - stackView.pop() - for (var i = 0; i < providerMenu.items.length; i++) { - providerMenu.items[i].checked = providerMenu.items[i].text === providerName - } - - if (minimap) { - minimap.destroy() - minimap = null - } - - createMap(providerName) - if (map.error === Map.NoError) { - selectMapType(map.activeMapType) - toolsMenu.createMenu(map); - } else { - mapTypeMenu.clear(); - toolsMenu.clear(); - } - } - - onSelectMapType: { - stackView.pop(page) - for (var i = 0; i < mapTypeMenu.items.length; i++) { - mapTypeMenu.items[i].checked = mapTypeMenu.items[i].text === mapType.name - } - map.activeMapType = mapType - } - - - onSelectTool: { - if (tool === "AddressRoute") { - stackView.push({ item: Qt.resolvedUrl("RouteAddress.qml") , - properties: { "plugin": map.plugin, - "toAddress": toAddress, - "fromAddress": fromAddress}}) - stackView.currentItem.showRoute.connect(showRoute) - stackView.currentItem.showMessage.connect(showMessage) - stackView.currentItem.closeForm.connect(closeForm) - } else if (tool === "CoordinateRoute") { - stackView.push({ item: Qt.resolvedUrl("RouteCoordinate.qml") , - properties: { "toCoordinate": toCoordinate, - "fromCoordinate": fromCoordinate}}) - stackView.currentItem.showRoute.connect(showRoute) - stackView.currentItem.closeForm.connect(closeForm) - } else if (tool === "Geocode") { - stackView.push({ item: Qt.resolvedUrl("Geocode.qml") , - properties: { "address": fromAddress}}) - stackView.currentItem.showPlace.connect(showPlace) - stackView.currentItem.closeForm.connect(closeForm) - } else if (tool === "RevGeocode") { - stackView.push({ item: Qt.resolvedUrl("ReverseGeocode.qml") , - properties: { "coordinate": fromCoordinate}}) - stackView.currentItem.showPlace.connect(showPlace) - stackView.currentItem.closeForm.connect(closeForm) - } else if (tool === "Language") { - stackView.push({ item: Qt.resolvedUrl("Locale.qml") , - properties: { "locale": map.plugin.locales[0]}}) - stackView.currentItem.selectLanguage.connect(setLanguage) - stackView.currentItem.closeForm.connect(closeForm) - } - } - - onToggleMapState: { - stackView.pop(page) - if (state === "FollowMe") { - map.followme =! map.followme - page.state = "" - } else if (state === "MiniMap") { - toggleMiniMapState() - isMiniMap = minimap - } - } - - function toggleMiniMapState() { - if (minimap) { - minimap.destroy() - minimap = null - } else { - minimap = Qt.createQmlObject ('import "content/map"; MiniMap{ z: map.z + 2 }', map) - } - page.state = "" - } - - //! [routerequest0] - function showRoute(startCoordinate, endCoordinate) { - // clear away any old data in the query - map.routeQuery.clearWaypoints(); - - // add the start and end coords as waypoints on the route - map.routeQuery.addWaypoint(startCoordinate) - map.routeQuery.addWaypoint(endCoordinate) - map.routeQuery.travelModes = RouteQuery.CarTravel - map.routeQuery.routeOptimizations = RouteQuery.FastestRoute - //! [routerequest0] - - //! [routerequest0 feature weight] - for (var i=0; i<9; i++) { - map.routeQuery.setFeatureWeight(i, 0) - } - //for (var i=0; i<routeDialog.features.length; i++) { - // map.routeQuery.setFeatureWeight(routeDialog.features[i], RouteQuery.AvoidFeatureWeight) - //} - //! [routerequest0 feature weight] - - //! [routerequest1] - map.routeModel.update(); - // center the map on the start coord - map.center = startCoordinate; - //! [routerequest1] - } - - function showPlace(geocode) { - // send the geocode request - map.geocodeModel.query = geocode - map.geocodeModel.update() - } - - function setLanguage(lang) { - map.plugin.locales = lang; - stackView.pop(page) - } - } - - function showMessage(title,message,backPage) { - stackView.push({ item: Qt.resolvedUrl("Message.qml") , - properties: { - "title" : title, - "message" : message, - "backPage" : backPage - }}) - stackView.currentItem.closeForm.connect(closeMessage) - } - - function closeMessage(backPage) { - stackView.pop(backPage) - } - - function closeForm() { - stackView.pop(page) - } - - function showRouteListPage() { - stackView.push({ item: Qt.resolvedUrl("RouteList.qml") , - properties: { - "routeModel" : map.routeModel - }}) - stackView.currentItem.closeForm.connect(closeForm) - } - - function geocodeMessage(){ - var street, district, city, county, state, countryCode, country, postalCode, latitude, longitude, text - latitude = Math.round(map.geocodeModel.get(0).coordinate.latitude * 10000) / 10000 - longitude =Math.round(map.geocodeModel.get(0).coordinate.longitude * 10000) / 10000 - street = map.geocodeModel.get(0).address.street - district = map.geocodeModel.get(0).address.district - city = map.geocodeModel.get(0).address.city - county = map.geocodeModel.get(0).address.county - state = map.geocodeModel.get(0).address.state - countryCode = map.geocodeModel.get(0).address.countryCode - country = map.geocodeModel.get(0).address.country - postalCode = map.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 createMap(provider){ + function createMap(provider) + { var plugin if (parameters && parameters.length>0) @@ -270,34 +71,35 @@ ApplicationWindow { map = Qt.createQmlObject ('import QtLocation 5.3;\ import "content/map";\ + import "helper.js" as Helper;\ MapComponent{\ width: page.width;\ height: page.height;\ onFollowmeChanged: {mainMenu.isFollowMe = map.followme}\ onSupportedMapTypesChanged: {mainMenu.mapTypeMenu.createMenu(map)}\ onCoordinatesCaptured: {\ - var text = "<b>" + qsTr("Latitude:") + "</b> " + roundNumber(latitude,4) + "<br/><b>" + qsTr("Longitude:") + "</b> " + roundNumber(longitude,4);\ - showMessage(qsTr("Coordinates"),text);\ + var text = "<b>" + qsTr("Latitude:") + "</b> " + Helper.roundNumber(latitude,4) + "<br/><b>" + qsTr("Longitude:") + "</b> " + Helper.roundNumber(longitude,4);\ + stackView.showMessage(qsTr("Coordinates"),text);\ }\ onGeocodeFinished:{\ if (map.geocodeModel.status == GeocodeModel.Ready) {\ if (map.geocodeModel.count == 0) {\ - showMessage(qsTr("Geocode Error"),qsTr("Unsuccessful geocode"));\ + stackView.showMessage(qsTr("Geocode Error"),qsTr("Unsuccessful geocode"));\ } else if (map.geocodeModel.count > 1) { \ - showMessage(qsTr("Ambiguous geocode"), map.geocodeModel.count + " " + \ + stackView.showMessage(qsTr("Ambiguous geocode"), map.geocodeModel.count + " " + \ qsTr("results found for the given address, please specify location"));\ } else { \ - showMessage(qsTr("Location"), geocodeMessage(),page);\ + stackView.showMessage(qsTr("Location"), geocodeMessage(),page);\ ;}\ } else if (map.geocodeModel.status == GeocodeModel.Error) {\ - showMessage(qsTr("Geocode Error"),qsTr("Unsuccessful geocode")); \ + stackView.showMessage(qsTr("Geocode Error"),qsTr("Unsuccessful geocode")); \ }\ }\ onRouteError: {\ - showMessage(qsTr("Route Error"),qsTr("Unable to find a route for the given points"),page);\ + stackView.showMessage(qsTr("Route Error"),qsTr("Unable to find a route for the given points"),page);\ }\ onShowGeocodeInfo:{\ - showMessage(qsTr("Location"),geocodeMessage(),page);\ + stackView.showMessage(qsTr("Location"),geocodeMessage(),page);\ }\ onErrorChanged: {\ if (map.error != Map.NoError) {\ @@ -306,7 +108,7 @@ ApplicationWindow { if (map.error == Map.MissingRequiredParameterError) \ message += "<br/>" + qsTr("or see") + " \'mapviewer --help\' "\ + qsTr("how to pass plugin parameters.");\ - showMessage(title,message);\ + stackView.showMessage(title,message);\ }\ }\ onShowMainMenu: {\ @@ -322,14 +124,15 @@ ApplicationWindow { itemPopupMenu.show("Point",coordinate);\ }\ onShowRouteList: {\ - showRouteListPage(); + stackView.showRouteListPage(); }\ }',page) map.plugin = plugin; map.zoomLevel = (map.maximumZoomLevel - map.minimumZoomLevel)/2 } - function getPlugins(){ + function getPlugins() + { var plugin = Qt.createQmlObject ('import QtLocation 5.3; Plugin {}', appWindow) var tempPlugin var myArray = new Array() @@ -342,7 +145,8 @@ ApplicationWindow { return myArray } - function initializeProvders(pluginParameters) { + function initializeProvders(pluginParameters) + { var parameters = new Array() for (var prop in pluginParameters){ var parameter = Qt.createQmlObject('import QtLocation 5.3; PluginParameter{ name: "'+ prop + '"; value: "' + pluginParameters[prop]+'"}',appWindow) @@ -357,24 +161,176 @@ ApplicationWindow { } } - MapPopupMenu { - id: mapPopupMenu - onItemClicked: { + title: qsTr("Mapviewer") + height: 640 + width: 360 + visible: true + menuBar: mainMenu + + Address { + id :fromAddress + street: "Sandakerveien 116" + city: "Oslo" + country: "Norway" + state : "" + postalCode: "0484" + } + + Address { + id: toAddress + street: "Holmenkollveien 140" + city: "Oslo" + country: "Norway" + postalCode: "0791" + } + + MainMenu { + id: mainMenu + + function toggleMiniMapState() + { + if (minimap) { + minimap.destroy() + minimap = null + } else { + minimap = Qt.createQmlObject ('import "content/map"; MiniMap{ z: map.z + 2 }', map) + } + } + + //! [routerequest0] + function showRoute(startCoordinate, endCoordinate) + { + // clear away any old data in the query + map.routeQuery.clearWaypoints(); + + // add the start and end coords as waypoints on the route + map.routeQuery.addWaypoint(startCoordinate) + map.routeQuery.addWaypoint(endCoordinate) + map.routeQuery.travelModes = RouteQuery.CarTravel + map.routeQuery.routeOptimizations = RouteQuery.FastestRoute + //! [routerequest0] + + //! [routerequest0 feature weight] + for (var i=0; i<9; i++) { + map.routeQuery.setFeatureWeight(i, 0) + } + //for (var i=0; i<routeDialog.features.length; i++) { + // map.routeQuery.setFeatureWeight(routeDialog.features[i], RouteQuery.AvoidFeatureWeight) + //} + //! [routerequest0 feature weight] + + //! [routerequest1] + map.routeModel.update(); + // center the map on the start coord + map.center = startCoordinate; + //! [routerequest1] + } + + function showPlace(geocode) + { + // send the geocode request + map.geocodeModel.query = geocode + map.geocodeModel.update() + } + + function setLanguage(lang) + { + map.plugin.locales = lang; stackView.pop(page) - if (item === "addMarker") { - map.addMarker() - } else if (item === "getCoordinate") { - map.coordinatesCaptured(coordinate.latitude, coordinate.longitude) - } else if (item === "fitViewport") { - map.fitViewportToMapItems() - } else if (item === "deleteMarkers") { - map.deleteMarkers() - } else if (item === "deleteItems") { - map.deleteMapItems() + } + + onSelectProvider: { + stackView.pop() + for (var i = 0; i < providerMenu.items.length; i++) { + providerMenu.items[i].checked = providerMenu.items[i].text === providerName + } + + if (minimap) { + minimap.destroy() + minimap = null + } + + createMap(providerName) + if (map.error === Map.NoError) { + selectMapType(map.activeMapType) + toolsMenu.createMenu(map); + } else { + mapTypeMenu.clear(); + toolsMenu.clear(); + } + } + + onSelectMapType: { + stackView.pop(page) + for (var i = 0; i < mapTypeMenu.items.length; i++) { + mapTypeMenu.items[i].checked = mapTypeMenu.items[i].text === mapType.name + } + map.activeMapType = mapType + } + + + onSelectTool: { + switch (tool) { + case "AddressRoute": + stackView.push({ item: Qt.resolvedUrl("RouteAddress.qml") , + properties: { "plugin": map.plugin, + "toAddress": toAddress, + "fromAddress": fromAddress}}) + stackView.currentItem.showRoute.connect(showRoute) + stackView.currentItem.showMessage.connect(stackView.showMessage) + stackView.currentItem.closeForm.connect(stackView.closeForm) + break + case "CoordinateRoute": + stackView.push({ item: Qt.resolvedUrl("RouteCoordinate.qml") , + properties: { "toCoordinate": toCoordinate, + "fromCoordinate": fromCoordinate}}) + stackView.currentItem.showRoute.connect(showRoute) + stackView.currentItem.closeForm.connect(stackView.closeForm) + break + case "Geocode": + stackView.push({ item: Qt.resolvedUrl("Geocode.qml") , + properties: { "address": fromAddress}}) + stackView.currentItem.showPlace.connect(showPlace) + stackView.currentItem.closeForm.connect(stackView.closeForm) + break + case "RevGeocode": + stackView.push({ item: Qt.resolvedUrl("ReverseGeocode.qml") , + properties: { "coordinate": fromCoordinate}}) + stackView.currentItem.showPlace.connect(showPlace) + stackView.currentItem.closeForm.connect(stackView.closeForm) + break + case "Language": + stackView.push({ item: Qt.resolvedUrl("Locale.qml") , + properties: { "locale": map.plugin.locales[0]}}) + stackView.currentItem.selectLanguage.connect(setLanguage) + stackView.currentItem.closeForm.connect(stackView.closeForm) + break + default: + console.log("Unsupported operation") } } - function show(coordinate) { + onToggleMapState: { + stackView.pop(page) + switch (state) { + case "FollowMe": + map.followme = !map.followme + break + case "MiniMap": + toggleMiniMapState() + isMiniMap = minimap + break + default: + console.log("Unsupported operation") + } + } + } + + MapPopupMenu { + id: mapPopupMenu + + function show(coordinate) + { stackView.pop(page) mapPopupMenu.coordinate = coordinate mapPopupMenu.markersCount = map.markers.length @@ -382,10 +338,58 @@ ApplicationWindow { mapPopupMenu.update() mapPopupMenu.popup() } + + onItemClicked: { + stackView.pop(page) + switch (item) { + case "addMarker": + map.addMarker() + break + case "getCoordinate": + map.coordinatesCaptured(coordinate.latitude, coordinate.longitude) + break + case "fitViewport": + map.fitViewportToMapItems() + break + case "deleteMarkers": + map.deleteMarkers() + break + case "deleteItems": + map.deleteMapItems() + break + default: + console.log("Unsupported operation") + } + } } MarkerPopupMenu { id: markerPopupMenu + + function show(coordinate) + { + stackView.pop(page) + markerPopupMenu.markersCount = map.markers.length + markerPopupMenu.update() + markerPopupMenu.popup() + } + + function askForCoordinate() + { + stackView.push({ item: Qt.resolvedUrl("ReverseGeocode.qml") , + properties: { "title": qsTr("New Coordinate"), + "coordinate": map.markers[map.currentMarker].coordinate}}) + stackView.currentItem.showPlace.connect(moveMarker) + stackView.currentItem.closeForm.connect(stackView.closeForm) + } + + function moveMarker(coordinate) + { + map.markers[map.currentMarker].coordinate = coordinate; + map.center = coordinate; + stackView.pop(page) + } + onItemClicked: { stackView.pop(page) switch (item) { @@ -405,8 +409,8 @@ ApplicationWindow { case "distanceToNextPoint": var coordinate1 = map.markers[currentMarker].coordinate; var coordinate2 = map.markers[currentMarker+1].coordinate; - var distance = map.formatDistance(coordinate1.distanceTo(coordinate2)); - showMessage(qsTr("Distance"),"<b>" + qsTr("Distance:") + "</b> " + distance) + var distance = Helper.formatDistance(coordinate1.distanceTo(coordinate2)); + stackView.showMessage(qsTr("Distance"),"<b>" + qsTr("Distance:") + "</b> " + distance) break case "drawImage": map.addGeoItem("ImageItem") @@ -427,36 +431,13 @@ ApplicationWindow { console.log("Unsupported operation") } } - - function show(coordinate) { - stackView.pop(page) - markerPopupMenu.markersCount = map.markers.length - markerPopupMenu.update() - markerPopupMenu.popup() - } - - function askForCoordinate() { - stackView.push({ item: Qt.resolvedUrl("ReverseGeocode.qml") , - properties: { "title": qsTr("New Coordinate"), - "coordinate": map.markers[map.currentMarker].coordinate}}) - stackView.currentItem.showPlace.connect(moveMarker) - stackView.currentItem.closeForm.connect(closeForm) - } - - function moveMarker(coordinate) - { - map.markers[map.currentMarker].coordinate = coordinate; - map.center = coordinate; - stackView.pop(page) - } - } ItemPopupMenu { - id: itemPopupMenu - function show(type,coordinate) { + function show(type,coordinate) + { stackView.pop(page) itemPopupMenu.type = type itemPopupMenu.update() @@ -467,7 +448,7 @@ ApplicationWindow { stackView.pop(page) switch (item) { case "showRouteInfo": - showRouteListPage() + stackView.showRouteListPage() break; case "deleteRoute": map.routeModel.reset(); @@ -482,10 +463,8 @@ ApplicationWindow { console.log("Unsupported operation") } } - } - StackView { id: stackView anchors.fill: parent @@ -493,5 +472,35 @@ ApplicationWindow { initialItem: Item { id: page } + + function showMessage(title,message,backPage) + { + push({ item: Qt.resolvedUrl("Message.qml") , + properties: { + "title" : title, + "message" : message, + "backPage" : backPage + }}) + currentItem.closeForm.connect(closeMessage) + } + + function closeMessage(backPage) + { + pop(backPage) + } + + function closeForm() + { + pop(page) + } + + function showRouteListPage() + { + push({ item: Qt.resolvedUrl("RouteList.qml") , + properties: { + "routeModel" : map.routeModel + }}) + currentItem.closeForm.connect(closeForm) + } } } diff --git a/examples/location/mapviewer/mapviewerwrapper.qrc b/examples/location/mapviewer/mapviewerwrapper.qrc index aceba310..dcbbbcab 100644 --- a/examples/location/mapviewer/mapviewerwrapper.qrc +++ b/examples/location/mapviewer/mapviewerwrapper.qrc @@ -29,5 +29,6 @@ <file>RouteList.qml</file> <file>RouteListDelegate.qml</file> <file>RouteListHeader.qml</file> + <file>helper.js</file> </qresource> </RCC> |