23 class DownloadRegionPrivate
26 MarbleModel* m_marbleModel;
30 int m_visibleTileLevel;
32 DownloadRegionPrivate();
34 int rad2PixelX( qreal
const lon,
const TextureLayer *textureLayer )
const;
36 int rad2PixelY( qreal
const lat,
const TextureLayer *textureLayer )
const;
39 DownloadRegionPrivate::DownloadRegionPrivate() : m_marbleModel( 0 ),
40 m_tileLevelRange( 0, 0 ), m_visibleTileLevel( 0 )
46 int DownloadRegionPrivate::rad2PixelX( qreal
const lon,
const TextureLayer *textureLayer )
const
48 qreal
const globalWidth = textureLayer->tileSize().width()
49 * textureLayer->tileColumnCount( m_visibleTileLevel );
50 return static_cast<int>( globalWidth * 0.5 + lon * ( globalWidth / ( 2.0 *
M_PI ) ) );
54 int DownloadRegionPrivate::rad2PixelY( qreal
const lat,
const TextureLayer *textureLayer )
const
56 qreal
const globalHeight = textureLayer->tileSize().height()
57 * textureLayer->tileRowCount( m_visibleTileLevel );
58 qreal
const normGlobalHeight = globalHeight /
M_PI;
59 switch ( textureLayer->tileProjection() ) {
61 return static_cast<int>( globalHeight * 0.5 - lat * normGlobalHeight );
63 if ( fabs( lat ) < 1.4835 )
64 return static_cast<int>( globalHeight * 0.5 -
gdInv( lat ) * 0.5 * normGlobalHeight );
66 return static_cast<int>( globalHeight * 0.5 - 3.1309587 * 0.5 * normGlobalHeight );
68 return static_cast<int>( globalHeight * 0.5 + 3.1309587 * 0.5 * normGlobalHeight );
76 d( new DownloadRegionPrivate )
83 d->m_marbleModel = model;
93 Q_ASSERT( minimumTileLevel >= 0 );
94 Q_ASSERT( maximumTileLevel >= 0 );
95 Q_ASSERT( minimumTileLevel <= maximumTileLevel );
96 d->m_tileLevelRange.first = minimumTileLevel;
97 d->m_tileLevelRange.second = maximumTileLevel;
102 Q_ASSERT( textureLayer );
103 int const westX = d->rad2PixelX( downloadRegion.
west(), textureLayer );
104 int const northY = d->rad2PixelY( downloadRegion.
north(), textureLayer );
105 int const eastX = d->rad2PixelX( downloadRegion.
east(), textureLayer );
106 int const southY = d->rad2PixelY( downloadRegion.
south(), textureLayer );
109 mDebug() <<
"DownloadRegionDialog downloadRegion:"
110 <<
"north:" << downloadRegion.
north()
111 <<
"south:" << downloadRegion.
south()
112 <<
"east:" << downloadRegion.
east()
113 <<
"west:" << downloadRegion.
west();
114 mDebug() <<
"north/west (x/y):" << westX << northY;
115 mDebug() <<
"south/east (x/y):" << eastX << southY;
119 mDebug() <<
"DownloadRegionDialog downloadRegion: tileSize:" << tileWidth << tileHeight;
121 int const visibleLevelX1 = qMin( westX, eastX );
122 int const visibleLevelY1 = qMin( northY, southY );
123 int const visibleLevelX2 = qMax( westX, eastX );
124 int const visibleLevelY2 = qMax( northY, southY );
126 mDebug() <<
"visible level pixel coords (level/x1/y1/x2/y2):" << d->m_visibleTileLevel
127 << visibleLevelX1 << visibleLevelY1 << visibleLevelX2 << visibleLevelY2;
129 int bottomLevelX1, bottomLevelY1, bottomLevelX2, bottomLevelY2;
132 if ( d->m_visibleTileLevel > d->m_tileLevelRange.second ) {
133 int const deltaLevel = d->m_visibleTileLevel - d->m_tileLevelRange.second;
134 bottomLevelX1 = visibleLevelX1 >> deltaLevel;
135 bottomLevelY1 = visibleLevelY1 >> deltaLevel;
136 bottomLevelX2 = visibleLevelX2 >> deltaLevel;
137 bottomLevelY2 = visibleLevelY2 >> deltaLevel;
139 else if ( d->m_visibleTileLevel < d->m_tileLevelRange.second ) {
140 int const deltaLevel = d->m_tileLevelRange.second - d->m_visibleTileLevel;
141 bottomLevelX1 = visibleLevelX1 << deltaLevel;
142 bottomLevelY1 = visibleLevelY1 << deltaLevel;
143 bottomLevelX2 = visibleLevelX2 << deltaLevel;
144 bottomLevelY2 = visibleLevelY2 << deltaLevel;
147 bottomLevelX1 = visibleLevelX1;
148 bottomLevelY1 = visibleLevelY1;
149 bottomLevelX2 = visibleLevelX2;
150 bottomLevelY2 = visibleLevelY2;
152 mDebug() <<
"bottom level pixel coords (level/x1/y1/x2/y2):"
153 << d->m_tileLevelRange.second
154 << bottomLevelX1 << bottomLevelY1 << bottomLevelX2 << bottomLevelY2;
156 TileCoordsPyramid coordsPyramid( d->m_tileLevelRange.first, d->m_tileLevelRange.second );
157 QRect bottomLevelTileCoords;
159 ( bottomLevelX1 / tileWidth,
160 bottomLevelY1 / tileHeight,
161 bottomLevelX2 / tileWidth + ( bottomLevelX2 % tileWidth > 0 ? 1 : 0 ),
162 bottomLevelY2 / tileHeight + ( bottomLevelY2 % tileHeight > 0 ? 1 : 0 ));
163 mDebug() <<
"bottom level tile coords: (x1/y1/size):" << bottomLevelTileCoords;
167 pyramid << coordsPyramid;
173 d->m_visibleTileLevel = tileLevel;
178 if ( !d->m_marbleModel ) {
182 int const topLevel = d->m_tileLevelRange.first;
183 int const bottomLevel = d->m_tileLevelRange.second;
189 qreal
radius = d->m_marbleModel->planetRadius();
191 qreal radianOffset = offset /
radius;
193 for(
int i = 1; i < waypoints.
size(); ++i ) {
196 qreal latCenter = position.
latitude();
199 qreal latNorth = asin( sin( latCenter ) * cos( radianOffset ) + cos( latCenter ) * sin( radianOffset ) * cos( 7*
M_PI/4 ) );
200 qreal dlonWest = atan2( sin( 7*
M_PI/4 ) * sin( radianOffset ) * cos( latCenter ), cos( radianOffset ) - sin( latCenter ) * sin( latNorth ) );
201 qreal lonWest = fmod( lonCenter - dlonWest +
M_PI, 2*
M_PI ) -
M_PI;
202 qreal latSouth = asin( sin( latCenter ) * cos( radianOffset ) + cos( latCenter ) * sin( radianOffset ) * cos( 3*
M_PI/4 ) );
203 qreal dlonEast = atan2( sin( 3*
M_PI/4 ) * sin( radianOffset ) * cos( latCenter ), cos( radianOffset ) - sin( latCenter ) * sin( latSouth ) );
204 qreal lonEast = fmod( lonCenter - dlonEast+
M_PI, 2*
M_PI ) -
M_PI;
206 int const northY = d->rad2PixelY( latNorth, textureLayer );
207 int const southY = d->rad2PixelY( latSouth, textureLayer );
208 int const eastX = d->rad2PixelX( lonEast, textureLayer );
209 int const westX = d->rad2PixelX( lonWest, textureLayer );
211 int const west = qMin( westX, eastX );
212 int const north = qMin( northY, southY );
213 int const east = qMax( westX, eastX );
214 int const south = qMax( northY, southY );
216 int bottomLevelTileX1 = 0;
217 int bottomLevelTileY1 = 0;
218 int bottomLevelTileX2 = 0;
219 int bottomLevelTileY2 = 0;
221 if ( d->m_visibleTileLevel > d->m_tileLevelRange.second ) {
222 int const deltaLevel = d->m_visibleTileLevel - d->m_tileLevelRange.second;
223 bottomLevelTileX1 = west >> deltaLevel;
224 bottomLevelTileY1 = north >> deltaLevel;
225 bottomLevelTileX2 = east >> deltaLevel;
226 bottomLevelTileY2 = south >> deltaLevel;
228 else if ( d->m_visibleTileLevel < bottomLevel ) {
229 int const deltaLevel = bottomLevel - d->m_visibleTileLevel;
230 bottomLevelTileX1 = west << deltaLevel;
231 bottomLevelTileY1 = north << deltaLevel;
232 bottomLevelTileX2 = east << deltaLevel;
233 bottomLevelTileY2 = south << deltaLevel;
236 bottomLevelTileX1 = west;
237 bottomLevelTileY1 = north;
238 bottomLevelTileX2 = east;
239 bottomLevelTileY2 = south;
242 QRect waypointRegion;
244 waypointRegion.
setCoords( bottomLevelTileX1/tileWidth, bottomLevelTileY1/tileHeight,
245 bottomLevelTileX2/tileWidth, bottomLevelTileY2/tileHeight );
247 pyramid << coordsPyramid;
255 #include "DownloadRegion.moc"
A 3d point representation.
qreal gdInv(qreal x)
This method is a fast Mac Laurin power series approximation of the.
void setMarbleModel(MarbleModel *model)
This file contains the headers for MarbleModel.
int size() const
Returns the number of nodes in a LineString.
qreal latitude(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
retrieves the latitude of the GeoDataCoordinates object use the unit parameter to switch between Radi...
qreal north(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the northern boundary of the bounding box.
qreal east(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the eastern boundary of the bounding box.
This file contains the headers for MarbleMap.
QVector< TileCoordsPyramid > region(const TextureLayer *textureLayer, const GeoDataLatLonAltBox ®ion) const
void setCoords(int x1, int y1, int x2, int y2)
static qreal radius(qreal zoom)
QVector< TileCoordsPyramid > fromPath(const TextureLayer *textureLayer, qreal offset, const GeoDataLineString &path) const
calculates the region to be downloaded around a path
qint64 tilesCount() const
returns the number of tiles covered by one pyramid
A LineString that allows to store a contiguous set of line segments.
qreal longitude(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
retrieves the longitude of the GeoDataCoordinates object use the unit parameter to switch between Rad...
qreal west(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the western boundary of the bounding box.
The data model (not based on QAbstractModel) for a MarbleWidget.
void setTileLevelRange(int const minimumTileLevel, int const maximumTileLevel)
qreal south(GeoDataCoordinates::Unit unit=GeoDataCoordinates::Radian) const
Get the southern boundary of the bounding box.
void setBottomLevelCoords(QRect const &coords)
void setVisibleTileLevel(int const tileLevel)
QDebug mDebug()
a function to replace qDebug() in Marble library code
A class that defines a 3D bounding box for geographic data.
DownloadRegion(QObject *parent=0)