summaryrefslogtreecommitdiff
path: root/src/mbgl/style
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/style')
-rw-r--r--src/mbgl/style/sources/custom_vector_source.cpp80
-rw-r--r--src/mbgl/style/sources/custom_vector_source_impl.cpp16
-rw-r--r--src/mbgl/style/sources/custom_vector_source_impl.hpp10
3 files changed, 94 insertions, 12 deletions
diff --git a/src/mbgl/style/sources/custom_vector_source.cpp b/src/mbgl/style/sources/custom_vector_source.cpp
index e0bbd85af7..38e708a7a8 100644
--- a/src/mbgl/style/sources/custom_vector_source.cpp
+++ b/src/mbgl/style/sources/custom_vector_source.cpp
@@ -1,18 +1,94 @@
#include <mbgl/style/sources/custom_vector_source.hpp>
#include <mbgl/style/sources/custom_vector_source_impl.hpp>
+#include <mbgl/actor/scheduler.hpp>
namespace mbgl {
namespace style {
+class CustomTileLoader::Impl {
+public:
+ Impl(TileFunction&& fetchTileFn, TileFunction&& cancelTileFn) {
+ fetchTileFunction = std::move(fetchTileFn);
+ cancelTileFunction = std::move(cancelTileFn);
+ }
+
+ void fetchTile(const CanonicalTileID& tileID, ActorRef<SetTileDataFunction> callbackRef) {
+ fetchTileFunction(tileID);
+ auto insertResult = tileCallbackMap.insert({tileID, callbackRef});
+ if (insertResult.second == false) {
+ insertResult.first->second = callbackRef;
+ }
+ }
+
+ void cancelTile(const CanonicalTileID& tileID) {
+ if(tileCallbackMap.find(tileID) != tileCallbackMap.end())
+ cancelTileFunction(tileID);
+ }
+
+ void removeTile(const CanonicalTileID& tileID) {
+ tileCallbackMap.erase(tileID);
+ }
+
+ void setTileData(const CanonicalTileID& tileID, const mapbox::geojson::geojson& data) {
+ auto iter = tileCallbackMap.find(tileID);
+ if (iter == tileCallbackMap.end()) return;
+ iter->second.invoke(&SetTileDataFunction::operator(), tileID, data);
+ }
+
+private:
+ TileFunction fetchTileFunction;
+ TileFunction cancelTileFunction;
+ std::unordered_map<CanonicalTileID, ActorRef<SetTileDataFunction>> tileCallbackMap;
+};
+
+
+CustomTileLoader::CustomTileLoader(TileFunction&& fetchTileFn, TileFunction&& cancelTileFn)
+ : impl(new CustomTileLoader::Impl(std::move(fetchTileFn), std::move(cancelTileFn))) {
+
+}
+
+CustomTileLoader::~CustomTileLoader() {
+ delete impl;
+ impl = nullptr;
+}
+
+void CustomTileLoader::fetchTile(const CanonicalTileID& tileID, ActorRef<SetTileDataFunction> callbackRef) {
+ impl->fetchTile(tileID, callbackRef);
+}
+
+void CustomTileLoader::cancelTile(const CanonicalTileID& tileID) {
+ impl->cancelTile(tileID);
+}
+
+void CustomTileLoader::setTileData(const CanonicalTileID& tileID, const mapbox::geojson::geojson& data) {
+ impl->setTileData(tileID, data);
+}
+
+void CustomTileLoader::removeTile(const CanonicalTileID& tileID) {
+ impl->removeTile(tileID);
+}
+
CustomVectorSource::CustomVectorSource(std::string id,
const GeoJSONOptions options,
- FetchTileFunction fetchTileFn)
- : Source(makeMutable<CustomVectorSource::Impl>(std::move(id), options, fetchTileFn)) {
+ TileFunction fetchTileFn,
+ TileFunction cancelTileFn)
+ : Source(makeMutable<CustomVectorSource::Impl>(std::move(id), options)),
+ mailbox(std::make_shared<Mailbox>(*Scheduler::GetCurrent())),
+ loader(std::move(fetchTileFn), std::move(cancelTileFn)) {
}
+const CustomVectorSource::Impl& CustomVectorSource::impl() const {
+ return static_cast<const CustomVectorSource::Impl&>(*baseImpl);
+}
void CustomVectorSource::loadDescription(FileSource&) {
+ baseImpl = makeMutable<CustomVectorSource::Impl>(impl(), ActorRef<CustomTileLoader>(loader, mailbox));
loaded = true;
}
+void CustomVectorSource::setTileData(const CanonicalTileID& tileID,
+ const mapbox::geojson::geojson& data) {
+ loader.setTileData(tileID, data);
+}
+
} // namespace style
} // namespace mbgl
diff --git a/src/mbgl/style/sources/custom_vector_source_impl.cpp b/src/mbgl/style/sources/custom_vector_source_impl.cpp
index 1b5ee4e5d1..d1f20045cb 100644
--- a/src/mbgl/style/sources/custom_vector_source_impl.cpp
+++ b/src/mbgl/style/sources/custom_vector_source_impl.cpp
@@ -9,11 +9,17 @@ namespace mbgl {
namespace style {
CustomVectorSource::Impl::Impl(std::string id_,
- const GeoJSONOptions options_,
- FetchTileFunction fetchTileFn_)
+ const GeoJSONOptions options_)
: Source::Impl(SourceType::CustomVector, std::move(id_)),
options(options_),
- fetchTileFn(fetchTileFn_) {
+ loaderRef({}) {
+}
+
+CustomVectorSource::Impl::Impl(const Impl& impl, ActorRef<CustomTileLoader> loaderRef_)
+ : Source::Impl(impl),
+ options(impl.options),
+ loaderRef(loaderRef_){
+
}
optional<std::string> CustomVectorSource::Impl::getAttribution() const {
@@ -24,8 +30,8 @@ GeoJSONOptions CustomVectorSource::Impl::getOptions() const {
return options;
}
-FetchTileFunction CustomVectorSource::Impl::getFetchTileFunction() const {
- return fetchTileFn;
+optional<ActorRef<CustomTileLoader>> CustomVectorSource::Impl::getTileLoader() const {
+ return loaderRef;
}
} // namespace style
diff --git a/src/mbgl/style/sources/custom_vector_source_impl.hpp b/src/mbgl/style/sources/custom_vector_source_impl.hpp
index aa07bc800d..af103f4c7e 100644
--- a/src/mbgl/style/sources/custom_vector_source_impl.hpp
+++ b/src/mbgl/style/sources/custom_vector_source_impl.hpp
@@ -3,24 +3,24 @@
#include <mbgl/style/source_impl.hpp>
#include <mbgl/style/sources/custom_vector_source.hpp>
#include <mbgl/tile/tile_id.hpp>
+#include <mbgl/actor/actor_ref.hpp>
namespace mbgl {
namespace style {
class CustomVectorSource::Impl : public Source::Impl {
public:
- Impl(std::string id,
- GeoJSONOptions options,
- FetchTileFunction fetchTileFn);
+ Impl(std::string id, GeoJSONOptions options);
+ Impl(const Impl&, ActorRef<CustomTileLoader>);
optional<std::string> getAttribution() const final;
GeoJSONOptions getOptions() const;
- FetchTileFunction getFetchTileFunction() const;
+ optional<ActorRef<CustomTileLoader>> getTileLoader() const;
private:
GeoJSONOptions options;
- FetchTileFunction fetchTileFn;
+ optional<ActorRef<CustomTileLoader>> loaderRef;
};
} // namespace style