From 6829c48816d996c8e920b581d0018a03a59d62fc Mon Sep 17 00:00:00 2001 From: Osmo Salomaa Date: Sat, 12 Apr 2014 22:20:25 +0300 Subject: [PATCH] Allow showing all geocoding results. --- qml/GeocodingResultsPage.qml | 12 ++++++++++++ qml/Map.qml | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/qml/GeocodingResultsPage.qml b/qml/GeocodingResultsPage.qml index cff7f68..bd17d0f 100644 --- a/qml/GeocodingResultsPage.qml +++ b/qml/GeocodingResultsPage.qml @@ -65,6 +65,18 @@ Page { } header: PageHeader { title: page.title } model: ListModel { id: listModel } + PullDownMenu { + visible: listModel.count > 1 + MenuItem { + text: "Show all" + onClicked: { + for (var i = 0; i < listModel.count; i++) + map.addPoi(listModel.get(i).x, listModel.get(i).y); + map.fitViewToPois(); + app.pageStack.pop(mapPage, PageStackAction.Immediate); + } + } + } VerticalScrollDecorator {} } BusyIndicator { diff --git a/qml/Map.qml b/qml/Map.qml index 24e8c2f..817b1b3 100644 --- a/qml/Map.qml +++ b/qml/Map.qml @@ -129,6 +129,31 @@ Map { map.pois = []; } + function fitViewToPois() { + // Set center and zoom so that all points of interest are visible. + var cx = 0; + var cy = 0; + for (var i = 0; i < map.pois.length; i++) { + cx += map.pois[i].coordinate.longitude; + cy += map.pois[i].coordinate.latitude; + } + cx /= map.pois.length; + cy /= map.pois.length; + map.setCenter(cx, cy); + while (map.zoomLevel > map.minimumZoomLevel) { + var allIn = true; + for (var i = 0; i < map.pois.length; i++) { + if (!map.inView(map.pois[i].coordinate.longitude, + map.pois[i].coordinate.latitude)) { + allIn = false; + break; + } + } + if (allIn) break; + map.setZoomLevel(map.zoomLevel - 1); + } + } + function getBoundingBox() { // Return currently visible [xmin, xmax, ymin, ymax]. var nw = map.toCoordinate(Qt.point(0, 0)); @@ -136,6 +161,12 @@ Map { return [nw.longitude, se.longitude, se.latitude, nw.latitude]; } + function inView(x, y) { + // Return true if point in the current view. + var bbox = map.getBoundingBox(); + return (x >= bbox[0] && x <= bbox[1] && y >= bbox[2] && y <= bbox[3]) + } + function renderTile(uid, x, y, zoom, uri) { // Render tile from local image file. for (var i = 0; i < map.tiles.length; i++) { @@ -172,12 +203,14 @@ Map { if (!x || !y) return; map.center.longitude = x; map.center.latitude = y; + map.changed = true; } function setZoomLevel(zoom) { // Set the current zoom level. map.zoomLevel = zoom; map.zoomLevelPrev = zoom; + map.changed = true; } function showTile(uid) {