summaryrefslogtreecommitdiff
path: root/src/mbgl/style/sources
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/style/sources')
-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
7 files changed, 67 insertions, 59 deletions
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;