Add Initial PMTiles support (#2882)
Co-authored-by: Bart Louwers <bart.louwers@gmail.com>
This commit is contained in:
29
src/mbgl/storage/pmtiles_file_source.hpp
Normal file
29
src/mbgl/storage/pmtiles_file_source.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/storage/file_source.hpp>
|
||||
#include <mbgl/storage/resource_options.hpp>
|
||||
#include <mbgl/util/client_options.hpp>
|
||||
#include <mbgl/util/thread.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
// File source for supporting .pmtiles maps
|
||||
class PMTilesFileSource : public FileSource {
|
||||
public:
|
||||
PMTilesFileSource(const ResourceOptions& resourceOptions, const ClientOptions& clientOptions);
|
||||
~PMTilesFileSource() override;
|
||||
|
||||
std::unique_ptr<AsyncRequest> request(const Resource&, Callback) override;
|
||||
bool canRequest(const Resource&) const override;
|
||||
|
||||
void setResourceOptions(ResourceOptions) override;
|
||||
ResourceOptions getResourceOptions() override;
|
||||
|
||||
void setClientOptions(ClientOptions) override;
|
||||
ClientOptions getClientOptions() override;
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::unique_ptr<util::Thread<Impl>> thread; // impl
|
||||
};
|
||||
|
||||
} // namespace mbgl
|
||||
@@ -46,14 +46,23 @@ std::string read_file(const std::string &filename) {
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<std::string> readFile(const std::string &filename) {
|
||||
std::optional<std::string> readFile(const std::string &filename,
|
||||
const std::optional<std::pair<uint64_t, uint64_t>> &dataRange) {
|
||||
MLN_TRACE_FUNC();
|
||||
|
||||
std::ifstream file(filename, std::ios::binary);
|
||||
if (file.good()) {
|
||||
std::stringstream data;
|
||||
data << file.rdbuf();
|
||||
return data.str();
|
||||
if (dataRange) {
|
||||
size_t size = static_cast<size_t>(dataRange->second - dataRange->first + 1);
|
||||
std::string data(size, '\0');
|
||||
file.seekg(static_cast<std::streampos>(dataRange->first));
|
||||
file.read(&data[0], static_cast<std::streamsize>(size));
|
||||
return data;
|
||||
} else {
|
||||
std::stringstream data;
|
||||
data << file.rdbuf();
|
||||
return data.str();
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <optional>
|
||||
@@ -15,7 +16,8 @@ struct IOException : std::runtime_error {
|
||||
void write_file(const std::string& filename, const std::string& data);
|
||||
std::string read_file(const std::string& filename);
|
||||
|
||||
std::optional<std::string> readFile(const std::string& filename);
|
||||
std::optional<std::string> readFile(const std::string& filename,
|
||||
const std::optional<std::pair<uint64_t, uint64_t>>& dataRange = std::nullopt);
|
||||
void deleteFile(const std::string& filename);
|
||||
void copyFile(const std::string& destination, const std::string& source);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user