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

@@ -1,5 +1,12 @@
#include <mbgl/map/raster_tile_data.hpp>
#include <mbgl/style/style.hpp>
#include <mbgl/map/source.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 <sstream>
using namespace mbgl;
@@ -14,6 +21,41 @@ RasterTileData::~RasterTileData() {
cancel();
}
void RasterTileData::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 RasterTileData::reparse(Worker& worker, std::function<void()> callback) {
if (!mayStartParsing()) {
return false;
}
workRequest = worker.send([this] { parse(); endParsing(); }, callback);
return true;
}
void RasterTileData::parse() {
if (getState() != State::loaded) {
return;