Make request and reparse pure virtual

This commit is contained in:
John Firebaugh
2015-06-04 15:54:42 -07:00
parent ee46378583
commit 7e71145a89
6 changed files with 101 additions and 51 deletions

View File

@@ -7,6 +7,9 @@
#include <mbgl/platform/log.hpp>
#include <mbgl/text/collision_tile.hpp>
#include <mbgl/util/pbf.hpp>
#include <mbgl/storage/resource.hpp>
#include <mbgl/storage/response.hpp>
#include <mbgl/storage/file_source.hpp>
#include <mbgl/util/worker.hpp>
#include <mbgl/util/work_request.hpp>
#include <mbgl/style/style.hpp>
@@ -32,6 +35,41 @@ VectorTileData::~VectorTileData() {
style.glyphAtlas->removeGlyphs(reinterpret_cast<uintptr_t>(this));
}
void VectorTileData::request(Worker& worker,
float pixelRatio,
const std::function<void()>& callback) {
std::string url = source.tileURL(id, pixelRatio);
state = State::loading;
FileSource* fs = util::ThreadContext::getFileSource();
req = fs->request({ Resource::Kind::Tile, url }, util::RunLoop::current.get()->get(), [url, callback, &worker, this](const Response &res) {
req = nullptr;
if (res.status != Response::Successful) {
std::stringstream message;
message << "Failed to load [" << url << "]: " << res.message;
setError(message.str());
callback();
return;
}
state = State::loaded;
data = res.data;
// Schedule tile parsing in another thread
reparse(worker, callback);
});
}
bool VectorTileData::reparse(Worker& worker, std::function<void()> callback) {
if (!mayStartParsing()) {
return false;
}
workRequest = worker.send([this] { parse(); endParsing(); }, callback);
return true;
}
void VectorTileData::parse() {
if (getState() != State::loaded && getState() != State::partial) {
return;