diff options
author | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2020-02-07 16:04:20 +0200 |
---|---|---|
committer | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2020-02-11 10:40:30 +0200 |
commit | ac50f5275b45fa6a0859da0b162b561f8f2e567e (patch) | |
tree | 6648882b724ce6acc1cb082eaa1b45e2cf6fcb64 | |
parent | def38cf4db9e973f1d3e13f4ee2fba1afd694ea0 (diff) | |
download | qtlocation-mapboxgl-ac50f5275b45fa6a0859da0b162b561f8f2e567e.tar.gz |
[core] Make CustomGeometrySource::TileOptions immutable
-rw-r--r-- | src/mbgl/style/sources/custom_geometry_source_impl.cpp | 17 | ||||
-rw-r--r-- | src/mbgl/style/sources/custom_geometry_source_impl.hpp | 4 | ||||
-rw-r--r-- | src/mbgl/tile/custom_geometry_tile.cpp | 32 | ||||
-rw-r--r-- | src/mbgl/tile/custom_geometry_tile.hpp | 10 | ||||
-rw-r--r-- | test/tile/custom_geometry_tile.test.cpp | 21 |
5 files changed, 43 insertions, 41 deletions
diff --git a/src/mbgl/style/sources/custom_geometry_source_impl.cpp b/src/mbgl/style/sources/custom_geometry_source_impl.cpp index 67d52bdc24..95da377277 100644 --- a/src/mbgl/style/sources/custom_geometry_source_impl.cpp +++ b/src/mbgl/style/sources/custom_geometry_source_impl.cpp @@ -4,27 +4,20 @@ namespace mbgl { namespace style { -CustomGeometrySource::Impl::Impl(std::string id_, - const CustomGeometrySource::Options options) +CustomGeometrySource::Impl::Impl(std::string id_, CustomGeometrySource::Options options) : Source::Impl(SourceType::CustomVector, std::move(id_)), - tileOptions(options.tileOptions), + tileOptions(makeMutable<CustomGeometrySource::TileOptions>(options.tileOptions)), zoomRange(options.zoomRange), - loaderRef({}) { -} + loaderRef({}) {} CustomGeometrySource::Impl::Impl(const Impl& impl, ActorRef<CustomTileLoader> loaderRef_) - : Source::Impl(impl), - tileOptions(impl.tileOptions), - zoomRange(impl.zoomRange), - loaderRef(loaderRef_){ - -} + : Source::Impl(impl), tileOptions(impl.tileOptions), zoomRange(impl.zoomRange), loaderRef(loaderRef_) {} optional<std::string> CustomGeometrySource::Impl::getAttribution() const { return {}; } -CustomGeometrySource::TileOptions CustomGeometrySource::Impl::getTileOptions() const { +Immutable<CustomGeometrySource::TileOptions> CustomGeometrySource::Impl::getTileOptions() const { return tileOptions; } diff --git a/src/mbgl/style/sources/custom_geometry_source_impl.hpp b/src/mbgl/style/sources/custom_geometry_source_impl.hpp index ce7187202d..1ae77b02ec 100644 --- a/src/mbgl/style/sources/custom_geometry_source_impl.hpp +++ b/src/mbgl/style/sources/custom_geometry_source_impl.hpp @@ -15,12 +15,12 @@ public: optional<std::string> getAttribution() const final; - CustomGeometrySource::TileOptions getTileOptions() const; + Immutable<CustomGeometrySource::TileOptions> getTileOptions() const; Range<uint8_t> getZoomRange() const; optional<ActorRef<CustomTileLoader>> getTileLoader() const; private: - CustomGeometrySource::TileOptions tileOptions; + Immutable<CustomGeometrySource::TileOptions> tileOptions; Range<uint8_t> zoomRange; optional<ActorRef<CustomTileLoader>> loaderRef; }; diff --git a/src/mbgl/tile/custom_geometry_tile.cpp b/src/mbgl/tile/custom_geometry_tile.cpp index 7b1fc2e2d9..660dcf64d4 100644 --- a/src/mbgl/tile/custom_geometry_tile.cpp +++ b/src/mbgl/tile/custom_geometry_tile.cpp @@ -13,17 +13,16 @@ namespace mbgl { CustomGeometryTile::CustomGeometryTile(const OverscaledTileID& overscaledTileID, - std::string sourceID_, - const TileParameters& parameters, - const style::CustomGeometrySource::TileOptions options_, - ActorRef<style::CustomTileLoader> loader_) + std::string sourceID_, + const TileParameters& parameters, + Immutable<style::CustomGeometrySource::TileOptions> options_, + ActorRef<style::CustomTileLoader> loader_) : GeometryTile(overscaledTileID, sourceID_, parameters), - necessity(TileNecessity::Optional), - options(options_), - loader(std::move(loader_)), - mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())), - actorRef(*this, mailbox) { -} + necessity(TileNecessity::Optional), + options(std::move(options_)), + loader(std::move(loader_)), + mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())), + actorRef(*this, mailbox) {} CustomGeometryTile::~CustomGeometryTile() { loader.invoke(&style::CustomTileLoader::removeTile, id); @@ -33,15 +32,16 @@ void CustomGeometryTile::setTileData(const GeoJSON& geoJSON) { auto featureData = mapbox::feature::feature_collection<int16_t>(); if (geoJSON.is<FeatureCollection>() && !geoJSON.get<FeatureCollection>().empty()) { - const double scale = util::EXTENT / options.tileSize; + const double scale = util::EXTENT / options->tileSize; mapbox::geojsonvt::TileOptions vtOptions; vtOptions.extent = util::EXTENT; - vtOptions.buffer = ::round(scale * options.buffer); - vtOptions.tolerance = scale * options.tolerance; - featureData = mapbox::geojsonvt::geoJSONToTile(geoJSON, - id.canonical.z, id.canonical.x, id.canonical.y, - vtOptions, options.wrap, options.clip).features; + vtOptions.buffer = ::round(scale * options->buffer); + vtOptions.tolerance = scale * options->tolerance; + featureData = + mapbox::geojsonvt::geoJSONToTile( + geoJSON, id.canonical.z, id.canonical.x, id.canonical.y, vtOptions, options->wrap, options->clip) + .features; } setData(std::make_unique<GeoJSONTileData>(std::move(featureData))); } diff --git a/src/mbgl/tile/custom_geometry_tile.hpp b/src/mbgl/tile/custom_geometry_tile.hpp index 1df44e6b2a..3f8cc27279 100644 --- a/src/mbgl/tile/custom_geometry_tile.hpp +++ b/src/mbgl/tile/custom_geometry_tile.hpp @@ -17,10 +17,10 @@ class CustomTileLoader; class CustomGeometryTile: public GeometryTile { public: CustomGeometryTile(const OverscaledTileID&, - std::string sourceID, - const TileParameters&, - const style::CustomGeometrySource::TileOptions, - ActorRef<style::CustomTileLoader> loader); + std::string sourceID, + const TileParameters&, + Immutable<style::CustomGeometrySource::TileOptions>, + ActorRef<style::CustomTileLoader> loader); ~CustomGeometryTile() override; void setTileData(const GeoJSON& data); @@ -35,7 +35,7 @@ public: private: bool stale = true; TileNecessity necessity; - const style::CustomGeometrySource::TileOptions options; + Immutable<style::CustomGeometrySource::TileOptions> options; ActorRef<style::CustomTileLoader> loader; std::shared_ptr<Mailbox> mailbox; ActorRef<CustomGeometryTile> actorRef; diff --git a/test/tile/custom_geometry_tile.test.cpp b/test/tile/custom_geometry_tile.test.cpp index f3d11ab898..6e8a7e6981 100644 --- a/test/tile/custom_geometry_tile.test.cpp +++ b/test/tile/custom_geometry_tile.test.cpp @@ -61,8 +61,11 @@ TEST(CustomGeometryTile, InvokeFetchTile) { auto mb =std::make_shared<Mailbox>(*Scheduler::GetCurrent()); ActorRef<CustomTileLoader> loaderActor(loader, mb); - CustomGeometryTile tile(OverscaledTileID(0, 0, 0), "source", test.tileParameters, CustomGeometrySource::TileOptions(), - loaderActor); + CustomGeometryTile tile(OverscaledTileID(0, 0, 0), + "source", + test.tileParameters, + makeMutable<CustomGeometrySource::TileOptions>(), + loaderActor); tile.setNecessity(TileNecessity::Required); @@ -86,8 +89,11 @@ TEST(CustomGeometryTile, InvokeCancelTile) { auto mb =std::make_shared<Mailbox>(*Scheduler::GetCurrent()); ActorRef<CustomTileLoader> loaderActor(loader, mb); - CustomGeometryTile tile(OverscaledTileID(0, 0, 0), "source", test.tileParameters, CustomGeometrySource::TileOptions(), - loaderActor); + CustomGeometryTile tile(OverscaledTileID(0, 0, 0), + "source", + test.tileParameters, + makeMutable<CustomGeometrySource::TileOptions>(), + loaderActor); tile.setNecessity(TileNecessity::Required); tile.setNecessity(TileNecessity::Optional); @@ -108,8 +114,11 @@ TEST(CustomGeometryTile, InvokeTileChanged) { auto mb =std::make_shared<Mailbox>(*Scheduler::GetCurrent()); ActorRef<CustomTileLoader> loaderActor(loader, mb); - CustomGeometryTile tile(OverscaledTileID(0, 0, 0), "source", test.tileParameters, CustomGeometrySource::TileOptions(), - loaderActor); + CustomGeometryTile tile(OverscaledTileID(0, 0, 0), + "source", + test.tileParameters, + makeMutable<CustomGeometrySource::TileOptions>(), + loaderActor); Immutable<LayerProperties> layerProperties = makeMutable<CircleLayerProperties>(staticImmutableCast<CircleLayer::Impl>(layer.baseImpl)); StubTileObserver observer; |