diff options
Diffstat (limited to 'src/mbgl')
-rw-r--r-- | src/mbgl/annotation/annotation_manager.cpp | 14 | ||||
-rw-r--r-- | src/mbgl/annotation/annotation_manager.hpp | 9 | ||||
-rw-r--r-- | src/mbgl/annotation/annotation_tile.cpp | 18 | ||||
-rw-r--r-- | src/mbgl/annotation/annotation_tile.hpp | 7 | ||||
-rw-r--r-- | src/mbgl/map/geometry_tile.hpp | 5 | ||||
-rw-r--r-- | src/mbgl/map/source.cpp | 7 | ||||
-rw-r--r-- | src/mbgl/map/source.hpp | 2 |
7 files changed, 46 insertions, 16 deletions
diff --git a/src/mbgl/annotation/annotation_manager.cpp b/src/mbgl/annotation/annotation_manager.cpp index e5c55c90dd..7169d51622 100644 --- a/src/mbgl/annotation/annotation_manager.cpp +++ b/src/mbgl/annotation/annotation_manager.cpp @@ -138,7 +138,19 @@ void AnnotationManager::updateStyle(Style& style) { } obsoleteShapeAnnotationLayers.clear(); - style.getSource(SourceID)->invalidateTiles(); + + for (auto& monitor : monitors) { + monitor->update(getTile(monitor->tileID)); + } +} + +void AnnotationManager::addTileMonitor(AnnotationTileMonitor& monitor) { + monitors.insert(&monitor); + monitor.update(getTile(monitor.tileID)); +} + +void AnnotationManager::removeTileMonitor(AnnotationTileMonitor& monitor) { + monitors.erase(&monitor); } } diff --git a/src/mbgl/annotation/annotation_manager.hpp b/src/mbgl/annotation/annotation_manager.hpp index 42acbb9983..f1b41c9ccc 100644 --- a/src/mbgl/annotation/annotation_manager.hpp +++ b/src/mbgl/annotation/annotation_manager.hpp @@ -9,12 +9,14 @@ #include <string> #include <vector> +#include <set> namespace mbgl { class PointAnnotation; class ShapeAnnotation; class AnnotationTile; +class AnnotationTileMonitor; class Style; class AnnotationManager : private util::noncopyable { @@ -30,17 +32,22 @@ public: LatLngBounds getBoundsForAnnotations(const AnnotationIDs&) const; void updateStyle(Style&); - std::unique_ptr<AnnotationTile> getTile(const TileID&); + + void addTileMonitor(AnnotationTileMonitor&); + void removeTileMonitor(AnnotationTileMonitor&); static const std::string SourceID; static const std::string PointLayerID; private: + std::unique_ptr<AnnotationTile> getTile(const TileID&); + AnnotationID nextID = 0; PointAnnotationImpl::Tree pointTree; PointAnnotationImpl::Map pointAnnotations; ShapeAnnotationImpl::Map shapeAnnotations; std::vector<std::string> obsoleteShapeAnnotationLayers; + std::set<AnnotationTileMonitor*> monitors; }; } diff --git a/src/mbgl/annotation/annotation_tile.cpp b/src/mbgl/annotation/annotation_tile.cpp index 81f7662b48..4b0f2a92ec 100644 --- a/src/mbgl/annotation/annotation_tile.cpp +++ b/src/mbgl/annotation/annotation_tile.cpp @@ -26,13 +26,23 @@ util::ptr<GeometryTileLayer> AnnotationTile::getLayer(const std::string& name) c return nullptr; } -AnnotationTileMonitor::AnnotationTileMonitor(const TileID& id, MapData& data) - : tile(data.getAnnotationManager()->getTile(id)) { +AnnotationTileMonitor::AnnotationTileMonitor(const TileID& tileID_, MapData& data_) + : tileID(tileID_), + data(data_) { } -Request* AnnotationTileMonitor::monitorTile(std::function<void (std::exception_ptr, std::unique_ptr<GeometryTile>)> callback) { - callback(nullptr, std::move(tile)); +AnnotationTileMonitor::~AnnotationTileMonitor() { + data.getAnnotationManager()->removeTileMonitor(*this); +} + +Request* AnnotationTileMonitor::monitorTile(std::function<void (std::exception_ptr, std::unique_ptr<GeometryTile>)> callback_) { + callback = callback_; + data.getAnnotationManager()->addTileMonitor(*this); return nullptr; } +void AnnotationTileMonitor::update(std::unique_ptr<GeometryTile> tile) { + callback(nullptr, std::move(tile)); +} + } diff --git a/src/mbgl/annotation/annotation_tile.hpp b/src/mbgl/annotation/annotation_tile.hpp index 52955da334..dcd843ed09 100644 --- a/src/mbgl/annotation/annotation_tile.hpp +++ b/src/mbgl/annotation/annotation_tile.hpp @@ -43,11 +43,16 @@ class MapData; class AnnotationTileMonitor : public GeometryTileMonitor { public: AnnotationTileMonitor(const TileID&, MapData&); + ~AnnotationTileMonitor(); + void update(std::unique_ptr<GeometryTile>); Request* monitorTile(std::function<void (std::exception_ptr, std::unique_ptr<GeometryTile>)>) override; + TileID tileID; + private: - std::unique_ptr<AnnotationTile> tile; + MapData& data; + std::function<void (std::exception_ptr, std::unique_ptr<GeometryTile>)> callback; }; } diff --git a/src/mbgl/map/geometry_tile.hpp b/src/mbgl/map/geometry_tile.hpp index 242476da64..93312bcf48 100644 --- a/src/mbgl/map/geometry_tile.hpp +++ b/src/mbgl/map/geometry_tile.hpp @@ -27,6 +27,7 @@ typedef std::vector<std::vector<Coordinate>> GeometryCollection; class GeometryTileFeature : private util::noncopyable { public: + virtual ~GeometryTileFeature() = default; virtual FeatureType getType() const = 0; virtual mapbox::util::optional<Value> getValue(const std::string& key) const = 0; virtual GeometryCollection getGeometries() const = 0; @@ -34,12 +35,14 @@ public: class GeometryTileLayer : private util::noncopyable { public: + virtual ~GeometryTileLayer() = default; virtual std::size_t featureCount() const = 0; virtual util::ptr<const GeometryTileFeature> getFeature(std::size_t) const = 0; }; class GeometryTile : private util::noncopyable { public: + virtual ~GeometryTile() = default; virtual util::ptr<GeometryTileLayer> getLayer(const std::string&) const = 0; }; @@ -47,6 +50,8 @@ class Request; class GeometryTileMonitor : private util::noncopyable { public: + virtual ~GeometryTileMonitor() = default; + /* * Monitor the tile held by this object for changes. When the tile is loaded for the first time, * or updates, the callback is executed. If an error occurs, the first parameter will be set. diff --git a/src/mbgl/map/source.cpp b/src/mbgl/map/source.cpp index 3cd73734fd..9a916537aa 100644 --- a/src/mbgl/map/source.cpp +++ b/src/mbgl/map/source.cpp @@ -526,13 +526,6 @@ bool Source::update(MapData& data, return allTilesUpdated; } -void Source::invalidateTiles() { - cache.clear(); - tiles.clear(); - tile_data.clear(); - updateTilePtrs(); -} - void Source::updateTilePtrs() { tilePtrs.clear(); for (const auto& pair : tiles) { diff --git a/src/mbgl/map/source.hpp b/src/mbgl/map/source.hpp index 4aab4a8b44..9120bbfa78 100644 --- a/src/mbgl/map/source.hpp +++ b/src/mbgl/map/source.hpp @@ -78,8 +78,6 @@ public: TexturePool&, bool shouldReparsePartialTiles); - void invalidateTiles(); - void updateMatrices(const mat4 &projMatrix, const TransformState &transform); void drawClippingMasks(Painter &painter); void finishRender(Painter &painter); |