summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mbgl/style/custom_tile_loader.cpp20
-rw-r--r--src/mbgl/style/custom_tile_loader.hpp10
-rw-r--r--src/mbgl/style/sources/custom_geometry_source.cpp2
-rw-r--r--src/mbgl/tile/custom_geometry_tile.cpp15
-rw-r--r--src/mbgl/tile/custom_geometry_tile.hpp14
5 files changed, 41 insertions, 20 deletions
diff --git a/src/mbgl/style/custom_tile_loader.cpp b/src/mbgl/style/custom_tile_loader.cpp
index d5bebf0086..af091be5cf 100644
--- a/src/mbgl/style/custom_tile_loader.cpp
+++ b/src/mbgl/style/custom_tile_loader.cpp
@@ -1,4 +1,5 @@
#include <mbgl/style/custom_tile_loader.hpp>
+#include <mbgl/tile/custom_geometry_tile.hpp>
namespace mbgl {
namespace style {
@@ -8,23 +9,23 @@ CustomTileLoader::CustomTileLoader(const TileFunction& fetchTileFn, const TileFu
cancelTileFunction = cancelTileFn;
}
-void CustomTileLoader::fetchTile(const OverscaledTileID& tileID, ActorRef<SetTileDataFunction> callbackRef) {
+void CustomTileLoader::fetchTile(const OverscaledTileID& tileID, ActorRef<CustomGeometryTile> tileRef) {
auto cachedTileData = dataCache.find(tileID.canonical);
if (cachedTileData != dataCache.end()) {
- callbackRef.invoke(&SetTileDataFunction::operator(), *(cachedTileData->second));
+ tileRef.invoke(&CustomGeometryTile::setTileData, *(cachedTileData->second));
}
auto tileCallbacks = tileCallbackMap.find(tileID.canonical);
if (tileCallbacks == tileCallbackMap.end()) {
- auto tuple = std::make_tuple(tileID.overscaledZ, tileID.wrap, callbackRef);
+ auto tuple = std::make_tuple(tileID.overscaledZ, tileID.wrap, tileRef);
tileCallbackMap.insert({ tileID.canonical, std::vector<OverscaledIDFunctionTuple>(1, tuple) });
} else {
for (auto iter = tileCallbacks->second.begin(); iter != tileCallbacks->second.end(); iter++) {
if (std::get<0>(*iter) == tileID.overscaledZ && std::get<1>(*iter) == tileID.wrap ) {
- std::get<2>(*iter) = callbackRef;
+ std::get<2>(*iter) = tileRef;
return;
}
}
- tileCallbacks->second.emplace_back(std::make_tuple(tileID.overscaledZ, tileID.wrap, callbackRef));
+ tileCallbacks->second.emplace_back(std::make_tuple(tileID.overscaledZ, tileID.wrap, tileRef));
}
if (cachedTileData == dataCache.end()) {
invokeTileFetch(tileID.canonical);
@@ -57,11 +58,12 @@ void CustomTileLoader::setTileData(const CanonicalTileID& tileID, const GeoJSON&
auto iter = tileCallbackMap.find(tileID);
if (iter == tileCallbackMap.end()) return;
- dataCache[tileID] = std::make_unique<mapbox::geojson::geojson>(std::move(data));;
+ auto dataPtr = std::make_unique<mapbox::geojson::geojson>(std::move(data));
for (auto tuple : iter->second) {
auto actor = std::get<2>(tuple);
- actor.invoke(&SetTileDataFunction::operator(), data);
+ actor.invoke(&CustomGeometryTile::setTileData, *dataPtr);
}
+ dataCache[tileID] = std::move(dataPtr);
}
void CustomTileLoader::invalidateTile(const CanonicalTileID& tileID) {
@@ -69,7 +71,7 @@ void CustomTileLoader::invalidateTile(const CanonicalTileID& tileID) {
if (tileCallbacks == tileCallbackMap.end()) { return; }
for (auto iter = tileCallbacks->second.begin(); iter != tileCallbacks->second.end(); iter++) {
auto actor = std::get<2>(*iter);
- actor.invoke(&SetTileDataFunction::operator(), mapbox::geojson::feature_collection());
+ actor.invoke(&CustomGeometryTile::invalidateTileData);
invokeTileCancel(tileID);
}
tileCallbackMap.erase(tileCallbacks);
@@ -82,7 +84,7 @@ void CustomTileLoader::invalidateRegion(const LatLngBounds& bounds, Range<uint8_
if (tileBounds.intersects(bounds) || bounds.contains(tileBounds) || tileBounds.contains(bounds)) {
for (auto iter = idtuple->second.begin(); iter != idtuple->second.end(); iter++) {
auto actor = std::get<2>(*iter);
- actor.invoke(&SetTileDataFunction::operator(), mapbox::geojson::feature_collection());
+ actor.invoke(&CustomGeometryTile::invalidateTileData);
invokeTileCancel(idtuple->first);
dataCache.erase(idtuple->first);
}
diff --git a/src/mbgl/style/custom_tile_loader.hpp b/src/mbgl/style/custom_tile_loader.hpp
index 149da69cfa..335d8c6143 100644
--- a/src/mbgl/style/custom_tile_loader.hpp
+++ b/src/mbgl/style/custom_tile_loader.hpp
@@ -2,25 +2,25 @@
#include <mbgl/style/sources/custom_geometry_source.hpp>
#include <mbgl/tile/tile_id.hpp>
-#include <mbgl/util/geo.hpp>
#include <mbgl/util/geojson.hpp>
#include <mbgl/actor/actor_ref.hpp>
#include <map>
namespace mbgl {
-namespace style {
-using SetTileDataFunction = std::function<void(const GeoJSON&)>;
+class CustomGeometryTile;
+
+namespace style {
class CustomTileLoader : private util::noncopyable {
public:
- using OverscaledIDFunctionTuple = std::tuple<uint8_t, int16_t, ActorRef<SetTileDataFunction>>;
+ using OverscaledIDFunctionTuple = std::tuple<uint8_t, int16_t, ActorRef<CustomGeometryTile>>;
CustomTileLoader(const TileFunction& fetchTileFn, const TileFunction& cancelTileFn);
- void fetchTile(const OverscaledTileID& tileID, ActorRef<SetTileDataFunction> callbackRef);
+ void fetchTile(const OverscaledTileID& tileID, ActorRef<CustomGeometryTile> tileRef);
void cancelTile(const OverscaledTileID& tileID);
void removeTile(const OverscaledTileID& tileID);
diff --git a/src/mbgl/style/sources/custom_geometry_source.cpp b/src/mbgl/style/sources/custom_geometry_source.cpp
index ab46843d38..b37490a5ce 100644
--- a/src/mbgl/style/sources/custom_geometry_source.cpp
+++ b/src/mbgl/style/sources/custom_geometry_source.cpp
@@ -40,6 +40,6 @@ void CustomGeometrySource::invalidateTile(const CanonicalTileID& tileID) {
void CustomGeometrySource::invalidateRegion(const LatLngBounds& bounds) {
loader->invoke(&CustomTileLoader::invalidateRegion, bounds, impl().getZoomRange());
}
-
+
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/tile/custom_geometry_tile.cpp b/src/mbgl/tile/custom_geometry_tile.cpp
index b608d90d83..7c8a85c4a4 100644
--- a/src/mbgl/tile/custom_geometry_tile.cpp
+++ b/src/mbgl/tile/custom_geometry_tile.cpp
@@ -5,6 +5,8 @@
#include <mbgl/actor/scheduler.hpp>
#include <mbgl/style/filter_evaluator.hpp>
#include <mbgl/util/string.hpp>
+#include <mbgl/tile/tile_observer.hpp>
+#include <mbgl/style/custom_tile_loader.hpp>
#include <mapbox/geojsonvt.hpp>
@@ -19,7 +21,8 @@ CustomGeometryTile::CustomGeometryTile(const OverscaledTileID& overscaledTileID,
necessity(TileNecessity::Optional),
options(options_),
loader(loader_),
- actor(*Scheduler::GetCurrent(), std::bind(&CustomGeometryTile::setTileData, this, std::placeholders::_1)) {
+ mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())),
+ actorRef(*this, mailbox) {
}
CustomGeometryTile::~CustomGeometryTile() {
@@ -43,14 +46,20 @@ void CustomGeometryTile::setTileData(const GeoJSON& geoJSON) {
setData(std::make_unique<GeoJSONTileData>(std::move(featureData)));
}
+void CustomGeometryTile::invalidateTileData() {
+ stale = true;
+ observer->onTileChanged(*this);
+}
+
//Fetching tile data for custom sources is assumed to be an expensive operation.
// Only required tiles make fetchTile requests. Attempt to cancel a tile
// that is no longer required.
void CustomGeometryTile::setNecessity(TileNecessity newNecessity) {
- if (newNecessity != necessity) {
+ if (newNecessity != necessity || stale ) {
necessity = newNecessity;
if (necessity == TileNecessity::Required) {
- loader.invoke(&style::CustomTileLoader::fetchTile, id, actor.self());
+ loader.invoke(&style::CustomTileLoader::fetchTile, id, actorRef);
+ stale = false;
} else if (!isRenderable()) {
loader.invoke(&style::CustomTileLoader::cancelTile, id);
}
diff --git a/src/mbgl/tile/custom_geometry_tile.hpp b/src/mbgl/tile/custom_geometry_tile.hpp
index 66cc412e8c..1df44e6b2a 100644
--- a/src/mbgl/tile/custom_geometry_tile.hpp
+++ b/src/mbgl/tile/custom_geometry_tile.hpp
@@ -1,13 +1,19 @@
#pragma once
#include <mbgl/tile/geometry_tile.hpp>
+#include <mbgl/style/sources/custom_geometry_source.hpp>
#include <mbgl/util/feature.hpp>
-#include <mbgl/style/custom_tile_loader.hpp>
+#include <mbgl/util/geojson.hpp>
+#include <mbgl/actor/mailbox.hpp>
namespace mbgl {
class TileParameters;
+namespace style {
+class CustomTileLoader;
+} // namespace style
+
class CustomGeometryTile: public GeometryTile {
public:
CustomGeometryTile(const OverscaledTileID&,
@@ -16,7 +22,9 @@ public:
const style::CustomGeometrySource::TileOptions,
ActorRef<style::CustomTileLoader> loader);
~CustomGeometryTile() override;
+
void setTileData(const GeoJSON& data);
+ void invalidateTileData();
void setNecessity(TileNecessity) final;
@@ -25,10 +33,12 @@ public:
const SourceQueryOptions&) override;
private:
+ bool stale = true;
TileNecessity necessity;
const style::CustomGeometrySource::TileOptions options;
ActorRef<style::CustomTileLoader> loader;
- Actor<style::SetTileDataFunction> actor;
+ std::shared_ptr<Mailbox> mailbox;
+ ActorRef<CustomGeometryTile> actorRef;
};
} // namespace mbgl