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

Commit

Permalink
Account for navigation block and auto-rotate when centering
Browse files Browse the repository at this point in the history
Closes #14
  • Loading branch information
otsaloma committed Oct 19, 2016
1 parent e9e2cd9 commit 24dd599
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
10 changes: 7 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ Poor Maps 0.26
==============

* [x] Add [OSM Scout Server][0.26a] offline tiles, geocoder and nearby
search -- listed in Poor Maps if you have OSM Scout Server
installed and they will only work if the server is running and you
have OpenStreetMap data available for the server (rinigus)
search – only listed in Poor Maps if you have OSM Scout Server
installed and will only work if the server is running and you
have made OpenStreetMap data available for the server (rinigus)
* [x] Increase download thread count to match CPU core count for
localhost (offline) tile servers
* [x] When navigating, make centering and auto-centering on position
center the position on the part of the map visible below the
navigation narrative, and further, if auto-rotate is on, center
slightly lower so that more map is shown ahead than behind (#14)

[0.26a]: https://openrepos.net/content/rinigus/osm-scout-server
31 changes: 28 additions & 3 deletions qml/Map.qml
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,20 @@ Map {
// otherwise actually relative positions inside the map component,
// which can differ from the screen when using auto-rotation.
var pos = map.toScreenPosition(map.position.coordinate);
if (!pos.x || Math.abs(pos.x - map.width/2) > app.screenWidth/6 ||
!pos.y || Math.abs(pos.y - map.height/2) > app.screenHeight/6)
var cx = map.width / 2, cy = map.height / 2;
if (app.navigationBlock.height > 0) {
// If the navigation block covers the top part of the screen,
// center the position to the part of the map remaining visible.
cy += app.navigationBlock.height / 2;
if (map.autoRotate)
// If auto-rotate is on, the user is always heading up
// on the screen and should see more ahead than behind.
cy += 0.1 * (app.screenHeight - app.navigationBlock.height);
}
var dx = app.screenWidth / 6;
var dy = (app.screenHeight - app.navigationBlock.height) / 6;
if (!pos.x || Math.abs(pos.x - cx) > dx ||
!pos.y || Math.abs(pos.y - cy) > dy)
map.centerOnPosition();
}
}
Expand Down Expand Up @@ -235,8 +247,21 @@ Map {

function centerOnPosition() {
// Center map on the current position.
var yshift = 0;
if (app.navigationBlock.height > 0) {
// If the navigation block covers the top part of the screen,
// center the position to the part of the map remaining visible.
var dy = app.navigationBlock.height / 2;
if (map.autoRotate)
// If auto-rotate is on, the user is always heading up
// on the screen and should see more ahead than behind.
dy += 0.1 * (app.screenHeight - app.navigationBlock.height);
var y0 = map.toCoordinate(Qt.point(map.width/2, map.height/2));
var y1 = map.toCoordinate(Qt.point(map.width/2, map.height/2 + dy));
yshift = y1.latitude - y0.latitude;
}
map.setCenter(map.position.coordinate.longitude,
map.position.coordinate.latitude);
map.position.coordinate.latitude - yshift);

}

Expand Down

0 comments on commit 24dd599

Please sign in to comment.