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/location/maps/qgeomap.cpp | |
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/location/maps/qgeomap.cpp')
-rw-r--r-- | src/location/maps/qgeomap.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/location/maps/qgeomap.cpp b/src/location/maps/qgeomap.cpp index ac6d661b..f30dbce7 100644 --- a/src/location/maps/qgeomap.cpp +++ b/src/location/maps/qgeomap.cpp @@ -120,6 +120,39 @@ QGeoCameraCapabilities QGeoMap::cameraCapabilities() const return QGeoCameraCapabilities(); } +/* Default implementations */ +QGeoCoordinate QGeoMap::itemPositionToCoordinate(const QDoubleVector2D &pos, bool clipToViewport) const +{ + if (clipToViewport) { + int w = viewportWidth(); + int h = viewportHeight(); + + if ((pos.x() < 0) || (w < pos.x()) || (pos.y() < 0) || (h < pos.y())) + return QGeoCoordinate(); + } + + QDoubleVector2D wrappedMapProjection = itemPositionToWrappedMapProjection(pos); + // With rotation/tilting, a screen position might end up outside the projection space. + // TODO: test for it + return mapProjectionToGeo(unwrapMapProjection(wrappedMapProjection)); +} + +QDoubleVector2D QGeoMap::coordinateToItemPosition(const QGeoCoordinate &coordinate, bool clipToViewport) const +{ + QDoubleVector2D pos = wrappedMapProjectionToItemPosition(wrapMapProjection(geoToMapProjection(coordinate))); + + if (clipToViewport) { + int w = viewportWidth(); + int h = viewportHeight(); + double x = pos.x(); + double y = pos.y(); + if ((x < -0.5) || (x > w + 0.5) || (y < -0.5) || (y > h + 0.5) || qIsNaN(x) || qIsNaN(y)) + return QDoubleVector2D(qQNaN(), qQNaN()); + } + return pos; +} + + void QGeoMap::prefetchData() { |