diff options
Diffstat (limited to 'src/mbgl/style/sources')
-rw-r--r-- | src/mbgl/style/sources/geojson_source.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/style/sources/geojson_source_impl.cpp | 26 | ||||
-rw-r--r-- | src/mbgl/style/sources/geojson_source_impl.hpp | 10 |
3 files changed, 18 insertions, 20 deletions
diff --git a/src/mbgl/style/sources/geojson_source.cpp b/src/mbgl/style/sources/geojson_source.cpp index 2bf27880b4..7480438132 100644 --- a/src/mbgl/style/sources/geojson_source.cpp +++ b/src/mbgl/style/sources/geojson_source.cpp @@ -18,7 +18,7 @@ void GeoJSONSource::setGeoJSON(const mapbox::geojson::geojson& geoJSON) { impl->setGeoJSON(geoJSON); } -std::string GeoJSONSource::getURL() { +optional<std::string> GeoJSONSource::getURL() { return impl->getURL(); } diff --git a/src/mbgl/style/sources/geojson_source_impl.cpp b/src/mbgl/style/sources/geojson_source_impl.cpp index 0821ac0232..8dc0d9bb85 100644 --- a/src/mbgl/style/sources/geojson_source_impl.cpp +++ b/src/mbgl/style/sources/geojson_source_impl.cpp @@ -36,13 +36,12 @@ GeoJSONSource::Impl::Impl(std::string id_, Source& base_, const GeoJSONOptions o GeoJSONSource::Impl::~Impl() = default; -void GeoJSONSource::Impl::setURL(std::string url) { - urlOrGeoJSON = std::move(url); +void GeoJSONSource::Impl::setURL(std::string url_) { + url = std::move(url_); } -std::string GeoJSONSource::Impl::getURL() { - assert(urlOrGeoJSON.is<std::string>()); - return urlOrGeoJSON.get<std::string>(); +optional<std::string> GeoJSONSource::Impl::getURL() { + return url; } void GeoJSONSource::Impl::setGeoJSON(const GeoJSON& geoJSON) { @@ -54,7 +53,7 @@ void GeoJSONSource::Impl::setGeoJSON(const GeoJSON& geoJSON) { vtOptions.extent = util::EXTENT; vtOptions.buffer = std::round(scale * options.buffer); vtOptions.tolerance = scale * options.tolerance; - urlOrGeoJSON = std::make_unique<mapbox::geojsonvt::GeoJSONVT>(geoJSON, vtOptions); + geoJSONOrSupercluster = std::make_unique<mapbox::geojsonvt::GeoJSONVT>(geoJSON, vtOptions); } else { mapbox::supercluster::Options clusterOptions; @@ -63,13 +62,13 @@ void GeoJSONSource::Impl::setGeoJSON(const GeoJSON& geoJSON) { clusterOptions.radius = std::round(scale * options.clusterRadius); const auto& features = geoJSON.get<mapbox::geometry::feature_collection<double>>(); - urlOrGeoJSON = + geoJSONOrSupercluster = std::make_unique<mapbox::supercluster::Supercluster>(features, clusterOptions); } } void GeoJSONSource::Impl::load(FileSource& fileSource) { - if (!urlOrGeoJSON.is<std::string>()) { + if (!url) { loaded = true; return; } @@ -78,8 +77,7 @@ void GeoJSONSource::Impl::load(FileSource& fileSource) { return; } - const std::string& url = urlOrGeoJSON.get<std::string>(); - req = fileSource.request(Resource::source(url), [this](Response res) { + req = fileSource.request(Resource::source(*url), [this](Response res) { if (res.error) { observer->onSourceError( base, std::make_exception_ptr(std::runtime_error(res.error->message))); @@ -128,13 +126,13 @@ Range<uint8_t> GeoJSONSource::Impl::getZoomRange() { std::unique_ptr<Tile> GeoJSONSource::Impl::createTile(const OverscaledTileID& tileID, const UpdateParameters& parameters) { assert(loaded); - if (urlOrGeoJSON.is<GeoJSONVTPointer>()) { + if (geoJSONOrSupercluster.is<GeoJSONVTPointer>()) { return std::make_unique<GeoJSONTile>(tileID, base.getID(), parameters, - *urlOrGeoJSON.get<GeoJSONVTPointer>()); + *geoJSONOrSupercluster.get<GeoJSONVTPointer>()); } else { - assert(urlOrGeoJSON.is<SuperclusterPointer>()); + assert(geoJSONOrSupercluster.is<SuperclusterPointer>()); return std::make_unique<GeoJSONTile>(tileID, base.getID(), parameters, - *urlOrGeoJSON.get<SuperclusterPointer>()); + *geoJSONOrSupercluster.get<SuperclusterPointer>()); } } diff --git a/src/mbgl/style/sources/geojson_source_impl.hpp b/src/mbgl/style/sources/geojson_source_impl.hpp index eb3563e85a..684b79b3fa 100644 --- a/src/mbgl/style/sources/geojson_source_impl.hpp +++ b/src/mbgl/style/sources/geojson_source_impl.hpp @@ -16,9 +16,9 @@ public: ~Impl() final; void setURL(std::string); - void setGeoJSON(const GeoJSON&); + optional<std::string> getURL(); - std::string getURL(); + void setGeoJSON(const GeoJSON&); void load(FileSource&) final; @@ -30,10 +30,10 @@ private: Range<uint8_t> getZoomRange() final; std::unique_ptr<Tile> createTile(const OverscaledTileID&, const UpdateParameters&) final; - variant<std::string, GeoJSONVTPointer, SuperclusterPointer> urlOrGeoJSON; - std::unique_ptr<AsyncRequest> req; - GeoJSONOptions options; + optional<std::string> url; + std::unique_ptr<AsyncRequest> req; + variant<GeoJSONVTPointer, SuperclusterPointer> geoJSONOrSupercluster; }; } // namespace style |