Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Commit

Permalink
Allow showing all geocoding results.
Browse files Browse the repository at this point in the history
  • Loading branch information
otsaloma committed Apr 12, 2014
1 parent 39eba3e commit 6829c48
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
12 changes: 12 additions & 0 deletions qml/GeocodingResultsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
33 changes: 33 additions & 0 deletions qml/Map.qml
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,44 @@ 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));
var se = map.toCoordinate(Qt.point(map.width, map.height));
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++) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6829c48

Please sign in to comment.