diff options
author | Paolo Angelelli <paolo.angelelli@qt.io> | 2016-11-16 17:05:15 +0100 |
---|---|---|
committer | Paolo Angelelli <paolo.angelelli@qt.io> | 2016-12-07 11:59:33 +0000 |
commit | 2906563af414810a71d704db7b4d5f7c882c3667 (patch) | |
tree | 90eaf69e4cc66cd971cbd3667c8de65824b40880 /src/imports | |
parent | 7656821275de8b932c75063adfcdf8deb968db84 (diff) | |
download | qtlocation-2906563af414810a71d704db7b4d5f7c882c3667.tar.gz |
Refactor QGeoMap API: split coordinate <-> itemPosition calls
This patch splits the two calls coordinateToItemPosition and
itemPositionToCoordinate into 3 separate steps:
- coordinate to map projection. Map projection has always to be in [0,1]
[0,1] range.
In case of QGeoTiledMap, the only map projection supported is
WebMercator, thus this call is currently equivalent to
coordinateToMercator.
- wrap map projection. Due to the longitude-wrapping-around nature of
QGeoMap/QDeclarativeGeoMap, coordinates which are greater than others
might end up before the others on the X axis of the projection.
This stage takes care of this aspect
- finally wrapped map projection to item position. this maps a wrapped
coordinate to screen.
Equivalent calls to do the inverse conversion are also provided.
The benefits of splitting the conversion in 3 are:
- possibility to precompute the map projection of item coordinates,
thus having to simply re-wrap them (2 ifs and one sum) upon camera
change.
- Possibility to bake the last step into a 4x4 matrix and offload
this to GPU
- support for rotation and tilting cameras. Without, it would be
impossible to "unwrapBelowX" item coordinates in presence of
rotation and tilt, while now it would be possible to do this before
the final projection to screen that peforms the tilting/rotation.
Change-Id: I9b6a06ff051bbfd09e6d3584485acdcebdceb7bd
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/imports')
-rw-r--r-- | src/imports/location/qdeclarativegeomap.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/imports/location/qdeclarativegeomap.cpp b/src/imports/location/qdeclarativegeomap.cpp index d432e776..050b5afb 100644 --- a/src/imports/location/qdeclarativegeomap.cpp +++ b/src/imports/location/qdeclarativegeomap.cpp @@ -962,21 +962,21 @@ void QDeclarativeGeoMap::fitViewportToGeoShape() return; } - // adjust zoom, use reference world to keep things simple - // otherwise we would need to do the error prone longitudes - // wrapping - QDoubleVector2D topLeftPoint = - m_map->referenceCoordinateToItemPosition(topLeft); - QDoubleVector2D bottomRightPoint = - m_map->referenceCoordinateToItemPosition(bottomRight); + QDoubleVector2D topLeftPoint = m_map->geoToMapProjection(topLeft); + QDoubleVector2D bottomRightPoint = m_map->geoToMapProjection(bottomRight); + if (bottomRightPoint.x() < topLeftPoint.x()) // crossing the dateline + bottomRightPoint.setX(bottomRightPoint.x() + 1.0); + double bboxWidth = bottomRightPoint.x() - topLeftPoint.x(); double bboxHeight = bottomRightPoint.y() - topLeftPoint.y(); + bboxWidth *= m_map->mapWidth(); + bboxHeight *= m_map->mapHeight(); // find center of the bounding box - QGeoCoordinate centerCoordinate = - m_map->referenceItemPositionToCoordinate( - (topLeftPoint + bottomRightPoint)/2); + QDoubleVector2D center = (topLeftPoint + bottomRightPoint) * 0.5; + center.setX(center.x() > 1.0 ? center.x() - 1.0 : center.x()); + QGeoCoordinate centerCoordinate = m_map->mapProjectionToGeo(center); // position camera to the center of bounding box setCenter(centerCoordinate); |