Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] Monitor annotation tiles, rather than completely invalidating …
Browse files Browse the repository at this point in the history
…them

Fixes #1688
  • Loading branch information
jfirebaugh committed Oct 30, 2015
1 parent 5f7dfa0 commit 5f6ed66
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 16 deletions.
14 changes: 13 additions & 1 deletion src/mbgl/annotation/annotation_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
9 changes: 8 additions & 1 deletion src/mbgl/annotation/annotation_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -30,17 +32,22 @@ class AnnotationManager : private util::noncopyable {
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;
};

}
Expand Down
18 changes: 14 additions & 4 deletions src/mbgl/annotation/annotation_tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

}
7 changes: 6 additions & 1 deletion src/mbgl/annotation/annotation_tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

}
Expand Down
5 changes: 5 additions & 0 deletions src/mbgl/map/geometry_tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,31 @@ 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;
};

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;
};

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.
Expand Down
7 changes: 0 additions & 7 deletions src/mbgl/map/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions src/mbgl/map/source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ class Source : private util::noncopyable {
TexturePool&,
bool shouldReparsePartialTiles);

void invalidateTiles();

void updateMatrices(const mat4 &projMatrix, const TransformState &transform);
void drawClippingMasks(Painter &painter);
void finishRender(Painter &painter);
Expand Down

0 comments on commit 5f6ed66

Please sign in to comment.