diff options
author | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2020-01-24 12:38:08 +0200 |
---|---|---|
committer | Mikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com> | 2020-01-24 14:15:37 +0200 |
commit | 61ab64906e6ebca9fe27463d9ea12a747314386c (patch) | |
tree | ca59b4331d0a50336a1becdc17fd603db49836a7 /src/mbgl/style/sources/geojson_source.cpp | |
parent | 9e1bcc4fdc6cb3bb1710a6e2cefd7e642159b2f3 (diff) | |
download | qtlocation-mapboxgl-61ab64906e6ebca9fe27463d9ea12a747314386c.tar.gz |
GeoJSONSource is re-using the existing scheduler
Thus avoiding spawing new threads on `setGeoJSONData()` calls.
Diffstat (limited to 'src/mbgl/style/sources/geojson_source.cpp')
-rw-r--r-- | src/mbgl/style/sources/geojson_source.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/mbgl/style/sources/geojson_source.cpp b/src/mbgl/style/sources/geojson_source.cpp index d8414c1f84..3afccf07f2 100644 --- a/src/mbgl/style/sources/geojson_source.cpp +++ b/src/mbgl/style/sources/geojson_source.cpp @@ -39,8 +39,20 @@ void GeoJSONSource::setURL(const std::string& url_) { } } +namespace { + +inline std::shared_ptr<GeoJSONData> createGeoJSONData(const mapbox::geojson::geojson& geoJSON, + const GeoJSONSource::Impl& impl) { + if (auto data = impl.getData().lock()) { + return GeoJSONData::create(geoJSON, impl.getOptions(), data->getScheduler()); + } + return GeoJSONData::create(geoJSON, impl.getOptions()); +} + +} // namespace + void GeoJSONSource::setGeoJSON(const mapbox::geojson::geojson& geoJSON) { - setGeoJSONData(GeoJSONData::create(geoJSON, impl().getOptions())); + setGeoJSONData(createGeoJSONData(geoJSON, impl())); } void GeoJSONSource::setGeoJSONData(std::shared_ptr<GeoJSONData> geoJSONData) { @@ -83,7 +95,7 @@ void GeoJSONSource::loadDescription(FileSource& fileSource) { conversion::Error error; std::shared_ptr<GeoJSONData> geoJSONData; if (optional<GeoJSON> geoJSON = conversion::convertJSON<GeoJSON>(*data, error)) { - geoJSONData = GeoJSONData::create(*geoJSON, current.getOptions()); + geoJSONData = createGeoJSONData(*geoJSON, current); } 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()); |