From 9a698fe3b1a64777835d4d5409c1ff5c43ea2aee Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Mon, 20 Apr 2020 12:19:35 +0300 Subject: [core] Introduce Source::setMinimumTileUpdateInterval API The `Source::setMinimumTileUpdateInterval()` method sets the minimum tile update interval, which is used to throttle the tile update network requests. Default value is `Duration::zero()`. --- include/mbgl/style/source.hpp | 19 +++++++++++++++---- src/mbgl/style/custom_tile_loader.hpp | 6 ++++-- src/mbgl/style/source.cpp | 12 ++++++++++++ src/mbgl/style/source_impl.hpp | 6 +++++- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/include/mbgl/style/source.hpp b/include/mbgl/style/source.hpp index 32b15bdf47..a1650ad06a 100644 --- a/include/mbgl/style/source.hpp +++ b/include/mbgl/style/source.hpp @@ -1,9 +1,9 @@ #pragma once -#include -#include -#include #include +#include +#include +#include #include #include @@ -40,8 +40,11 @@ struct LayerTypeInfo; * * auto vectorSource = std::make_unique("my-vector-source"); */ -class Source : public mbgl::util::noncopyable { +class Source { public: + Source(const Source&) = delete; + Source& operator=(const Source&) = delete; + virtual ~Source(); // Check whether this source is of the given subtype. @@ -76,6 +79,14 @@ public: void setPrefetchZoomDelta(optional delta) noexcept; optional getPrefetchZoomDelta() const noexcept; + // If the given source supports loading tiles from a server, + // sets the minimum tile update interval, which is used to + // throttle the tile update network requests. + // + // Default value is `Duration::zero()`. + void setMinimumTileUpdateInterval(Duration) noexcept; + Duration getMinimumTileUpdateInterval() const noexcept; + // Sets a limit for how much a parent tile can be overscaled. // // When a set of tiles for a current zoom level is being rendered and some of the diff --git a/src/mbgl/style/custom_tile_loader.hpp b/src/mbgl/style/custom_tile_loader.hpp index b27a8a1521..78317fdcb1 100644 --- a/src/mbgl/style/custom_tile_loader.hpp +++ b/src/mbgl/style/custom_tile_loader.hpp @@ -1,9 +1,9 @@ #pragma once +#include #include #include #include -#include #include #include @@ -14,8 +14,10 @@ class CustomGeometryTile; namespace style { -class CustomTileLoader : private util::noncopyable { +class CustomTileLoader { public: + CustomTileLoader(const CustomTileLoader&) = delete; + CustomTileLoader& operator=(const CustomTileLoader&) = delete; using OverscaledIDFunctionTuple = std::tuple>; diff --git a/src/mbgl/style/source.cpp b/src/mbgl/style/source.cpp index 51a3c80089..42ad367d66 100644 --- a/src/mbgl/style/source.cpp +++ b/src/mbgl/style/source.cpp @@ -43,6 +43,18 @@ optional Source::getPrefetchZoomDelta() const noexcept { return baseImpl->getPrefetchZoomDelta(); } +void Source::setMinimumTileUpdateInterval(Duration interval) noexcept { + if (getMinimumTileUpdateInterval() == interval) return; + auto newImpl = createMutable(); + newImpl->setMinimumTileUpdateInterval(interval); + baseImpl = std::move(newImpl); + observer->onSourceChanged(*this); +} + +Duration Source::getMinimumTileUpdateInterval() const noexcept { + return baseImpl->getMinimumTileUpdateInterval(); +} + void Source::setMaxOverscaleFactorForParentTiles(optional overscaleFactor) noexcept { if (getMaxOverscaleFactorForParentTiles() == overscaleFactor) return; auto newImpl = createMutable(); diff --git a/src/mbgl/style/source_impl.hpp b/src/mbgl/style/source_impl.hpp index af8435537a..b16b763766 100644 --- a/src/mbgl/style/source_impl.hpp +++ b/src/mbgl/style/source_impl.hpp @@ -22,15 +22,19 @@ public: virtual optional getAttribution() const = 0; void setPrefetchZoomDelta(optional delta) noexcept; optional getPrefetchZoomDelta() const noexcept; + void setMinimumTileUpdateInterval(Duration interval) { minimumTileUpdateInterval = interval; } + Duration getMinimumTileUpdateInterval() const { return minimumTileUpdateInterval; } void setMaxOverscaleFactorForParentTiles(optional overscaleFactor) noexcept; optional getMaxOverscaleFactorForParentTiles() const noexcept; const SourceType type; const std::string id; + +protected: optional prefetchZoomDelta; optional maxOverscaleFactor; + Duration minimumTileUpdateInterval{Duration::zero()}; -protected: Impl(SourceType, std::string); Impl(const Impl&) = default; }; -- cgit v1.2.1