Merge remote-tracking branch 'remotes/origin/pr/127'
Conflicts: include/llmr/map/map.hpp src/map/map.cpp src/platform/platform.cpp
This commit is contained in:
@@ -11,11 +11,11 @@
|
||||
|
||||
using namespace llmr;
|
||||
|
||||
TileData::TileData(Tile::ID id, const Style& style, GlyphAtlas& glyphAtlas, const bool use_raster, const bool use_retina)
|
||||
TileData::TileData(Tile::ID id, const Style& style, GlyphAtlas& glyphAtlas, const std::string url, const bool is_raster)
|
||||
: id(id),
|
||||
use_raster(use_raster),
|
||||
use_retina(use_retina),
|
||||
url(url),
|
||||
state(State::initial),
|
||||
is_raster(is_raster),
|
||||
raster(),
|
||||
style(style),
|
||||
glyphAtlas(glyphAtlas) {
|
||||
@@ -38,17 +38,9 @@ const std::string TileData::toString() const {
|
||||
void TileData::request() {
|
||||
state = State::loading;
|
||||
|
||||
std::string url;
|
||||
|
||||
if (use_raster) {
|
||||
url = util::sprintf(kTileRasterURL, id.z, id.x, id.y, (use_retina ? "@2x" : ""));
|
||||
} else {
|
||||
url = util::sprintf(kTileVectorURL, id.z, id.x, id.y);
|
||||
}
|
||||
|
||||
// Note: Somehow this feels slower than the change to request_http()
|
||||
std::weak_ptr<TileData> weak_tile = shared_from_this();
|
||||
req = platform::request_http(url, [weak_tile, url](platform::Response *res) {
|
||||
req = platform::request_http(url, [weak_tile](platform::Response *res) {
|
||||
std::shared_ptr<TileData> tile = weak_tile.lock();
|
||||
if (!tile || tile->state == State::obsolete) {
|
||||
// noop. Tile is obsolete and we're now just waiting for the refcount
|
||||
@@ -58,7 +50,7 @@ void TileData::request() {
|
||||
tile->data.swap(res->body);
|
||||
tile->parse();
|
||||
} else {
|
||||
fprintf(stderr, "[%s] tile loading failed: %d, %s\n", url.c_str(), res->code, res->error_message.c_str());
|
||||
fprintf(stderr, "[%s] tile loading failed: %d, %s\n", tile->url.c_str(), res->code, res->error_message.c_str());
|
||||
}
|
||||
}, []() {
|
||||
platform::restart();
|
||||
@@ -77,18 +69,11 @@ bool TileData::parse() {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (use_raster) {
|
||||
raster = std::make_shared<Raster>();
|
||||
raster->load(data);
|
||||
state = State::parsed;
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
// Parsing creates state that is encapsulated in TileParser. While parsing,
|
||||
// the TileParser object writes results into this objects. All other state
|
||||
// is going to be discarded afterwards.
|
||||
TileParser parser(data, *this, style, glyphAtlas);
|
||||
TileParser parser(data, *this, style, glyphAtlas, is_raster);
|
||||
} catch (const std::exception& ex) {
|
||||
fprintf(stderr, "[%p] exception [%d/%d/%d]... failed: %s\n", this, id.z, id.x, id.y, ex.what());
|
||||
cancel();
|
||||
|
||||
Reference in New Issue
Block a user