Skip to content

Commit

Permalink
Rename MaptilerFileSource to MBTilesFileSource (mapbox#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
brendan-ward authored Apr 7, 2022
1 parent b3a4f16 commit 539d81a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 37 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## master

- [core] `MaptilerFileSource` renamed to `MBTilesFileSource`.

## maps-v1.6.0

### ✨ New features
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion platform/default/src/mbgl/storage/file_source_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class DefaultFileSourceManagerImpl final : public FileSourceManager {
[](const ResourceOptions& options) { return std::make_unique<LocalFileSource>(options); });

registerFileSourceFactory(FileSourceType::Mbtiles,
[](const ResourceOptions& options) { return std::make_unique<MaptilerFileSource>(options); });
[](const ResourceOptions& options) { return std::make_unique<MBTilesFileSource>(options); });

registerFileSourceFactory(FileSourceType::Network, [](const ResourceOptions& options) {
std::unique_ptr<FileSource> networkSource = std::make_unique<OnlineFileSource>(options);
Expand Down
22 changes: 11 additions & 11 deletions platform/default/src/mbgl/storage/main_resource_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class MainResourceLoaderThread {
std::shared_ptr<FileSource> databaseFileSource_,
std::shared_ptr<FileSource> localFileSource_,
std::shared_ptr<FileSource> onlineFileSource_,
std::shared_ptr<FileSource> maptilerFileSource_)
std::shared_ptr<FileSource> 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<FileSourceRequest>& ref) {
auto callback = [ref](const Response& res) { ref.invoke(&FileSourceRequest::setResponse, res); };
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -127,7 +127,7 @@ class MainResourceLoaderThread {
const std::shared_ptr<FileSource> databaseFileSource;
const std::shared_ptr<FileSource> localFileSource;
const std::shared_ptr<FileSource> onlineFileSource;
const std::shared_ptr<FileSource> maptilerFileSource;
const std::shared_ptr<FileSource> mbtilesFileSource;
std::map<AsyncRequest*, std::unique_ptr<AsyncRequest>> tasks;
};

Expand All @@ -138,12 +138,12 @@ class MainResourceLoader::Impl {
std::shared_ptr<FileSource> databaseFileSource_,
std::shared_ptr<FileSource> localFileSource_,
std::shared_ptr<FileSource> onlineFileSource_,
std::shared_ptr<FileSource> maptilerFileSource_)
std::shared_ptr<FileSource> 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::Thread<MainResourceLoaderThread>>(
util::makeThreadPrioritySetter(platform::EXPERIMENTAL_THREAD_PRIORITY_WORKER),
Expand All @@ -152,7 +152,7 @@ class MainResourceLoader::Impl {
databaseFileSource,
localFileSource,
onlineFileSource,
maptilerFileSource)),
mbtilesFileSource)),
resourceOptions (options.clone()) {}

std::unique_ptr<AsyncRequest> request(const Resource& resource, Callback callback) {
Expand All @@ -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_; }
Expand All @@ -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() {
Expand All @@ -199,7 +199,7 @@ class MainResourceLoader::Impl {
const std::shared_ptr<FileSource> databaseFileSource;
const std::shared_ptr<FileSource> localFileSource;
const std::shared_ptr<FileSource> onlineFileSource;
const std::shared_ptr<FileSource> maptilerFileSource;
const std::shared_ptr<FileSource> mbtilesFileSource;
const bool supportsCacheOnlyRequests_;
const std::unique_ptr<util::Thread<MainResourceLoaderThread>> thread;
mutable std::mutex resourceOptionsMutex;
Expand Down
23 changes: 10 additions & 13 deletions platform/default/src/mbgl/storage/mbtiles_file_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,15 @@
#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);
}
} // namespace

namespace mbgl {
using namespace rapidjson;
//using namespace mapbox::sqlite;

class MaptilerFileSource::Impl {
class MBTilesFileSource::Impl {
public:
explicit Impl(const ActorRef<Impl>&, const ResourceOptions& options): resourceOptions (options.clone()) {}

Expand Down Expand Up @@ -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<char>::length(util::MBTILES_PROTOCOL)));
}

std::string db_path(const std::string &path) {
Expand Down Expand Up @@ -265,19 +262,19 @@ class MaptilerFileSource::Impl {
};


MaptilerFileSource::MaptilerFileSource(const ResourceOptions& options) :
MBTilesFileSource::MBTilesFileSource(const ResourceOptions& options) :
thread(std::make_unique<util::Thread<Impl>>(
util::makeThreadPrioritySetter(platform::EXPERIMENTAL_THREAD_PRIORITY_FILE), "MaptilerFileSource", options.clone())) {}
util::makeThreadPrioritySetter(platform::EXPERIMENTAL_THREAD_PRIORITY_FILE), "MBTilesFileSource", options.clone())) {}


std::unique_ptr<AsyncRequest> MaptilerFileSource::request(const Resource &resource, FileSource::Callback callback) {
std::unique_ptr<AsyncRequest> MBTilesFileSource::request(const Resource &resource, FileSource::Callback callback) {
auto req = std::make_unique<FileSourceRequest>(std::move(callback));

if (resource.url.find(":///") == std::string::npos) {
Response response;
response.noContent = true;
response.error = std::make_unique<Response::Error>(Response::Error::Reason::Other,
"MaptilerFileSource only supports absolute path urls");
"MBTilesFileSource only supports absolute path urls");
req->actor().invoke(&FileSourceRequest::setResponse, response);

} else {
Expand All @@ -290,17 +287,17 @@ std::unique_ptr<AsyncRequest> 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();
}

Expand Down
16 changes: 5 additions & 11 deletions src/mbgl/storage/mbtiles_file_source.hpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
#pragma once

#include <mbgl/storage/file_source.hpp>
#include <mbgl/util/logging.hpp>
#include <mbgl/util/thread.hpp>
#include <mbgl/storage/resource_options.hpp>

#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 <AsyncRequest> request(const Resource &, Callback) override;

//static bool acceptsURL(const std::string &url);
bool canRequest(const Resource&) const override;

void setResourceOptions(ResourceOptions) override;
Expand All @@ -28,6 +25,3 @@ class MaptilerFileSource : public FileSource {
};

} // namespace mbgl


#endif //MBGL_MAPTILER_FILE_SOURCE_H

0 comments on commit 539d81a

Please sign in to comment.