diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-10-30 11:30:54 +0200 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2019-10-31 10:24:55 +0200 |
commit | 8c498cd36c07b1019e5ddb60d5f9f8872f036e25 (patch) | |
tree | ea5c5578ae0433c9c3fff9da42c221d99c72ddfc /src/mbgl/style/sources/geojson_source.cpp | |
parent | 6900ac9837c6981b2a3f8d389ac09c0fca56b749 (diff) | |
download | qtlocation-mapboxgl-8c498cd36c07b1019e5ddb60d5f9f8872f036e25.tar.gz |
[core] Introduce and apply GeoJSONData::create() API
Diffstat (limited to 'src/mbgl/style/sources/geojson_source.cpp')
-rw-r--r-- | src/mbgl/style/sources/geojson_source.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/mbgl/style/sources/geojson_source.cpp b/src/mbgl/style/sources/geojson_source.cpp index 5171c7c8d9..79e7c23459 100644 --- a/src/mbgl/style/sources/geojson_source.cpp +++ b/src/mbgl/style/sources/geojson_source.cpp @@ -32,8 +32,12 @@ void GeoJSONSource::setURL(const std::string& url_) { } void GeoJSONSource::setGeoJSON(const mapbox::geojson::geojson& geoJSON) { + setGeoJSONData(GeoJSONData::create(geoJSON, impl().getOptions())); +} + +void GeoJSONSource::setGeoJSONData(std::shared_ptr<GeoJSONData> geoJSONData) { req.reset(); - baseImpl = makeMutable<Impl>(impl(), geoJSON); + baseImpl = makeMutable<Impl>(impl(), std::move(geoJSONData)); observer->onSourceChanged(*this); } @@ -62,17 +66,15 @@ void GeoJSONSource::loadDescription(FileSource& fileSource) { *this, std::make_exception_ptr(std::runtime_error("unexpectedly empty GeoJSON"))); } else { conversion::Error error; - optional<GeoJSON> geoJSON = conversion::convertJSON<GeoJSON>(*res.data, error); - if (!geoJSON) { + std::shared_ptr<GeoJSONData> geoJSONData; + if (optional<GeoJSON> geoJSON = conversion::convertJSON<GeoJSON>(*res.data, error)) { + geoJSONData = GeoJSONData::create(*geoJSON, impl().getOptions()); + } else { + // Create an empty GeoJSON VT object to make sure we're not infinitely waiting for tiles to load. Log::Error(Event::ParseStyle, "Failed to parse GeoJSON data: %s", error.message.c_str()); - // Create an empty GeoJSON VT object to make sure we're not infinitely waiting for - // tiles to load. - baseImpl = makeMutable<Impl>(impl(), GeoJSON{ FeatureCollection{} }); - } else { - baseImpl = makeMutable<Impl>(impl(), *geoJSON); } - + baseImpl = makeMutable<Impl>(impl(), std::move(geoJSONData)); loaded = true; observer->onSourceLoaded(*this); } |