[core] remove SourceInfo dependency from *TileData
This commit is contained in:
committed by
John Firebaugh
parent
aac6b00dd0
commit
1ff317c1cd
@@ -10,11 +10,9 @@ using namespace mbgl;
|
||||
|
||||
RasterTileData::RasterTileData(const TileID& id_,
|
||||
TexturePool &texturePool_,
|
||||
const SourceInfo &source_,
|
||||
Worker& worker_)
|
||||
: TileData(id_),
|
||||
texturePool(texturePool_),
|
||||
source(source_),
|
||||
worker(worker_) {
|
||||
}
|
||||
|
||||
@@ -22,9 +20,8 @@ RasterTileData::~RasterTileData() {
|
||||
cancel();
|
||||
}
|
||||
|
||||
void RasterTileData::request(float pixelRatio,
|
||||
void RasterTileData::request(const std::string& url,
|
||||
const RasterTileData::Callback& callback) {
|
||||
std::string url = source.tileURL(id, pixelRatio);
|
||||
state = State::loading;
|
||||
|
||||
FileSource* fs = util::ThreadContext::getFileSource();
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class SourceInfo;
|
||||
class FileRequest;
|
||||
class StyleLayer;
|
||||
class TexturePool;
|
||||
@@ -14,12 +13,12 @@ class WorkRequest;
|
||||
|
||||
class RasterTileData : public TileData {
|
||||
public:
|
||||
RasterTileData(const TileID&, TexturePool&, const SourceInfo&, Worker&);
|
||||
RasterTileData(const TileID&, TexturePool&, Worker&);
|
||||
~RasterTileData();
|
||||
|
||||
using Callback = std::function<void()>;
|
||||
|
||||
void request(float pixelRatio,
|
||||
void request(const std::string& url,
|
||||
const Callback& callback);
|
||||
|
||||
void cancel() override;
|
||||
@@ -28,7 +27,6 @@ public:
|
||||
|
||||
private:
|
||||
TexturePool& texturePool;
|
||||
const SourceInfo& source;
|
||||
Worker& worker;
|
||||
std::unique_ptr<FileRequest> req;
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <mbgl/util/token.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
#include <mbgl/util/tile_cover.hpp>
|
||||
#include <mbgl/util/url.hpp>
|
||||
|
||||
#include <mbgl/map/vector_tile_data.hpp>
|
||||
#include <mbgl/map/raster_tile_data.hpp>
|
||||
@@ -307,16 +308,15 @@ TileData::State Source::addTile(const TileID& id, const StyleUpdateParameters& p
|
||||
if (info.type == SourceType::Raster) {
|
||||
auto tileData = std::make_shared<RasterTileData>(normalized_id,
|
||||
parameters.texturePool,
|
||||
info,
|
||||
parameters.worker);
|
||||
|
||||
tileData->request(parameters.pixelRatio, callback);
|
||||
tileData->request(util::templateTileURL(info.tiles.at(0), normalized_id, parameters.pixelRatio), callback);
|
||||
newTile->data = tileData;
|
||||
} else {
|
||||
std::unique_ptr<GeometryTileMonitor> monitor;
|
||||
|
||||
if (info.type == SourceType::Vector) {
|
||||
monitor = std::make_unique<VectorTileMonitor>(info, normalized_id, parameters.pixelRatio);
|
||||
monitor = std::make_unique<VectorTileMonitor>(normalized_id, info.tiles.at(0));
|
||||
} else if (info.type == SourceType::Annotations) {
|
||||
monitor = std::make_unique<AnnotationTileMonitor>(normalized_id, parameters.data);
|
||||
} else if (info.type == SourceType::GeoJSON) {
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
#include <mbgl/map/source_info.hpp>
|
||||
#include <mbgl/map/tile_id.hpp>
|
||||
#include <mbgl/util/mapbox.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
#include <mbgl/util/token.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
std::string SourceInfo::tileURL(const TileID& id, float pixelRatio) const {
|
||||
std::string result = tiles.at(0);
|
||||
result = util::mapbox::normalizeTileURL(result, url, type);
|
||||
result = util::replaceTokens(result, [&](const std::string& token) -> std::string {
|
||||
if (token == "z") {
|
||||
return util::toString(std::min(id.z, static_cast<int8_t>(max_zoom)));
|
||||
} else if (token == "x") {
|
||||
return util::toString(id.x);
|
||||
} else if (token == "y") {
|
||||
return util::toString(id.y);
|
||||
} else if (token == "prefix") {
|
||||
std::string prefix{ 2 };
|
||||
prefix[0] = "0123456789abcdef"[id.x % 16];
|
||||
prefix[1] = "0123456789abcdef"[id.y % 16];
|
||||
return prefix;
|
||||
} else if (token == "ratio") {
|
||||
return pixelRatio > 1.0 ? "@2x" : "";
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace mbgl
|
||||
@@ -25,8 +25,6 @@ public:
|
||||
std::array<float, 3> center = { { 0, 0, 0 } };
|
||||
std::array<float, 4> bounds = { { -180, -90, 180, 90 } };
|
||||
std::string source_id = "";
|
||||
|
||||
std::string tileURL(const TileID&, float pixelRatio) const;
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <mbgl/storage/response.hpp>
|
||||
#include <mbgl/storage/file_source.hpp>
|
||||
#include <mbgl/util/thread_context.hpp>
|
||||
#include <mbgl/util/url.hpp>
|
||||
|
||||
#include <utility>
|
||||
|
||||
@@ -177,11 +178,12 @@ util::ptr<const GeometryTileFeature> VectorTileLayer::getFeature(std::size_t i)
|
||||
return std::make_shared<VectorTileFeature>(features.at(i), *this);
|
||||
}
|
||||
|
||||
VectorTileMonitor::VectorTileMonitor(const SourceInfo& source, const TileID& id, float pixelRatio)
|
||||
: url(source.tileURL(id, pixelRatio)) {
|
||||
VectorTileMonitor::VectorTileMonitor(const TileID& tileID_, const std::string& urlTemplate_)
|
||||
: tileID(tileID_), urlTemplate(urlTemplate_) {
|
||||
}
|
||||
|
||||
std::unique_ptr<FileRequest> VectorTileMonitor::monitorTile(const GeometryTileMonitor::Callback& callback) {
|
||||
const std::string url = util::templateTileURL(urlTemplate, tileID);
|
||||
return util::ThreadContext::getFileSource()->request({ Resource::Kind::Tile, url }, [callback, this](Response res) {
|
||||
if (res.data && data == res.data) {
|
||||
// We got the same data again. Abort early.
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define MBGL_MAP_VECTOR_TILE
|
||||
|
||||
#include <mbgl/map/geometry_tile.hpp>
|
||||
#include <mbgl/map/tile_id.hpp>
|
||||
#include <mbgl/util/pbf.hpp>
|
||||
|
||||
#include <map>
|
||||
@@ -56,17 +57,17 @@ private:
|
||||
mutable std::map<std::string, util::ptr<GeometryTileLayer>> layers;
|
||||
};
|
||||
|
||||
class SourceInfo;
|
||||
class TileID;
|
||||
|
||||
class VectorTileMonitor : public GeometryTileMonitor {
|
||||
public:
|
||||
VectorTileMonitor(const SourceInfo&, const TileID&, float pixelRatio);
|
||||
VectorTileMonitor(const TileID&, const std::string& urlTemplate);
|
||||
|
||||
std::unique_ptr<FileRequest> monitorTile(const GeometryTileMonitor::Callback&) override;
|
||||
|
||||
private:
|
||||
std::string url;
|
||||
TileID tileID;
|
||||
std::string urlTemplate;
|
||||
std::shared_ptr<const std::string> data;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
#include <mbgl/util/url.hpp>
|
||||
#include <mbgl/util/token.hpp>
|
||||
#include <mbgl/util/string.hpp>
|
||||
#include <mbgl/map/tile_id.hpp>
|
||||
|
||||
#include <cctype>
|
||||
#include <iomanip>
|
||||
@@ -47,6 +50,27 @@ std::string percentDecode(const std::string& input) {
|
||||
return decoded;
|
||||
}
|
||||
|
||||
std::string templateTileURL(const std::string& url, const TileID& id, float pixelRatio) {
|
||||
return util::replaceTokens(url, [&](const std::string& token) -> std::string {
|
||||
if (token == "z") {
|
||||
return util::toString(id.sourceZ);
|
||||
} else if (token == "x") {
|
||||
return util::toString(id.x);
|
||||
} else if (token == "y") {
|
||||
return util::toString(id.y);
|
||||
} else if (token == "prefix") {
|
||||
std::string prefix{ 2 };
|
||||
prefix[0] = "0123456789abcdef"[id.x % 16];
|
||||
prefix[1] = "0123456789abcdef"[id.y % 16];
|
||||
return prefix;
|
||||
} else if (token == "ratio") {
|
||||
return pixelRatio > 1.0 ? "@2x" : "";
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
namespace {
|
||||
const std::string assetProtocol = "asset://";
|
||||
}
|
||||
|
||||
@@ -4,11 +4,16 @@
|
||||
#include <string>
|
||||
|
||||
namespace mbgl {
|
||||
|
||||
class TileID;
|
||||
|
||||
namespace util {
|
||||
|
||||
std::string percentEncode(const std::string&);
|
||||
std::string percentDecode(const std::string&);
|
||||
|
||||
std::string templateTileURL(const std::string& url, const TileID& id, float pixelRatio = 1);
|
||||
|
||||
bool isAssetURL(const std::string&);
|
||||
|
||||
} // namespace util
|
||||
|
||||
Reference in New Issue
Block a user