summaryrefslogtreecommitdiff
path: root/src/mbgl/style
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/style')
-rw-r--r--src/mbgl/style/parser.cpp12
-rw-r--r--src/mbgl/style/source_impl.cpp (renamed from src/mbgl/style/source.cpp)43
-rw-r--r--src/mbgl/style/source_impl.hpp (renamed from src/mbgl/style/source.hpp)9
-rw-r--r--src/mbgl/style/sources/geojson_source_impl.cpp (renamed from src/mbgl/style/sources/geojson_source.cpp)36
-rw-r--r--src/mbgl/style/sources/geojson_source_impl.hpp (renamed from src/mbgl/style/sources/geojson_source.hpp)10
-rw-r--r--src/mbgl/style/sources/raster_source_impl.cpp (renamed from src/mbgl/style/sources/raster_source.cpp)16
-rw-r--r--src/mbgl/style/sources/raster_source_impl.hpp (renamed from src/mbgl/style/sources/raster_source.hpp)7
-rw-r--r--src/mbgl/style/sources/vector_source.cpp25
-rw-r--r--src/mbgl/style/sources/vector_source_impl.cpp25
-rw-r--r--src/mbgl/style/sources/vector_source_impl.hpp (renamed from src/mbgl/style/sources/vector_source.hpp)7
-rw-r--r--src/mbgl/style/style.cpp36
-rw-r--r--src/mbgl/style/tile_source_impl.cpp (renamed from src/mbgl/style/tile_source.cpp)29
-rw-r--r--src/mbgl/style/tile_source_impl.hpp (renamed from src/mbgl/style/tile_source.hpp)13
13 files changed, 139 insertions, 129 deletions
diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp
index 09689f22f1..34f01c14c1 100644
--- a/src/mbgl/style/parser.cpp
+++ b/src/mbgl/style/parser.cpp
@@ -1,7 +1,7 @@
#include <mbgl/style/parser.hpp>
-#include <mbgl/style/sources/raster_source.hpp>
-#include <mbgl/style/sources/vector_source.hpp>
-#include <mbgl/style/sources/geojson_source.hpp>
+#include <mbgl/style/sources/raster_source_impl.hpp>
+#include <mbgl/style/sources/vector_source_impl.hpp>
+#include <mbgl/style/sources/geojson_source_impl.hpp>
#include <mbgl/style/layer_impl.hpp>
#include <mbgl/style/layers/fill_layer.hpp>
#include <mbgl/style/layers/line_layer.hpp>
@@ -99,16 +99,16 @@ void Parser::parseSources(const JSValue& value) {
switch (*type) {
case SourceType::Raster: {
- source = RasterSource::parse(id, sourceVal);
+ source = RasterSource::Impl::parse(id, sourceVal);
break;
}
case SourceType::Vector:
- source = VectorSource::parse(id, sourceVal);
+ source = VectorSource::Impl::parse(id, sourceVal);
break;
case SourceType::GeoJSON:
- source = GeoJSONSource::parse(id, sourceVal);
+ source = GeoJSONSource::Impl::parse(id, sourceVal);
break;
default:
diff --git a/src/mbgl/style/source.cpp b/src/mbgl/style/source_impl.cpp
index 5f4949c94c..4223f2b50d 100644
--- a/src/mbgl/style/source.cpp
+++ b/src/mbgl/style/source_impl.cpp
@@ -1,4 +1,4 @@
-#include <mbgl/style/source.hpp>
+#include <mbgl/style/source_impl.hpp>
#include <mbgl/style/source_observer.hpp>
#include <mbgl/map/transform.hpp>
#include <mbgl/renderer/render_tile.hpp>
@@ -23,15 +23,16 @@ namespace style {
static SourceObserver nullObserver;
-Source::Source(SourceType type_, std::string id_)
+Source::Impl::Impl(SourceType type_, std::string id_, Source& base_)
: type(type_),
id(std::move(id_)),
+ base(base_),
observer(&nullObserver) {
}
-Source::~Source() = default;
+Source::Impl::~Impl() = default;
-bool Source::isLoaded() const {
+bool Source::Impl::isLoaded() const {
if (!loaded) return false;
for (const auto& pair : tiles) {
@@ -43,13 +44,13 @@ bool Source::isLoaded() const {
return true;
}
-void Source::invalidateTiles() {
+void Source::Impl::invalidateTiles() {
tiles.clear();
renderTiles.clear();
cache.clear();
}
-void Source::startRender(algorithm::ClipIDGenerator& generator,
+void Source::Impl::startRender(algorithm::ClipIDGenerator& generator,
const mat4& projMatrix,
const TransformState& transform) {
if (type == SourceType::Vector ||
@@ -65,18 +66,18 @@ void Source::startRender(algorithm::ClipIDGenerator& generator,
}
}
-void Source::finishRender(Painter& painter) {
+void Source::Impl::finishRender(Painter& painter) {
for (auto& pair : renderTiles) {
auto& tile = pair.second;
painter.renderTileDebug(tile);
}
}
-const std::map<UnwrappedTileID, RenderTile>& Source::getRenderTiles() const {
+const std::map<UnwrappedTileID, RenderTile>& Source::Impl::getRenderTiles() const {
return renderTiles;
}
-Tile* Source::getTile(const OverscaledTileID& overscaledTileID) const {
+Tile* Source::Impl::getTile(const OverscaledTileID& overscaledTileID) const {
auto it = tiles.find(overscaledTileID);
if (it != tiles.end()) {
return it->second.get();
@@ -85,7 +86,7 @@ Tile* Source::getTile(const OverscaledTileID& overscaledTileID) const {
}
}
-bool Source::update(const UpdateParameters& parameters) {
+bool Source::Impl::update(const UpdateParameters& parameters) {
bool allTilesUpdated = true;
if (!loaded || parameters.animationTime <= updated) {
@@ -205,7 +206,7 @@ static Point<int16_t> coordinateToTilePoint(const UnwrappedTileID& tileID, const
};
}
-std::unordered_map<std::string, std::vector<Feature>> Source::queryRenderedFeatures(const QueryParameters& parameters) const {
+std::unordered_map<std::string, std::vector<Feature>> Source::Impl::queryRenderedFeatures(const QueryParameters& parameters) const {
LineString<double> queryGeometry;
for (const auto& p : parameters.geometry) {
@@ -241,32 +242,32 @@ std::unordered_map<std::string, std::vector<Feature>> Source::queryRenderedFeatu
return result;
}
-void Source::setCacheSize(size_t size) {
+void Source::Impl::setCacheSize(size_t size) {
cache.setSize(size);
}
-void Source::onLowMemory() {
+void Source::Impl::onLowMemory() {
cache.clear();
}
-void Source::setObserver(SourceObserver* observer_) {
+void Source::Impl::setObserver(SourceObserver* observer_) {
observer = observer_;
}
-void Source::onTileLoaded(Tile& tile, bool isNewTile) {
- observer->onTileLoaded(*this, tile.id, isNewTile);
+void Source::Impl::onTileLoaded(Tile& tile, bool isNewTile) {
+ observer->onTileLoaded(base, tile.id, isNewTile);
}
-void Source::onTileError(Tile& tile, std::exception_ptr error) {
- observer->onTileError(*this, tile.id, error);
+void Source::Impl::onTileError(Tile& tile, std::exception_ptr error) {
+ observer->onTileError(base, tile.id, error);
}
-void Source::onNeedsRepaint() {
+void Source::Impl::onNeedsRepaint() {
observer->onNeedsRepaint();
}
-void Source::dumpDebugLogs() const {
- Log::Info(Event::General, "Source::id: %s", id.c_str());
+void Source::Impl::dumpDebugLogs() const {
+ Log::Info(Event::General, "Source::id: %s", base.getID().c_str());
Log::Info(Event::General, "Source::loaded: %d", loaded);
for (const auto& pair : tiles) {
diff --git a/src/mbgl/style/source.hpp b/src/mbgl/style/source_impl.hpp
index 5c1a813562..64651d7e3f 100644
--- a/src/mbgl/style/source.hpp
+++ b/src/mbgl/style/source_impl.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include <mbgl/style/source.hpp>
+
#include <mbgl/tile/tile_id.hpp>
#include <mbgl/tile/tile_observer.hpp>
#include <mbgl/tile/tile.hpp>
@@ -33,10 +35,10 @@ class UpdateParameters;
class QueryParameters;
class SourceObserver;
-class Source : public TileObserver, private util::noncopyable {
+class Source::Impl : public TileObserver, private util::noncopyable {
public:
- Source(SourceType, std::string id);
- ~Source() override;
+ Impl(SourceType, std::string id, Source&);
+ ~Impl() override;
virtual void load(FileSource&) = 0;
bool isLoaded() const;
@@ -74,6 +76,7 @@ public:
protected:
void invalidateTiles();
+ Source& base;
SourceObserver* observer = nullptr;
private:
diff --git a/src/mbgl/style/sources/geojson_source.cpp b/src/mbgl/style/sources/geojson_source_impl.cpp
index e06b00ec99..f58e0fc62b 100644
--- a/src/mbgl/style/sources/geojson_source.cpp
+++ b/src/mbgl/style/sources/geojson_source_impl.cpp
@@ -1,4 +1,4 @@
-#include <mbgl/style/sources/geojson_source.hpp>
+#include <mbgl/style/sources/geojson_source_impl.hpp>
#include <mbgl/style/source_observer.hpp>
#include <mbgl/style/parser.hpp>
#include <mbgl/tile/geojson_tile.hpp>
@@ -15,7 +15,7 @@
namespace mbgl {
namespace style {
-std::unique_ptr<mapbox::geojsonvt::GeoJSONVT> GeoJSONSource::parseGeoJSON(const JSValue& value) {
+std::unique_ptr<mapbox::geojsonvt::GeoJSONVT> GeoJSONSource::Impl::parseGeoJSON(const JSValue& value) {
using namespace mapbox::geojsonvt;
Options options;
@@ -32,7 +32,7 @@ std::unique_ptr<mapbox::geojsonvt::GeoJSONVT> GeoJSONSource::parseGeoJSON(const
}
}
-std::unique_ptr<GeoJSONSource> GeoJSONSource::parse(const std::string& id, const JSValue& value) {
+std::unique_ptr<GeoJSONSource> GeoJSONSource::Impl::parse(const std::string& id, const JSValue& value) {
// We should probably split this up to have URLs in the url property, and actual data
// in the data property. Until then, we're going to detect the content based on the
// object type.
@@ -43,23 +43,27 @@ std::unique_ptr<GeoJSONSource> GeoJSONSource::parse(const std::string& id, const
const JSValue& dataVal = value["data"];
if (dataVal.IsString()) {
- return std::make_unique<GeoJSONSource>(id, std::string(dataVal.GetString(), dataVal.GetStringLength()));
+ return std::make_unique<GeoJSONSource>([&] (Source& base) {
+ return std::make_unique<Impl>(id, base, std::string(dataVal.GetString(), dataVal.GetStringLength()));
+ });
} else if (dataVal.IsObject()) {
- return std::make_unique<GeoJSONSource>(id, parseGeoJSON(dataVal));
+ return std::make_unique<GeoJSONSource>([&] (Source& base) {
+ return std::make_unique<Impl>(id, base, parseGeoJSON(dataVal));
+ });
} else {
Log::Error(Event::ParseStyle, "GeoJSON data must be a URL or an object");
return nullptr;
}
}
-GeoJSONSource::GeoJSONSource(std::string id_, variant<std::string, GeoJSON> urlOrGeoJSON_)
- : Source(SourceType::GeoJSON, std::move(id_)),
+GeoJSONSource::Impl::Impl(std::string id_, Source& base_, variant<std::string, GeoJSON> urlOrGeoJSON_)
+ : Source::Impl(SourceType::GeoJSON, std::move(id_), base_),
urlOrGeoJSON(std::move(urlOrGeoJSON_)) {
}
-GeoJSONSource::~GeoJSONSource() = default;
+GeoJSONSource::Impl::~Impl() = default;
-void GeoJSONSource::load(FileSource& fileSource) {
+void GeoJSONSource::Impl::load(FileSource& fileSource) {
if (urlOrGeoJSON.is<GeoJSON>()) {
loaded = true;
return;
@@ -72,11 +76,11 @@ void GeoJSONSource::load(FileSource& fileSource) {
const std::string& url = urlOrGeoJSON.get<std::string>();
req = fileSource.request(Resource::source(url), [this](Response res) {
if (res.error) {
- observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error(res.error->message)));
+ observer->onSourceError(base, std::make_exception_ptr(std::runtime_error(res.error->message)));
} else if (res.notModified) {
return;
} else if (res.noContent) {
- observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error("unexpectedly empty GeoJSON")));
+ observer->onSourceError(base, std::make_exception_ptr(std::runtime_error("unexpectedly empty GeoJSON")));
} else {
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> d;
d.Parse<0>(res.data->c_str());
@@ -84,7 +88,7 @@ void GeoJSONSource::load(FileSource& fileSource) {
if (d.HasParseError()) {
std::stringstream message;
message << d.GetErrorOffset() << " - " << rapidjson::GetParseError_En(d.GetParseError());
- observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error(message.str())));
+ observer->onSourceError(base, std::make_exception_ptr(std::runtime_error(message.str())));
return;
}
@@ -93,20 +97,20 @@ void GeoJSONSource::load(FileSource& fileSource) {
urlOrGeoJSON = parseGeoJSON(d);
loaded = true;
- observer->onSourceLoaded(*this);
+ observer->onSourceLoaded(base);
}
});
}
-Range<uint8_t> GeoJSONSource::getZoomRange() {
+Range<uint8_t> GeoJSONSource::Impl::getZoomRange() {
assert(loaded);
return { 0, urlOrGeoJSON.get<GeoJSON>()->options.maxZoom };
}
-std::unique_ptr<Tile> GeoJSONSource::createTile(const OverscaledTileID& tileID,
+std::unique_ptr<Tile> GeoJSONSource::Impl::createTile(const OverscaledTileID& tileID,
const UpdateParameters& parameters) {
assert(loaded);
- return std::make_unique<GeoJSONTile>(tileID, id, parameters, *urlOrGeoJSON.get<GeoJSON>());
+ return std::make_unique<GeoJSONTile>(tileID, base.getID(), parameters, *urlOrGeoJSON.get<GeoJSON>());
}
} // namespace style
diff --git a/src/mbgl/style/sources/geojson_source.hpp b/src/mbgl/style/sources/geojson_source_impl.hpp
index 490dae48b8..350045b27c 100644
--- a/src/mbgl/style/sources/geojson_source.hpp
+++ b/src/mbgl/style/sources/geojson_source_impl.hpp
@@ -1,6 +1,7 @@
#pragma once
-#include <mbgl/style/source.hpp>
+#include <mbgl/style/sources/geojson_source.hpp>
+#include <mbgl/style/source_impl.hpp>
#include <mbgl/util/rapidjson.hpp>
#include <mbgl/util/variant.hpp>
@@ -16,15 +17,16 @@ class AsyncRequest;
namespace style {
-class GeoJSONSource : public Source {
+class GeoJSONSource::Impl : public Source::Impl {
public:
using GeoJSON = std::unique_ptr<mapbox::geojsonvt::GeoJSONVT>;
static std::unique_ptr<GeoJSONSource> parse(const std::string& id, const JSValue&);
static GeoJSON parseGeoJSON(const JSValue&);
- GeoJSONSource(std::string id, variant<std::string, GeoJSON> urlOrGeoJSON);
- ~GeoJSONSource() final;
+ Impl(std::string id, Source&,
+ variant<std::string, GeoJSON> urlOrGeoJSON);
+ ~Impl() final;
void load(FileSource&) final;
diff --git a/src/mbgl/style/sources/raster_source.cpp b/src/mbgl/style/sources/raster_source_impl.cpp
index 9f873a3065..a6e19b4757 100644
--- a/src/mbgl/style/sources/raster_source.cpp
+++ b/src/mbgl/style/sources/raster_source_impl.cpp
@@ -1,12 +1,12 @@
-#include <mbgl/style/sources/raster_source.hpp>
+#include <mbgl/style/sources/raster_source_impl.hpp>
#include <mbgl/tile/raster_tile.hpp>
#include <mbgl/platform/log.hpp>
namespace mbgl {
namespace style {
-std::unique_ptr<RasterSource> RasterSource::parse(std::string id, const JSValue& value) {
- optional<variant<std::string, Tileset>> urlOrTileset = TileSource::parseURLOrTileset(value);
+std::unique_ptr<RasterSource> RasterSource::Impl::parse(std::string id, const JSValue& value) {
+ optional<variant<std::string, Tileset>> urlOrTileset = TileSourceImpl::parseURLOrTileset(value);
if (!urlOrTileset) {
return nullptr;
}
@@ -25,13 +25,13 @@ std::unique_ptr<RasterSource> RasterSource::parse(std::string id, const JSValue&
return std::make_unique<RasterSource>(std::move(id), std::move(*urlOrTileset), tileSize);
}
-RasterSource::RasterSource(std::string id_,
- variant<std::string, Tileset> urlOrTileset_,
- uint16_t tileSize_)
- : TileSource(SourceType::Raster, std::move(id_), std::move(urlOrTileset_), tileSize_) {
+RasterSource::Impl::Impl(std::string id_, Source& base_,
+ variant<std::string, Tileset> urlOrTileset_,
+ uint16_t tileSize_)
+ : TileSourceImpl(SourceType::Raster, std::move(id_), base_, std::move(urlOrTileset_), tileSize_) {
}
-std::unique_ptr<Tile> RasterSource::createTile(const OverscaledTileID& tileID,
+std::unique_ptr<Tile> RasterSource::Impl::createTile(const OverscaledTileID& tileID,
const UpdateParameters& parameters) {
return std::make_unique<RasterTile>(tileID, parameters, tileset);
}
diff --git a/src/mbgl/style/sources/raster_source.hpp b/src/mbgl/style/sources/raster_source_impl.hpp
index 27b2276df5..2222b13082 100644
--- a/src/mbgl/style/sources/raster_source.hpp
+++ b/src/mbgl/style/sources/raster_source_impl.hpp
@@ -1,15 +1,16 @@
#pragma once
-#include <mbgl/style/tile_source.hpp>
+#include <mbgl/style/sources/raster_source.hpp>
+#include <mbgl/style/tile_source_impl.hpp>
namespace mbgl {
namespace style {
-class RasterSource : public TileSource {
+class RasterSource::Impl : public TileSourceImpl {
public:
static std::unique_ptr<RasterSource> parse(std::string id, const JSValue&);
- RasterSource(std::string id, variant<std::string, Tileset>, uint16_t tileSize);
+ Impl(std::string id, Source&, variant<std::string, Tileset>, uint16_t tileSize);
private:
std::unique_ptr<Tile> createTile(const OverscaledTileID&, const UpdateParameters&) final;
diff --git a/src/mbgl/style/sources/vector_source.cpp b/src/mbgl/style/sources/vector_source.cpp
deleted file mode 100644
index 3f8f840b38..0000000000
--- a/src/mbgl/style/sources/vector_source.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#include <mbgl/style/sources/vector_source.hpp>
-#include <mbgl/tile/vector_tile.hpp>
-
-namespace mbgl {
-namespace style {
-
-std::unique_ptr<VectorSource> VectorSource::parse(std::string id, const JSValue& value) {
- optional<variant<std::string, Tileset>> urlOrTileset = TileSource::parseURLOrTileset(value);
- if (!urlOrTileset) {
- return nullptr;
- }
- return std::make_unique<VectorSource>(std::move(id), std::move(*urlOrTileset));
-}
-
-VectorSource::VectorSource(std::string id_, variant<std::string, Tileset> urlOrTileset_)
- : TileSource(SourceType::Vector, std::move(id_), std::move(urlOrTileset_), util::tileSize) {
-}
-
-std::unique_ptr<Tile> VectorSource::createTile(const OverscaledTileID& tileID,
- const UpdateParameters& parameters) {
- return std::make_unique<VectorTile>(tileID, id, parameters, tileset);
-}
-
-} // namespace style
-} // namespace mbgl
diff --git a/src/mbgl/style/sources/vector_source_impl.cpp b/src/mbgl/style/sources/vector_source_impl.cpp
new file mode 100644
index 0000000000..28e14f3e16
--- /dev/null
+++ b/src/mbgl/style/sources/vector_source_impl.cpp
@@ -0,0 +1,25 @@
+#include <mbgl/style/sources/vector_source_impl.hpp>
+#include <mbgl/tile/vector_tile.hpp>
+
+namespace mbgl {
+namespace style {
+
+std::unique_ptr<VectorSource> VectorSource::Impl::parse(std::string id, const JSValue& value) {
+ optional<variant<std::string, Tileset>> urlOrTileset = TileSourceImpl::parseURLOrTileset(value);
+ if (!urlOrTileset) {
+ return nullptr;
+ }
+ return std::make_unique<VectorSource>(std::move(id), std::move(*urlOrTileset));
+}
+
+VectorSource::Impl::Impl(std::string id_, Source& base_, variant<std::string, Tileset> urlOrTileset_)
+ : TileSourceImpl(SourceType::Vector, std::move(id_), base_, std::move(urlOrTileset_), util::tileSize) {
+}
+
+std::unique_ptr<Tile> VectorSource::Impl::createTile(const OverscaledTileID& tileID,
+ const UpdateParameters& parameters) {
+ return std::make_unique<VectorTile>(tileID, base.getID(), parameters, tileset);
+}
+
+} // namespace style
+} // namespace mbgl
diff --git a/src/mbgl/style/sources/vector_source.hpp b/src/mbgl/style/sources/vector_source_impl.hpp
index ced7d80471..4a6703e5c0 100644
--- a/src/mbgl/style/sources/vector_source.hpp
+++ b/src/mbgl/style/sources/vector_source_impl.hpp
@@ -1,15 +1,16 @@
#pragma once
-#include <mbgl/style/tile_source.hpp>
+#include <mbgl/style/sources/vector_source.hpp>
+#include <mbgl/style/tile_source_impl.hpp>
namespace mbgl {
namespace style {
-class VectorSource : public TileSource {
+class VectorSource::Impl : public TileSourceImpl {
public:
static std::unique_ptr<VectorSource> parse(std::string id, const JSValue&);
- VectorSource(std::string id, variant<std::string, Tileset>);
+ Impl(std::string id, Source&, variant<std::string, Tileset>);
private:
std::unique_ptr<Tile> createTile(const OverscaledTileID&, const UpdateParameters&) final;
diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp
index af19c41393..a75133f82d 100644
--- a/src/mbgl/style/style.cpp
+++ b/src/mbgl/style/style.cpp
@@ -1,6 +1,6 @@
#include <mbgl/style/style.hpp>
#include <mbgl/style/observer.hpp>
-#include <mbgl/style/source.hpp>
+#include <mbgl/style/source_impl.hpp>
#include <mbgl/style/layers/symbol_layer.hpp>
#include <mbgl/style/layers/symbol_layer_impl.hpp>
#include <mbgl/style/layers/custom_layer.hpp>
@@ -47,7 +47,7 @@ Style::Style(FileSource& fileSource_, float pixelRatio)
Style::~Style() {
for (const auto& source : sources) {
- source->setObserver(nullptr);
+ source->baseImpl->setObserver(nullptr);
}
glyphStore->setObserver(nullptr);
@@ -107,7 +107,7 @@ void Style::setJSON(const std::string& json) {
}
void Style::addSource(std::unique_ptr<Source> source) {
- source->setObserver(this);
+ source->baseImpl->setObserver(this);
sources.emplace_back(std::move(source));
}
@@ -156,7 +156,7 @@ void Style::update(const UpdateParameters& parameters) {
bool allTilesUpdated = true;
for (const auto& source : sources) {
- if (!source->update(parameters)) {
+ if (!source->baseImpl->update(parameters)) {
allTilesUpdated = false;
}
}
@@ -195,7 +195,7 @@ void Style::cascade(const TimePoint& timePoint, MapMode mode) {
void Style::recalculate(float z, const TimePoint& timePoint, MapMode mode) {
for (const auto& source : sources) {
- source->enabled = false;
+ source->baseImpl->enabled = false;
}
zoomHistory.update(z, timePoint);
@@ -213,9 +213,9 @@ void Style::recalculate(float z, const TimePoint& timePoint, MapMode mode) {
Source* source = getSource(layer->baseImpl->source);
if (source && layer->baseImpl->needsRendering()) {
- source->enabled = true;
- if (!source->loaded) {
- source->load(fileSource);
+ source->baseImpl->enabled = true;
+ if (!source->baseImpl->loaded) {
+ source->baseImpl->load(fileSource);
}
}
}
@@ -223,7 +223,7 @@ void Style::recalculate(float z, const TimePoint& timePoint, MapMode mode) {
Source* Style::getSource(const std::string& id) const {
const auto it = std::find_if(sources.begin(), sources.end(), [&](const auto& source) {
- return source->id == id;
+ return source->getID() == id;
});
return it != sources.end() ? it->get() : nullptr;
@@ -239,7 +239,7 @@ bool Style::isLoaded() const {
}
for (const auto& source: sources) {
- if (source->enabled && !source->isLoaded()) return false;
+ if (source->baseImpl->enabled && !source->baseImpl->isLoaded()) return false;
}
if (!spriteStore->isLoaded()) {
@@ -253,7 +253,7 @@ RenderData Style::getRenderData() const {
RenderData result;
for (const auto& source : sources) {
- if (source->enabled) {
+ if (source->baseImpl->enabled) {
result.sources.insert(source.get());
}
}
@@ -285,7 +285,7 @@ RenderData Style::getRenderData() const {
continue;
}
- for (auto& pair : source->getRenderTiles()) {
+ for (auto& pair : source->baseImpl->getRenderTiles()) {
auto& tile = pair.second;
if (!tile.tile.isRenderable()) {
continue;
@@ -324,7 +324,7 @@ std::vector<Feature> Style::queryRenderedFeatures(const QueryParameters& paramet
std::unordered_map<std::string, std::vector<Feature>> resultsByLayer;
for (const auto& source : sources) {
- auto sourceResults = source->queryRenderedFeatures(parameters);
+ auto sourceResults = source->baseImpl->queryRenderedFeatures(parameters);
std::move(sourceResults.begin(), sourceResults.end(), std::inserter(resultsByLayer, resultsByLayer.begin()));
}
@@ -352,13 +352,13 @@ float Style::getQueryRadius() const {
void Style::setSourceTileCacheSize(size_t size) {
for (const auto& source : sources) {
- source->setCacheSize(size);
+ source->baseImpl->setCacheSize(size);
}
}
void Style::onLowMemory() {
for (const auto& source : sources) {
- source->onLowMemory();
+ source->baseImpl->onLowMemory();
}
}
@@ -388,7 +388,7 @@ void Style::onSourceLoaded(Source& source) {
void Style::onSourceError(Source& source, std::exception_ptr error) {
lastError = error;
Log::Error(Event::Style, "Failed to load source %s: %s",
- source.id.c_str(), util::toString(error).c_str());
+ source.getID().c_str(), util::toString(error).c_str());
observer->onSourceError(source, error);
observer->onResourceError(error);
}
@@ -405,7 +405,7 @@ void Style::onTileLoaded(Source& source, const OverscaledTileID& tileID, bool is
void Style::onTileError(Source& source, const OverscaledTileID& tileID, std::exception_ptr error) {
lastError = error;
Log::Error(Event::Style, "Failed to load tile %s for source %s: %s",
- util::toString(tileID).c_str(), source.id.c_str(), util::toString(error).c_str());
+ util::toString(tileID).c_str(), source.getID().c_str(), util::toString(error).c_str());
observer->onTileError(source, tileID, error);
observer->onResourceError(error);
}
@@ -429,7 +429,7 @@ void Style::onSpriteError(std::exception_ptr error) {
void Style::dumpDebugLogs() const {
for (const auto& source : sources) {
- source->dumpDebugLogs();
+ source->baseImpl->dumpDebugLogs();
}
spriteStore->dumpDebugLogs();
diff --git a/src/mbgl/style/tile_source.cpp b/src/mbgl/style/tile_source_impl.cpp
index 0824693331..634ef39808 100644
--- a/src/mbgl/style/tile_source.cpp
+++ b/src/mbgl/style/tile_source_impl.cpp
@@ -1,4 +1,4 @@
-#include <mbgl/style/tile_source.hpp>
+#include <mbgl/style/tile_source_impl.hpp>
#include <mbgl/style/source_observer.hpp>
#include <mbgl/style/parser.hpp>
#include <mbgl/util/tileset.hpp>
@@ -81,7 +81,7 @@ Tileset parseTileJSON(const JSValue& value) {
} // end namespace
-Tileset TileSource::parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType type, uint16_t tileSize) {
+Tileset TileSourceImpl::parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType type, uint16_t tileSize) {
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> document;
document.Parse<0>(json.c_str());
@@ -103,7 +103,7 @@ Tileset TileSource::parseTileJSON(const std::string& json, const std::string& so
return result;
}
-optional<variant<std::string, Tileset>> TileSource::parseURLOrTileset(const JSValue& value) {
+optional<variant<std::string, Tileset>> TileSourceImpl::parseURLOrTileset(const JSValue& value) {
if (!value.HasMember("url")) {
return { mbgl::style::parseTileJSON(value) };
}
@@ -117,18 +117,17 @@ optional<variant<std::string, Tileset>> TileSource::parseURLOrTileset(const JSVa
return { std::string(urlVal.GetString(), urlVal.GetStringLength()) };
}
-TileSource::TileSource(SourceType type_,
- std::string id_,
- variant<std::string, Tileset> urlOrTileset_,
- uint16_t tileSize_)
- : Source(type_, std::move(id_)),
+TileSourceImpl::TileSourceImpl(SourceType type_, std::string id_, Source& base_,
+ variant<std::string, Tileset> urlOrTileset_,
+ uint16_t tileSize_)
+ : Impl(type_, std::move(id_), base_),
urlOrTileset(std::move(urlOrTileset_)),
tileSize(tileSize_) {
}
-TileSource::~TileSource() = default;
+TileSourceImpl::~TileSourceImpl() = default;
-void TileSource::load(FileSource& fileSource) {
+void TileSourceImpl::load(FileSource& fileSource) {
if (urlOrTileset.is<Tileset>()) {
tileset = urlOrTileset.get<Tileset>();
loaded = true;
@@ -142,11 +141,11 @@ void TileSource::load(FileSource& fileSource) {
const std::string& url = urlOrTileset.get<std::string>();
req = fileSource.request(Resource::source(url), [this, url](Response res) {
if (res.error) {
- observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error(res.error->message)));
+ observer->onSourceError(base, std::make_exception_ptr(std::runtime_error(res.error->message)));
} else if (res.notModified) {
return;
} else if (res.noContent) {
- observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error("unexpectedly empty TileJSON")));
+ observer->onSourceError(base, std::make_exception_ptr(std::runtime_error("unexpectedly empty TileJSON")));
} else {
Tileset newTileset;
@@ -156,7 +155,7 @@ void TileSource::load(FileSource& fileSource) {
try {
newTileset = parseTileJSON(*res.data, url, type, tileSize);
} catch (...) {
- observer->onSourceError(*this, std::current_exception());
+ observer->onSourceError(base, std::current_exception());
return;
}
@@ -183,12 +182,12 @@ void TileSource::load(FileSource& fileSource) {
tileset = newTileset;
loaded = true;
- observer->onSourceLoaded(*this);
+ observer->onSourceLoaded(base);
}
});
}
-Range<uint8_t> TileSource::getZoomRange() {
+Range<uint8_t> TileSourceImpl::getZoomRange() {
assert(loaded);
return tileset.zoomRange;
}
diff --git a/src/mbgl/style/tile_source.hpp b/src/mbgl/style/tile_source_impl.hpp
index 66d956a6ef..1ceb1188db 100644
--- a/src/mbgl/style/tile_source.hpp
+++ b/src/mbgl/style/tile_source_impl.hpp
@@ -1,6 +1,6 @@
#pragma once
-#include <mbgl/style/source.hpp>
+#include <mbgl/style/source_impl.hpp>
#include <mbgl/util/tileset.hpp>
#include <mbgl/util/variant.hpp>
#include <mbgl/util/optional.hpp>
@@ -16,17 +16,16 @@ namespace style {
Shared implementation for VectorSource and RasterSource. Should eventually
be refactored to use composition rather than inheritance.
*/
-class TileSource : public Source {
+class TileSourceImpl : public Source::Impl {
public:
// A tile source can either specify a URL to TileJSON, or inline TileJSON.
static optional<variant<std::string, Tileset>> parseURLOrTileset(const JSValue&);
static Tileset parseTileJSON(const std::string& json, const std::string& sourceURL, SourceType, uint16_t tileSize);
- TileSource(SourceType,
- std::string id,
- variant<std::string, Tileset> urlOrTileset,
- uint16_t tileSize);
- ~TileSource() override;
+ TileSourceImpl(SourceType, std::string id, Source&,
+ variant<std::string, Tileset> urlOrTileset,
+ uint16_t tileSize);
+ ~TileSourceImpl() override;
void load(FileSource&) final;