Code Monkey home page Code Monkey logo

Comments (1)

raptorswing avatar raptorswing commented on August 11, 2024

Hi. Sorry for the slow response. It is possible, but might require a bit of effort. The code supports different "Tile Source" implementations. These can have their own implementations for loading tiles (e.g. HTTP requests, drawing on the fly, or loading from disk). There isn't one built-in for loading from disk, but the base class that they all inherit from does have the ability to store downloaded/rendered tiles to a disk cache and then load from there instead of hitting the network or rendering the tiles again.

See, for example, parts of the caching implementation in MapTileSource:

QImage *MapTileSource::fromDiskCache(const QString &cacheID)
{
//Figure out x,y,z based on the cacheID
quint32 x,y,z;
if (!MapTileSource::cacheID2xyz(cacheID,&x,&y,&z))
return 0;
//See if we've got it in the cache
const QString path = this->getDiskCacheFile(x,y,z);
QFile fp(path);
if (!fp.exists())
return 0;
//Figure out when the tile we're loading from cache was supposed to expire
QDateTime expireTime = this->getTileExpirationTime(cacheID);
//If the cached tile is older than we would like, throw it out
if (QDateTime::currentDateTimeUtc().secsTo(expireTime) <= 0)
{
if (!QFile::remove(path))
qWarning() << "Failed to remove old cache file" << path;
return 0;
}
if (!fp.open(QFile::ReadOnly))
{
qWarning() << "Failed to open" << QFileInfo(fp.fileName()).baseName() << "from cache";
return 0;
}
QByteArray data;
quint64 counter = 0;
while (data.length() < fp.size())
{
data += fp.read(20480);
if (++counter >= MAX_DISK_CACHE_READ_ATTEMPTS)
{
qWarning() << "Reading cache file" << fp.fileName() << "took too long. Aborting.";
return 0;
}
}
QImage * image = new QImage();
if (!image->loadFromData(data))
{
delete image;
return 0;
}
return image;
}

You could conceivably implement a tile source that reuses this caching functionality, or maybe do something else. In either case, you'll probably want to implement a child class of MapTileSource.

from mapgraphics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.