diff --git a/include/mbgl/style/sources/geojson_source.hpp b/include/mbgl/style/sources/geojson_source.hpp index 306a33025..e633e6efb 100644 --- a/include/mbgl/style/sources/geojson_source.hpp +++ b/include/mbgl/style/sources/geojson_source.hpp @@ -2,6 +2,7 @@ #include #include +#include #include @@ -42,7 +43,7 @@ public: void setURL(const std::string& url); void setGeoJSON(const GeoJSON&); - std::string getURL(); + optional getURL(); // Private implementation diff --git a/platform/default/mbgl/storage/offline_download.cpp b/platform/default/mbgl/storage/offline_download.cpp index 87534f222..bf75989d2 100644 --- a/platform/default/mbgl/storage/offline_download.cpp +++ b/platform/default/mbgl/storage/offline_download.cpp @@ -205,8 +205,8 @@ void OfflineDownload::activateDownload() { style::GeoJSONSource::Impl* geojsonSource = static_cast(source->baseImpl.get()); - if (!geojsonSource->loaded) { - ensureResource(Resource::source(geojsonSource->getURL())); + if (geojsonSource->getURL()) { + ensureResource(Resource::source(*geojsonSource->getURL())); } break; } diff --git a/src/mbgl/style/sources/geojson_source.cpp b/src/mbgl/style/sources/geojson_source.cpp index 2bf27880b..748043813 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 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 0821ac023..8dc0d9bb8 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()); - return urlOrGeoJSON.get(); +optional 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(geoJSON, vtOptions); + geoJSONOrSupercluster = std::make_unique(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>(); - urlOrGeoJSON = + geoJSONOrSupercluster = std::make_unique(features, clusterOptions); } } void GeoJSONSource::Impl::load(FileSource& fileSource) { - if (!urlOrGeoJSON.is()) { + if (!url) { loaded = true; return; } @@ -78,8 +77,7 @@ void GeoJSONSource::Impl::load(FileSource& fileSource) { return; } - const std::string& url = urlOrGeoJSON.get(); - 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 GeoJSONSource::Impl::getZoomRange() { std::unique_ptr GeoJSONSource::Impl::createTile(const OverscaledTileID& tileID, const UpdateParameters& parameters) { assert(loaded); - if (urlOrGeoJSON.is()) { + if (geoJSONOrSupercluster.is()) { return std::make_unique(tileID, base.getID(), parameters, - *urlOrGeoJSON.get()); + *geoJSONOrSupercluster.get()); } else { - assert(urlOrGeoJSON.is()); + assert(geoJSONOrSupercluster.is()); return std::make_unique(tileID, base.getID(), parameters, - *urlOrGeoJSON.get()); + *geoJSONOrSupercluster.get()); } } diff --git a/src/mbgl/style/sources/geojson_source_impl.hpp b/src/mbgl/style/sources/geojson_source_impl.hpp index eb3563e85..684b79b3f 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 getURL(); - std::string getURL(); + void setGeoJSON(const GeoJSON&); void load(FileSource&) final; @@ -30,10 +30,10 @@ private: Range getZoomRange() final; std::unique_ptr createTile(const OverscaledTileID&, const UpdateParameters&) final; - variant urlOrGeoJSON; - std::unique_ptr req; - GeoJSONOptions options; + optional url; + std::unique_ptr req; + variant geoJSONOrSupercluster; }; } // namespace style