コード例 #1
0
ファイル: map.cpp プロジェクト: tumic0/GPXSee
void Map::loadTilesSync(QList<Tile> &list)
{
	QList<Download> dl;

	for (int i = 0; i < list.size(); i++) {
		Tile &t = list[i];
		QString file = tileFile(t);
		QFileInfo fi(file);

		if (!fi.exists())
			dl.append(Download(tileUrl(t), file));
		else
			loadTileFile(t, file);
	}

	if (dl.empty())
		return;

	QEventLoop wait;
	connect(&Downloader::instance(), SIGNAL(finished()), &wait, SLOT(quit()));
	if (Downloader::instance().get(dl))
		wait.exec();

	for (int i = 0; i < list.size(); i++) {
		Tile &t = list[i];

		if (t.pixmap().isNull()) {
			QString file = tileFile(t);
			QFileInfo fi(file);

			if (!(fi.exists() && loadTileFile(t, file)))
				fillTile(t);
		}
	}
}
コード例 #2
0
//*************************************************************************************************
//! Reads the TIL file for pertinent info. Returns TRUE if successful
//*************************************************************************************************
bool rspfQuickbirdRpcModel::parseTileData(const rspfFilename& image_file)
{
   rspfFilename tileFile (image_file);
   tileFile.setExtension("TIL");
   if (!findSupportFile(tileFile))
      return false;

   rspfQuickbirdTile tileHdr;
   if(!tileHdr.open(tileFile))
      return false;

   rspfQuickbirdTileInfo info;
   if(!tileHdr.getInfo(info, image_file.file()))
      return false;

   if((info.theUlXOffset != RSPF_INT_NAN) && (info.theUlYOffset != RSPF_INT_NAN) &&
      (info.theLrXOffset != RSPF_INT_NAN) && (info.theLrYOffset != RSPF_INT_NAN) &&
      (info.theLlXOffset != RSPF_INT_NAN) && (info.theLlYOffset != RSPF_INT_NAN) &&
      (info.theUrXOffset != RSPF_INT_NAN) && (info.theUrYOffset != RSPF_INT_NAN))
   {
      theImageClipRect = rspfIrect(rspfIpt(info.theUlXOffset, info.theUlYOffset),
                                    rspfIpt(info.theUrXOffset, info.theUrYOffset),
                                    rspfIpt(info.theLrXOffset, info.theLrYOffset),
                                    rspfIpt(info.theLlXOffset, info.theLlYOffset));
   }
   else if ((info.theUlXOffset != RSPF_INT_NAN) && (info.theUlYOffset != RSPF_INT_NAN) &&
      (theImageClipRect.width() != RSPF_INT_NAN) && (theImageClipRect.height() != RSPF_INT_NAN))
   {
      theImageClipRect = rspfIrect(info.theUlXOffset, info.theUlYOffset,
                                    info.theUlXOffset+theImageClipRect.width()-1, 
                                    info.theUlYOffset+theImageClipRect.height()-1);
   }

   return true;
}
コード例 #3
0
bool writeTilesToDatabase(QStringList const &listTileFiles,
                          Kompex::SQLiteStatement * pStmt)
{

    for(int i=0; i < listTileFiles.size(); i++)   {

        QFile tileFile(listTileFiles[i]);
        if(!tileFile.open(QIODevice::ReadOnly))   {
            qDebug() << "ERROR: Could not open tile file"
                     << listTileFiles[i];
            return false;
        }

        QByteArray pngBlob = tileFile.readAll();
        try   {
            pStmt->Sql("INSERT INTO tiles(id,png) VALUES(?,?)");
            pStmt->BindInt(1,i);
            pStmt->BindBlob(2,pngBlob.data(),pngBlob.size());
            pStmt->ExecuteAndFree();
        }
        catch(Kompex::SQLiteException &exception)   {
            qDebug() << "ERROR: SQLite exception writing tile data:"
                     << QString::fromStdString(exception.GetString());
            return false;
        }
    }
    return true;
}
コード例 #4
0
ファイル: newareadialog.cpp プロジェクト: ZebraQuake/AneMake
void NewAreaDialog::confirm() {
	name = nameEdit->text();
	tile = tileEdit->text();
	obj = objEdit->text();
	width = widthEdit->text().toInt();
	height = heightEdit->text().toInt();
	
	if(name.isEmpty() || name.isNull()) {
		QMessageBox::information(this, "Error", "Name is invalid");
		return;
	}
	
	QFile tileFile(tile);
	tileFile.open(QFile::ReadOnly);
	if(!tileFile.exists() || !tileFile.isOpen()) {
		QMessageBox::information(this, "Error", "Terrain sheet is invalid");
		return;
	}
	
	QFile objFile(obj);
	objFile.open(QFile::ReadOnly);
	if(!objFile.exists() || !objFile.isOpen()) {
		QMessageBox::information(this, "Error", "Object sheet is invalid");
		return;
	}
	
	accept();
}
コード例 #5
0
ファイル: TileManager.cpp プロジェクト: Samuel-Lewis/Crypt
void TileManager::loadTilesFromFile(std::string filename)
{
    // as we get these anytime, we need to keep the dict alive so load it in manually
    tileDict = GDictMake();
    std::ifstream tileFile(resourcePath() + filename);
    if (tileFile.good())
    {
        tileFile >> tileDict;
    }
コード例 #6
0
ファイル: BiomeManager.cpp プロジェクト: Samuel-Lewis/Crypt
void BiomeManager::loadBiomesFromFile(std::string filename)
{
    // as we get these anytime, we need to keep the dict alive so load it in manually
    biomes = GArrayMake();
    std::ifstream tileFile(resourcePath() + filename);
    if (tileFile.good())
    {
        tileFile >> biomes;
    }
コード例 #7
0
ファイル: map.cpp プロジェクト: tumic0/GPXSee
void Map::loadTilesAsync(QList<Tile> &list)
{
	QList<Download> dl;

	for (int i = 0; i < list.size(); i++) {
		Tile &t = list[i];
		QString file = tileFile(t);
		QFileInfo fi(file);

		if (!fi.exists()) {
			fillTile(t);
			dl.append(Download(tileUrl(t), file));
		} else
			loadTileFile(t, file);
	}

	if (!dl.empty())
		Downloader::instance().get(dl);
}
コード例 #8
0
bool OsmAnd::OnlineMapRasterTileProvider_P::obtainTile(const TileId tileId, const ZoomLevel zoom, std::shared_ptr<const MapTile>& outTile, const IQueryController* const queryController)
{
    // Check provider can supply this zoom level
    if(zoom > owner->maxZoom || zoom < owner->minZoom)
    {
        outTile.reset();
        return true;
    }

    // Check if requested tile is already being processed, and wait until that's done
    // to mark that as being processed.
    lockTile(tileId, zoom);

    // Check if requested tile is already in local storage.
    const auto tileLocalRelativePath =
        QString::number(zoom) + QDir::separator() +
        QString::number(tileId.x) + QDir::separator() +
        QString::number(tileId.y) + QLatin1String(".tile");
    QFileInfo localFile;
    {
        QMutexLocker scopedLocker(&_localCachePathMutex);
        localFile.setFile(_localCachePath.filePath(tileLocalRelativePath));
    }
    if(localFile.exists())
    {
        // Since tile is in local storage, it's safe to unmark it as being processed
        unlockTile(tileId, zoom);

        // If local file is empty, it means that requested tile does not exist (has no data)
        if(localFile.size() == 0)
        {
            outTile.reset();
            return true;
        }

        auto bitmap = new SkBitmap();
        SkFILEStream fileStream(qPrintable(localFile.absoluteFilePath()));
        if(!SkImageDecoder::DecodeStream(&fileStream, bitmap, SkBitmap::Config::kNo_Config, SkImageDecoder::kDecodePixels_Mode))
        {
            LogPrintf(LogSeverityLevel::Error, "Failed to decode tile file '%s'", qPrintable(localFile.absoluteFilePath()));

            delete bitmap;

            return false;
        }

        assert(bitmap->width() == bitmap->height());
        assert(bitmap->width() == owner->providerTileSize);

        // Return tile
        auto tile = new MapBitmapTile(bitmap, owner->alphaChannelData);
        outTile.reset(tile);
        return true;
    }

    // Since tile is not in local cache (or cache is disabled, which is the same),
    // the tile must be downloaded from network:

    // If network access is disallowed, return failure
    if(!_networkAccessAllowed)
    {
        // Before returning, unlock tile
        unlockTile(tileId, zoom);

        return false;
    }

    // Check if there is free download slot. If all download slots are used, wait for one to be freed
    if(owner->maxConcurrentDownloads > 0)
    {
        QMutexLocker scopedLocker(&_currentDownloadsCounterMutex);

        while(_currentDownloadsCounter >= owner->maxConcurrentDownloads)
            _currentDownloadsCounterChanged.wait(&_currentDownloadsCounterMutex);

        _currentDownloadsCounter++;
    }

    // Perform synchronous download
    auto tileUrl = owner->urlPattern;
    tileUrl
        .replace(QLatin1String("${zoom}"), QString::number(zoom))
        .replace(QLatin1String("${x}"), QString::number(tileId.x))
        .replace(QLatin1String("${y}"), QString::number(tileId.y));
    const auto networkReply = Network::Downloader::download(tileUrl);

    // Free download slot
    {
        QMutexLocker scopedLocker(&_currentDownloadsCounterMutex);

        _currentDownloadsCounter--;
        _currentDownloadsCounterChanged.wakeAll();
    }

    // Ensure that all directories are created in path to local tile
    localFile.dir().mkpath(localFile.dir().absolutePath());

    // If there was error, check what the error was
    auto networkError = networkReply->error();
    if(networkError != QNetworkReply::NetworkError::NoError)
    {
        const auto httpStatus = networkReply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();

        LogPrintf(LogSeverityLevel::Warning, "Failed to download tile from %s (HTTP status %d)", qPrintable(tileUrl), httpStatus);

        // 404 means that this tile does not exist, so create a zero file
        if(httpStatus == 404)
        {
            // Save to a file
            QFile tileFile(localFile.absoluteFilePath());
            if(tileFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
            {
                tileFile.close();

                // Unlock the tile
                unlockTile(tileId, zoom);
                networkReply->deleteLater();
                return true;
            }
            else
            {
                LogPrintf(LogSeverityLevel::Error, "Failed to mark tile as non-existent with empty file '%s'", qPrintable(localFile.absoluteFilePath()));

                // Unlock the tile
                unlockTile(tileId, zoom);
                return false;
            }
        }

        // Unlock the tile
        unlockTile(tileId, zoom);
        return false;
    }

    // Save data to a file
#if OSMAND_DEBUG
    LogPrintf(LogSeverityLevel::Info, "Downloaded tile from %s", qPrintable(tileUrl));
#endif
    const auto& data = networkReply->readAll();

    // Save to a file
    QFile tileFile(localFile.absoluteFilePath());
    if(tileFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
    {
        tileFile.write(data);
        tileFile.close();

#if OSMAND_DEBUG
        LogPrintf(LogSeverityLevel::Info, "Saved tile from %s to %s", qPrintable(tileUrl), qPrintable(localFile.absoluteFilePath()));
#endif
    }
    else
        LogPrintf(LogSeverityLevel::Error, "Failed to save tile to '%s'", qPrintable(localFile.absoluteFilePath()));

    // Unlock tile, since local storage work is done
    unlockTile(tileId, zoom);

    // Decode in-memory
    auto bitmap = new SkBitmap();
    if(!SkImageDecoder::DecodeMemory(data.data(), data.size(), bitmap, SkBitmap::Config::kNo_Config, SkImageDecoder::kDecodePixels_Mode))
    {
        LogPrintf(LogSeverityLevel::Error, "Failed to decode tile file from '%s'", qPrintable(tileUrl));

        delete bitmap;

        return false;
    }

    assert(bitmap->width() == bitmap->height());
    assert(bitmap->width() == owner->providerTileSize);

    // Return tile
    auto tile = new MapBitmapTile(bitmap, owner->alphaChannelData);
    outTile.reset(tile);
    return true;
}
コード例 #9
0
void OsmAnd::OnlineMapRasterTileProvider_P::handleNetworkReply( QNetworkReply* reply, const std::shared_ptr<TileEntry>& tileEntry )
{
    tileEntry->localPath.dir().mkpath(tileEntry->localPath.dir().absolutePath());

    auto error = reply->error();
    if(error != QNetworkReply::NetworkError::NoError)
    {
        const auto httpStatus = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();

        LogPrintf(LogSeverityLevel::Warning, "Failed to download tile from %s (HTTP status %d)", qPrintable(reply->request().url().toString()), httpStatus);

        // 404 means that this tile does not exist, so create a zero file
        if(httpStatus == 404)
        {
            // Save to a file
            QFile tileFile(tileEntry->localPath.absoluteFilePath());
            if(tileFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
                tileFile.close();
            else
                LogPrintf(LogSeverityLevel::Error, "Failed to mark tile as non-existent with empty file '%s'", qPrintable(tileEntry->localPath.absoluteFilePath()));
        }

        _tiles.removeEntry(tileEntry);

        return;
    }

#if defined(_DEBUG) || defined(DEBUG)
    LogPrintf(LogSeverityLevel::Info, "Downloaded tile from %s", reply->request().url().toString().toStdString().c_str());
#endif
    const auto& data = reply->readAll();

    // Save to a file
    QFile tileFile(tileEntry->localPath.absoluteFilePath());
    if(tileFile.open(QIODevice::WriteOnly | QIODevice::Truncate))
    {
        tileFile.write(data);
        tileFile.close();

#if defined(_DEBUG) || defined(DEBUG)
        LogPrintf(LogSeverityLevel::Info, "Saved tile from %s to %s", qPrintable(reply->request().url().toString()), qPrintable(tileEntry->localPath.absoluteFilePath()));
#endif
    }
    else
        LogPrintf(LogSeverityLevel::Error, "Failed to save tile to '%s'", qPrintable(tileEntry->localPath.absoluteFilePath()));

    // Decode in-memory if we have receiver
    if(tileEntry->callback)
    {
        auto skBitmap = new SkBitmap();
        if(!SkImageDecoder::DecodeMemory(data.data(), data.size(), skBitmap, SkBitmap::Config::kNo_Config, SkImageDecoder::kDecodePixels_Mode))
        {
            LogPrintf(LogSeverityLevel::Error, "Failed to decode tile file from '%s'", reply->request().url().toString().toStdString().c_str());

            delete skBitmap;
            std::shared_ptr<IMapTileProvider::Tile> emptyTile;
            tileEntry->callback(tileEntry->tileId, tileEntry->zoom, emptyTile, false);

            _tiles.removeEntry(tileEntry);

            return;
        }

        assert(skBitmap->width() == skBitmap->height());
        assert(skBitmap->width() == owner->tileDimension);

        std::shared_ptr<OnlineMapRasterTileProvider::Tile> tile(new OnlineMapRasterTileProvider::Tile(skBitmap, owner->alphaChannelData));
        tileEntry->callback(tileEntry->tileId, tileEntry->zoom, tile, true);

        _tiles.removeEntry(tileEntry);
    }
}