TileId TileId::fromCoordinates(const GeoDataCoordinates &coords, int zoomLevel) { if ( zoomLevel < 0 ) { return TileId(); } const int maxLat = 90 * 1000000; const int maxLon = 180 * 1000000; int lat = GeoDataCoordinates::normalizeLat( coords.latitude( GeoDataCoordinates::Degree ), GeoDataCoordinates::Degree ) * 1000000; int lon = GeoDataCoordinates::normalizeLon( coords.longitude( GeoDataCoordinates::Degree ), GeoDataCoordinates::Degree ) * 1000000; int x = 0; int y = 0; for( int i=0; i<zoomLevel; ++i ) { const int deltaLat = maxLat >> i; if( lat <= ( maxLat - deltaLat )) { y += 1<<(zoomLevel-i-1); lat += deltaLat; } const int deltaLon = maxLon >> i; if( lon >= ( maxLon - deltaLon )) { x += 1<<(zoomLevel-i-1); } else { lon += deltaLon; } } return TileId(0, zoomLevel, x, y); }
void GeoGraphicsScene::addIdem( GeoGraphicsItem* item ) { // Select zoom level so that the object fit in single tile int zoomLevel; qreal north, south, east, west; item->latLonAltBox().boundaries( north, south, east, west ); for(zoomLevel = s_tileZoomLevel; zoomLevel >= 0; zoomLevel--) { if( d->coordToTileId( GeoDataCoordinates(west, north, 0), zoomLevel ) == d->coordToTileId( GeoDataCoordinates(east, south, 0), zoomLevel ) ) break; } int tnorth, tsouth, teast, twest; TileId key; key = d->coordToTileId( GeoDataCoordinates(west, north, 0), zoomLevel ); twest = key.x(); tnorth = key.y(); key = d->coordToTileId( GeoDataCoordinates(east, south, 0), zoomLevel ); teast = key.x(); tsouth = key.y(); for( int i = twest; i <= teast; i++ ) { for( int j = tsouth; j <= tnorth; j++ ) { QList< GeoGraphicsItem* >& tileList = d->m_items[TileId( "", zoomLevel, i, j )]; QList< GeoGraphicsItem* >::iterator position = qLowerBound( tileList.begin(), tileList.end(), item, zValueLessThan ); tileList.insert( position, item ); } } }
void GeoGraphicsScene::removeItem( GeoGraphicsItem* item ) { int zoomLevel; qreal north, south, east, west; item->latLonAltBox().boundaries( north, south, east, west ); for(zoomLevel = s_tileZoomLevel; zoomLevel >= 0; zoomLevel--) { if( d->coordToTileId( GeoDataCoordinates(west, north, 0), zoomLevel ) == d->coordToTileId( GeoDataCoordinates(east, south, 0), zoomLevel ) ) break; } int tnorth, tsouth, teast, twest; TileId key; key = d->coordToTileId( GeoDataCoordinates(west, north, 0), zoomLevel ); twest = key.x(); tnorth = key.y(); key = d->coordToTileId( GeoDataCoordinates(east, south, 0), zoomLevel ); teast = key.x(); tsouth = key.y(); for( int i = twest; i <= teast; i++ ) { for( int j = tsouth; j <= tnorth; j++ ) { QList< GeoGraphicsItem* >& tileList = d->m_items[TileId( "", zoomLevel, i, j )]; tileList.removeOne( item ); } } }
/** * Return the parent tile. * * Note that the parent tile will cover a 4 times bigger region than the current tile. * * Note that for tiles with level 0 no parent tile will exist. The method will assert in this case! */ TileId TileId::GetParent() const { Magnification zoomedOutMagnification; assert(magnification.GetLevel()>0); zoomedOutMagnification.SetLevel(magnification.GetLevel()-1); return TileId(zoomedOutMagnification,x/2,y/2); }
void TileLoader::updateTile( QByteArray const & data, QString const & idStr ) { QStringList const components = idStr.split( ':', QString::SkipEmptyParts ); Q_ASSERT( components.size() == 4 ); QString const sourceDir = components[ 0 ]; int const zoomLevel = components[ 1 ].toInt(); int const tileX = components[ 2 ].toInt(); int const tileY = components[ 3 ].toInt(); TileId const id = TileId( sourceDir, zoomLevel, tileX, tileY ); QImage const tileImage = QImage::fromData( data ); if ( tileImage.isNull() ) return; emit tileCompleted( id, tileImage ); }
void TileMap::shiftleft() { for (int y = 0; y < height_; y++) { for (int x = 1; x < width_; x++) { int index = x + y * width_; // transfer [x][y] -> [x-1][y] tileids_[index - 1] = tileids_[index]; } { int index = (width_ - 1) + y * width_; tileids_[index] = TileId(EMPTY_TILE, EMPTY_TILE); } } }
void TileMap::shiftdown() { for (int x = 0; x < width_; x++) { for (int y = height_ - 2; y >= 0; y--) { int index = x + y * width_; // transfer [x][y] -> [x][y+1] tileids_[index + width_] = tileids_[index]; } { int index = x + 0 * width_; tileids_[index] = TileId(EMPTY_TILE, EMPTY_TILE); } } }
void TileMap::shiftup() { for (int x = 0; x < width_; x++) { for (int y = 1; y < height_; y++) { int index = x + y * width_; // transfer [x][y] -> [x][y-1] tileids_[index - width_] = tileids_[index]; } { int index = x + (height_ - 1) * width_; tileids_[index] = TileId(EMPTY_TILE, EMPTY_TILE); } } }
void TileMap::shiftright() { for (int y = 0; y < height_; y++) { for (int x = width_ - 2; x >= 0; x--) { int index = x + y * width_; // transfer [x][y] -> [x+1][y] tileids_[index + 1] = tileids_[index]; } { int index = 0 + y * width_; tileids_[index] = TileId(EMPTY_TILE, EMPTY_TILE); } } }
void TileLoader::updateTile(const QString &fileName, const QString &idStr) { QStringList const components = idStr.split( ':', QString::SkipEmptyParts ); Q_ASSERT( components.size() == 5 ); QString const origin = components[0]; QString const sourceDir = components[ 1 ]; int const zoomLevel = components[ 2 ].toInt(); int const tileX = components[ 3 ].toInt(); int const tileY = components[ 4 ].toInt(); TileId const id = TileId( sourceDir, zoomLevel, tileX, tileY ); if (origin == GeoSceneTypes::GeoSceneVectorTileType) { GeoDataDocument* document = openVectorFile(MarbleDirs::path(fileName)); if (document) { emit tileCompleted(id, document); } } }
TileMap::TileMap(Application* application, int width, int height, TextureBase* texture, int tilewidth, int tileheight, int spacingx, int spacingy, int marginx, int marginy, int displaywidth, int displayheight) : Sprite(application) { texture_ = texture; texture_->ref(); tileids_.resize(width * height, TileId(EMPTY_TILE, EMPTY_TILE)); width_ = width; height_ = height; tilewidth_ = tilewidth; tileheight_ = tileheight; spacingx_ = spacingx; spacingy_ = spacingy; marginx_ = marginx; marginy_ = marginy; displaywidth_ = displaywidth; displayheight_ = displayheight; }
/** * Return all tile necessary for covering the given boundingbox using the given magnification. */ void DataTileCache::GetTilesForBoundingBox(const Magnification& magnification, const GeoBox& boundingBox, std::list<TileRef>& tiles) const { tiles.clear(); //log.Debug() << "Creating tile data for level " << level << " and bounding box " << boundingBox.GetDisplayText(); uint32_t level=magnification.GetLevel(); uint32_t cx1=(uint32_t)floor((boundingBox.GetMinLon()+180.0)/cellDimension[level].width); uint32_t cy1=(uint32_t)floor((boundingBox.GetMinLat()+90.0)/cellDimension[level].height); uint32_t cx2=(uint32_t)floor((boundingBox.GetMaxLon()+180.0)/cellDimension[level].width); uint32_t cy2=(uint32_t)floor((boundingBox.GetMaxLat()+90.0)/cellDimension[level].height); //std::cout << "Tile bounding box: " << cx1 << "," << cy1 << " - " << cx2 << "," << cy2 << std::endl; for (size_t y=cy1; y<=cy2; y++) { for (size_t x=cx1; x<=cx2; x++) { tiles.push_back(GetTile(TileId(magnification,x,y))); } } }