summaryrefslogtreecommitdiff
path: root/src/mbgl/map/raster_tile_data.cpp
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-06-04 15:54:42 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-07-01 15:21:08 -0700
commit7e71145a89f0377736312c3b818a41ffb25bdf9a (patch)
tree5c898e3d0b973b382f1b6a176d2980a20691c13f /src/mbgl/map/raster_tile_data.cpp
parentee463785832343b60b2525126052d3ce65fea5a7 (diff)
downloadqtlocation-mapboxgl-7e71145a89f0377736312c3b818a41ffb25bdf9a.tar.gz
Make request and reparse pure virtual
Diffstat (limited to 'src/mbgl/map/raster_tile_data.cpp')
-rw-r--r--src/mbgl/map/raster_tile_data.cpp44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/mbgl/map/raster_tile_data.cpp b/src/mbgl/map/raster_tile_data.cpp
index 0f8efe3b48..ee53a6a288 100644
--- a/src/mbgl/map/raster_tile_data.cpp
+++ b/src/mbgl/map/raster_tile_data.cpp
@@ -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;