From 539d81a3b9f85d80cdf7f6b6153f19b1f2efd42d Mon Sep 17 00:00:00 2001 From: Brendan Ward Date: Thu, 7 Apr 2022 00:56:52 -0700 Subject: [PATCH] Rename MaptilerFileSource to MBTilesFileSource (#198) --- CHANGELOG.md | 4 +++- .../src/mbgl/storage/file_source_manager.cpp | 2 +- .../src/mbgl/storage/main_resource_loader.cpp | 22 +++++++++--------- .../src/mbgl/storage/mbtiles_file_source.cpp | 23 ++++++++----------- src/mbgl/storage/mbtiles_file_source.hpp | 16 ++++--------- 5 files changed, 30 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47623a22d4b..dfdb7c28b0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## master +- [core] `MaptilerFileSource` renamed to `MBTilesFileSource`. + ## maps-v1.6.0 ### ✨ New features @@ -35,7 +37,7 @@ Default minimum tile update interval value is `Duration::zero()`. - [core] Indroduce `distance` expression. ([#16397](https://github.com/mapbox/mapbox-gl-native/pull/16397)) - + The `distance` expression returns the shortest distance between two geometries. The returned value can be consumed as an input into another expression for changing a paint or layout property or filtering features by distance. Currently, the `distance` expression supports `Point`, `MultiPoint`, `LineString`, `MultiLineString` geometry types. diff --git a/platform/default/src/mbgl/storage/file_source_manager.cpp b/platform/default/src/mbgl/storage/file_source_manager.cpp index 259ec239750..3db95fd079c 100644 --- a/platform/default/src/mbgl/storage/file_source_manager.cpp +++ b/platform/default/src/mbgl/storage/file_source_manager.cpp @@ -28,7 +28,7 @@ class DefaultFileSourceManagerImpl final : public FileSourceManager { [](const ResourceOptions& options) { return std::make_unique(options); }); registerFileSourceFactory(FileSourceType::Mbtiles, - [](const ResourceOptions& options) { return std::make_unique(options); }); + [](const ResourceOptions& options) { return std::make_unique(options); }); registerFileSourceFactory(FileSourceType::Network, [](const ResourceOptions& options) { std::unique_ptr networkSource = std::make_unique(options); diff --git a/platform/default/src/mbgl/storage/main_resource_loader.cpp b/platform/default/src/mbgl/storage/main_resource_loader.cpp index 5bc03e4d998..2d980c4822b 100644 --- a/platform/default/src/mbgl/storage/main_resource_loader.cpp +++ b/platform/default/src/mbgl/storage/main_resource_loader.cpp @@ -20,12 +20,12 @@ class MainResourceLoaderThread { std::shared_ptr databaseFileSource_, std::shared_ptr localFileSource_, std::shared_ptr onlineFileSource_, - std::shared_ptr maptilerFileSource_) + std::shared_ptr mbtilesFileSource_) : assetFileSource(std::move(assetFileSource_)), databaseFileSource(std::move(databaseFileSource_)), localFileSource(std::move(localFileSource_)), onlineFileSource(std::move(onlineFileSource_)), - maptilerFileSource(std::move(maptilerFileSource_)) {} + mbtilesFileSource(std::move(mbtilesFileSource_)) {} void request(AsyncRequest* req, const Resource& resource, const ActorRef& ref) { auto callback = [ref](const Response& res) { ref.invoke(&FileSourceRequest::setResponse, res); }; @@ -65,9 +65,9 @@ class MainResourceLoaderThread { if (assetFileSource && assetFileSource->canRequest(resource)) { // Asset request tasks[req] = assetFileSource->request(resource, callback); - } else if (maptilerFileSource && maptilerFileSource->canRequest(resource)) { + } else if (mbtilesFileSource && mbtilesFileSource->canRequest(resource)) { // Local file request - tasks[req] = maptilerFileSource->request(resource, callback); + tasks[req] = mbtilesFileSource->request(resource, callback); } else if (localFileSource && localFileSource->canRequest(resource)) { // Local file request tasks[req] = localFileSource->request(resource, callback); @@ -127,7 +127,7 @@ class MainResourceLoaderThread { const std::shared_ptr databaseFileSource; const std::shared_ptr localFileSource; const std::shared_ptr onlineFileSource; - const std::shared_ptr maptilerFileSource; + const std::shared_ptr mbtilesFileSource; std::map> tasks; }; @@ -138,12 +138,12 @@ class MainResourceLoader::Impl { std::shared_ptr databaseFileSource_, std::shared_ptr localFileSource_, std::shared_ptr onlineFileSource_, - std::shared_ptr maptilerFileSource_) + std::shared_ptr mbtilesFileSource_) : assetFileSource(std::move(assetFileSource_)), databaseFileSource(std::move(databaseFileSource_)), localFileSource(std::move(localFileSource_)), onlineFileSource(std::move(onlineFileSource_)), - maptilerFileSource(std::move(maptilerFileSource_)), + mbtilesFileSource(std::move(mbtilesFileSource_)), supportsCacheOnlyRequests_(bool(databaseFileSource)), thread(std::make_unique>( util::makeThreadPrioritySetter(platform::EXPERIMENTAL_THREAD_PRIORITY_WORKER), @@ -152,7 +152,7 @@ class MainResourceLoader::Impl { databaseFileSource, localFileSource, onlineFileSource, - maptilerFileSource)), + mbtilesFileSource)), resourceOptions (options.clone()) {} std::unique_ptr request(const Resource& resource, Callback callback) { @@ -170,7 +170,7 @@ class MainResourceLoader::Impl { (localFileSource && localFileSource->canRequest(resource)) || (databaseFileSource && databaseFileSource->canRequest(resource)) || (onlineFileSource && onlineFileSource->canRequest(resource)) || - (maptilerFileSource && maptilerFileSource->canRequest(resource)); + (mbtilesFileSource && mbtilesFileSource->canRequest(resource)); } bool supportsCacheOnlyRequests() const { return supportsCacheOnlyRequests_; } @@ -186,7 +186,7 @@ class MainResourceLoader::Impl { databaseFileSource->setResourceOptions(options.clone()); localFileSource->setResourceOptions(options.clone()); onlineFileSource->setResourceOptions(options.clone()); - maptilerFileSource->setResourceOptions(options.clone()); + mbtilesFileSource->setResourceOptions(options.clone()); } ResourceOptions getResourceOptions() { @@ -199,7 +199,7 @@ class MainResourceLoader::Impl { const std::shared_ptr databaseFileSource; const std::shared_ptr localFileSource; const std::shared_ptr onlineFileSource; - const std::shared_ptr maptilerFileSource; + const std::shared_ptr mbtilesFileSource; const bool supportsCacheOnlyRequests_; const std::unique_ptr> thread; mutable std::mutex resourceOptionsMutex; diff --git a/platform/default/src/mbgl/storage/mbtiles_file_source.cpp b/platform/default/src/mbgl/storage/mbtiles_file_source.cpp index dc2b6087665..ff3d76510a7 100644 --- a/platform/default/src/mbgl/storage/mbtiles_file_source.cpp +++ b/platform/default/src/mbgl/storage/mbtiles_file_source.cpp @@ -24,8 +24,6 @@ #endif namespace { -//TODO: replace by mbgl::util::MBTILES_PROTOCOL -const std::string maptilerProtocol = "mbtiles://"; bool acceptsURL(const std::string& url) { return 0 == url.rfind(mbgl::util::MBTILES_PROTOCOL, 0); } @@ -33,9 +31,8 @@ bool acceptsURL(const std::string& url) { namespace mbgl { using namespace rapidjson; -//using namespace mapbox::sqlite; -class MaptilerFileSource::Impl { +class MBTilesFileSource::Impl { public: explicit Impl(const ActorRef&, const ResourceOptions& options): resourceOptions (options.clone()) {} @@ -65,7 +62,7 @@ class MaptilerFileSource::Impl { } std::string url_to_path(const std::string &url) { - return mbgl::util::percentDecode(url.substr(maptilerProtocol.size())); + return mbgl::util::percentDecode(url.substr(std::char_traits::length(util::MBTILES_PROTOCOL))); } std::string db_path(const std::string &path) { @@ -265,19 +262,19 @@ class MaptilerFileSource::Impl { }; -MaptilerFileSource::MaptilerFileSource(const ResourceOptions& options) : +MBTilesFileSource::MBTilesFileSource(const ResourceOptions& options) : thread(std::make_unique>( - util::makeThreadPrioritySetter(platform::EXPERIMENTAL_THREAD_PRIORITY_FILE), "MaptilerFileSource", options.clone())) {} + util::makeThreadPrioritySetter(platform::EXPERIMENTAL_THREAD_PRIORITY_FILE), "MBTilesFileSource", options.clone())) {} -std::unique_ptr MaptilerFileSource::request(const Resource &resource, FileSource::Callback callback) { +std::unique_ptr MBTilesFileSource::request(const Resource &resource, FileSource::Callback callback) { auto req = std::make_unique(std::move(callback)); if (resource.url.find(":///") == std::string::npos) { Response response; response.noContent = true; response.error = std::make_unique(Response::Error::Reason::Other, - "MaptilerFileSource only supports absolute path urls"); + "MBTilesFileSource only supports absolute path urls"); req->actor().invoke(&FileSourceRequest::setResponse, response); } else { @@ -290,17 +287,17 @@ std::unique_ptr MaptilerFileSource::request(const Resource &resour return req; } -bool MaptilerFileSource::canRequest(const Resource& resource) const { +bool MBTilesFileSource::canRequest(const Resource& resource) const { return acceptsURL(resource.url); } -MaptilerFileSource::~MaptilerFileSource() = default; +MBTilesFileSource::~MBTilesFileSource() = default; -void MaptilerFileSource::setResourceOptions(ResourceOptions options) { +void MBTilesFileSource::setResourceOptions(ResourceOptions options) { thread->actor().invoke(&Impl::setResourceOptions, options.clone()); } -ResourceOptions MaptilerFileSource::getResourceOptions() { +ResourceOptions MBTilesFileSource::getResourceOptions() { return thread->actor().ask(&Impl::getResourceOptions).get(); } diff --git a/src/mbgl/storage/mbtiles_file_source.hpp b/src/mbgl/storage/mbtiles_file_source.hpp index 9ea62f35381..76afd14c158 100644 --- a/src/mbgl/storage/mbtiles_file_source.hpp +++ b/src/mbgl/storage/mbtiles_file_source.hpp @@ -1,22 +1,19 @@ +#pragma once + #include -#include #include #include -#ifndef MBGL_MAPTILER_FILE_SOURCE_H -#define MBGL_MAPTILER_FILE_SOURCE_H namespace mbgl { // File source for supporting .mbtiles maps. // can only load resource URLS that are absolute paths to local files -class MaptilerFileSource : public FileSource { +class MBTilesFileSource : public FileSource { public: - MaptilerFileSource(const ResourceOptions& options); - ~MaptilerFileSource() override; + MBTilesFileSource(const ResourceOptions& options); + ~MBTilesFileSource() override; std::unique_ptr request(const Resource &, Callback) override; - - //static bool acceptsURL(const std::string &url); bool canRequest(const Resource&) const override; void setResourceOptions(ResourceOptions) override; @@ -28,6 +25,3 @@ class MaptilerFileSource : public FileSource { }; } // namespace mbgl - - -#endif //MBGL_MAPTILER_FILE_SOURCE_H \ No newline at end of file