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.cpp2
-rw-r--r--src/mbgl/style/sources/geojson_source_impl.cpp89
-rw-r--r--src/mbgl/style/sources/geojson_source_impl.hpp21
-rw-r--r--src/mbgl/style/sources/raster_source_impl.cpp7
-rw-r--r--src/mbgl/style/sources/raster_source_impl.hpp3
-rw-r--r--src/mbgl/style/sources/vector_source_impl.cpp8
-rw-r--r--src/mbgl/style/sources/vector_source_impl.hpp3
7 files changed, 65 insertions, 68 deletions
diff --git a/src/mbgl/style/sources/geojson_source.cpp b/src/mbgl/style/sources/geojson_source.cpp
index 62726cd127..110c1cd63c 100644
--- a/src/mbgl/style/sources/geojson_source.cpp
+++ b/src/mbgl/style/sources/geojson_source.cpp
@@ -4,7 +4,7 @@
namespace mbgl {
namespace style {
-GeoJSONSource::GeoJSONSource(const std::string& id, const GeoJSONOptions options)
+GeoJSONSource::GeoJSONSource(const std::string& id, const GeoJSONOptions& options)
: Source(SourceType::GeoJSON,
std::make_unique<GeoJSONSource::Impl>(std::move(id), *this, options)),
impl(static_cast<Impl*>(baseImpl.get())) {
diff --git a/src/mbgl/style/sources/geojson_source_impl.cpp b/src/mbgl/style/sources/geojson_source_impl.cpp
index 6431d5faa4..08ed95ea3f 100644
--- a/src/mbgl/style/sources/geojson_source_impl.cpp
+++ b/src/mbgl/style/sources/geojson_source_impl.cpp
@@ -1,10 +1,12 @@
-#include <mbgl/util/logging.hpp>
-#include <mbgl/storage/file_source.hpp>
+#include <mbgl/style/sources/geojson_source_impl.hpp>
#include <mbgl/style/conversion/geojson.hpp>
#include <mbgl/style/source_observer.hpp>
-#include <mbgl/style/sources/geojson_source_impl.hpp>
-#include <mbgl/tile/geojson_tile.hpp>
+#include <mbgl/tile/tile_id.hpp>
+#include <mbgl/storage/file_source.hpp>
+#include <mbgl/renderer/sources/render_geojson_source.hpp>
#include <mbgl/util/rapidjson.hpp>
+#include <mbgl/util/constants.cpp>
+#include <mbgl/util/logging.hpp>
#include <mapbox/geojson.hpp>
#include <mapbox/geojson/rapidjson.hpp>
@@ -31,6 +33,34 @@ optional<GeoJSON> convertGeoJSON(const JSValue& value, Error& error) {
}
} // namespace conversion
+class GeoJSONVTData : public GeoJSONData {
+public:
+ GeoJSONVTData(const GeoJSON& geoJSON,
+ const mapbox::geojsonvt::Options& options)
+ : impl(geoJSON, options) {}
+
+ mapbox::geometry::feature_collection<int16_t> getTile(const CanonicalTileID& tileID) final {
+ return impl.getTile(tileID.z, tileID.x, tileID.y).features;
+ }
+
+private:
+ mapbox::geojsonvt::GeoJSONVT impl;
+};
+
+class SuperclusterData : public GeoJSONData {
+public:
+ SuperclusterData(const mapbox::geometry::feature_collection<double>& features,
+ const mapbox::supercluster::Options& options)
+ : impl(features, options) {}
+
+ mapbox::geometry::feature_collection<int16_t> getTile(const CanonicalTileID& tileID) final {
+ return impl.getTile(tileID.z, tileID.x, tileID.y);
+ }
+
+private:
+ mapbox::supercluster::Supercluster impl;
+};
+
GeoJSONSource::Impl::Impl(std::string id_, Source& base_, const GeoJSONOptions options_)
: Source::Impl(SourceType::GeoJSON, std::move(id_), base_), options(options_) {
}
@@ -52,18 +82,14 @@ optional<std::string> GeoJSONSource::Impl::getURL() const {
return url;
}
-
void GeoJSONSource::Impl::setGeoJSON(const GeoJSON& geoJSON) {
req.reset();
_setGeoJSON(geoJSON);
}
-// Private implementation
void GeoJSONSource::Impl::_setGeoJSON(const GeoJSON& geoJSON) {
double scale = util::EXTENT / util::tileSize;
- cache.clear();
-
if (options.cluster
&& geoJSON.is<mapbox::geometry::feature_collection<double>>()
&& !geoJSON.get<mapbox::geometry::feature_collection<double>>().empty()) {
@@ -71,35 +97,15 @@ void GeoJSONSource::Impl::_setGeoJSON(const GeoJSON& geoJSON) {
clusterOptions.maxZoom = options.clusterMaxZoom;
clusterOptions.extent = util::EXTENT;
clusterOptions.radius = std::round(scale * options.clusterRadius);
-
- const auto& features = geoJSON.get<mapbox::geometry::feature_collection<double>>();
- geoJSONOrSupercluster =
- std::make_unique<mapbox::supercluster::Supercluster>(features, clusterOptions);
+ data = std::make_unique<SuperclusterData>(
+ geoJSON.get<mapbox::geometry::feature_collection<double>>(), clusterOptions);
} else {
mapbox::geojsonvt::Options vtOptions;
vtOptions.maxZoom = options.maxzoom;
vtOptions.extent = util::EXTENT;
vtOptions.buffer = std::round(scale * options.buffer);
vtOptions.tolerance = scale * options.tolerance;
- geoJSONOrSupercluster = std::make_unique<mapbox::geojsonvt::GeoJSONVT>(geoJSON, vtOptions);
- }
-
- for (auto const &item : tiles) {
- GeoJSONTile* geoJSONTile = static_cast<GeoJSONTile*>(item.second.get());
- setTileData(*geoJSONTile, geoJSONTile->id);
- }
-}
-
-void GeoJSONSource::Impl::setTileData(GeoJSONTile& tile, const OverscaledTileID& tileID) {
- if (geoJSONOrSupercluster.is<GeoJSONVTPointer>()) {
- tile.updateData(geoJSONOrSupercluster.get<GeoJSONVTPointer>()->getTile(tileID.canonical.z,
- tileID.canonical.x,
- tileID.canonical.y).features);
- } else {
- assert(geoJSONOrSupercluster.is<SuperclusterPointer>());
- tile.updateData(geoJSONOrSupercluster.get<SuperclusterPointer>()->getTile(tileID.canonical.z,
- tileID.canonical.x,
- tileID.canonical.y));
+ data = std::make_unique<GeoJSONVTData>(geoJSON, vtOptions);
}
}
@@ -135,8 +141,6 @@ void GeoJSONSource::Impl::loadDescription(FileSource& fileSource) {
return;
}
- invalidateTiles();
-
conversion::Error error;
optional<GeoJSON> geoJSON = conversion::convertGeoJSON<JSValue>(d, error);
if (!geoJSON) {
@@ -155,19 +159,16 @@ void GeoJSONSource::Impl::loadDescription(FileSource& fileSource) {
});
}
-optional<Range<uint8_t>> GeoJSONSource::Impl::getZoomRange() const {
- if (loaded) {
- return { { 0, options.maxzoom }};
- }
- return {};
+std::unique_ptr<RenderSource> GeoJSONSource::Impl::createRenderSource() const {
+ return std::make_unique<RenderGeoJSONSource>(*this);
+}
+
+Range<uint8_t> GeoJSONSource::Impl::getZoomRange() const {
+ return { 0, options.maxzoom };
}
-std::unique_ptr<Tile> GeoJSONSource::Impl::createTile(const OverscaledTileID& tileID,
- const UpdateParameters& parameters) {
- assert(loaded);
- auto tilePointer = std::make_unique<GeoJSONTile>(tileID, base.getID(), parameters);
- setTileData(*tilePointer.get(), tileID);
- return std::move(tilePointer);
+GeoJSONData* GeoJSONSource::Impl::getData() const {
+ return data.get();
}
} // namespace style
diff --git a/src/mbgl/style/sources/geojson_source_impl.hpp b/src/mbgl/style/sources/geojson_source_impl.hpp
index b827a0b26c..e8b881d05e 100644
--- a/src/mbgl/style/sources/geojson_source_impl.hpp
+++ b/src/mbgl/style/sources/geojson_source_impl.hpp
@@ -3,14 +3,19 @@
#include <mbgl/style/source_impl.hpp>
#include <mbgl/style/sources/geojson_source.hpp>
#include <mbgl/util/variant.hpp>
-#include <mbgl/tile/geojson_tile.hpp>
namespace mbgl {
class AsyncRequest;
+class CanonicalTileID;
namespace style {
+class GeoJSONData {
+public:
+ virtual mapbox::geometry::feature_collection<int16_t> getTile(const CanonicalTileID&) = 0;
+};
+
class GeoJSONSource::Impl : public Source::Impl {
public:
Impl(std::string id, Source&, const GeoJSONOptions);
@@ -18,27 +23,21 @@ public:
void setURL(std::string);
optional<std::string> getURL() const;
+ Range<uint8_t> getZoomRange() const;
void setGeoJSON(const GeoJSON&);
- void setTileData(GeoJSONTile&, const OverscaledTileID& tileID);
+ GeoJSONData* getData() const;
void loadDescription(FileSource&) final;
-
- uint16_t getTileSize() const final {
- return util::tileSize;
- }
-
- optional<Range<uint8_t>> getZoomRange() const final;
+ std::unique_ptr<RenderSource> createRenderSource() const final;
private:
void _setGeoJSON(const GeoJSON&);
- std::unique_ptr<Tile> createTile(const OverscaledTileID&, const UpdateParameters&) final;
-
GeoJSONOptions options;
optional<std::string> url;
std::unique_ptr<AsyncRequest> req;
- variant<GeoJSONVTPointer, SuperclusterPointer> geoJSONOrSupercluster;
+ std::unique_ptr<GeoJSONData> data;
};
} // namespace style
diff --git a/src/mbgl/style/sources/raster_source_impl.cpp b/src/mbgl/style/sources/raster_source_impl.cpp
index b727651260..b85d221f2e 100644
--- a/src/mbgl/style/sources/raster_source_impl.cpp
+++ b/src/mbgl/style/sources/raster_source_impl.cpp
@@ -1,5 +1,5 @@
#include <mbgl/style/sources/raster_source_impl.hpp>
-#include <mbgl/tile/raster_tile.hpp>
+#include <mbgl/renderer/sources/render_raster_source.hpp>
namespace mbgl {
namespace style {
@@ -10,9 +10,8 @@ RasterSource::Impl::Impl(std::string id_, Source& base_,
: TileSourceImpl(SourceType::Raster, std::move(id_), base_, std::move(urlOrTileset_), tileSize_) {
}
-std::unique_ptr<Tile> RasterSource::Impl::createTile(const OverscaledTileID& tileID,
- const UpdateParameters& parameters) {
- return std::make_unique<RasterTile>(tileID, parameters, tileset);
+std::unique_ptr<RenderSource> RasterSource::Impl::createRenderSource() const {
+ return std::make_unique<RenderRasterSource>(*this);
}
} // namespace style
diff --git a/src/mbgl/style/sources/raster_source_impl.hpp b/src/mbgl/style/sources/raster_source_impl.hpp
index 6f34a050bb..4bc76560f8 100644
--- a/src/mbgl/style/sources/raster_source_impl.hpp
+++ b/src/mbgl/style/sources/raster_source_impl.hpp
@@ -10,8 +10,7 @@ class RasterSource::Impl : public TileSourceImpl {
public:
Impl(std::string id, Source&, variant<std::string, Tileset>, uint16_t tileSize);
-private:
- std::unique_ptr<Tile> createTile(const OverscaledTileID&, const UpdateParameters&) final;
+ std::unique_ptr<RenderSource> createRenderSource() const final;
};
} // namespace style
diff --git a/src/mbgl/style/sources/vector_source_impl.cpp b/src/mbgl/style/sources/vector_source_impl.cpp
index efe8afbbea..158abf8575 100644
--- a/src/mbgl/style/sources/vector_source_impl.cpp
+++ b/src/mbgl/style/sources/vector_source_impl.cpp
@@ -1,5 +1,6 @@
#include <mbgl/style/sources/vector_source_impl.hpp>
-#include <mbgl/tile/vector_tile.hpp>
+#include <mbgl/renderer/sources/render_vector_source.hpp>
+#include <mbgl/util/constants.hpp>
namespace mbgl {
namespace style {
@@ -8,9 +9,8 @@ VectorSource::Impl::Impl(std::string id_, Source& base_, variant<std::string, Ti
: 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);
+std::unique_ptr<RenderSource> VectorSource::Impl::createRenderSource() const {
+ return std::make_unique<RenderVectorSource>(*this);
}
} // namespace style
diff --git a/src/mbgl/style/sources/vector_source_impl.hpp b/src/mbgl/style/sources/vector_source_impl.hpp
index 6726fa6955..844739948c 100644
--- a/src/mbgl/style/sources/vector_source_impl.hpp
+++ b/src/mbgl/style/sources/vector_source_impl.hpp
@@ -10,8 +10,7 @@ class VectorSource::Impl : public TileSourceImpl {
public:
Impl(std::string id, Source&, variant<std::string, Tileset>);
-private:
- std::unique_ptr<Tile> createTile(const OverscaledTileID&, const UpdateParameters&) final;
+ std::unique_ptr<RenderSource> createRenderSource() const final;
};
} // namespace style