* [core] Introduce FileSourceManager and use it for default platform impl
- Add `FileSourceManager` interface that provides access to `FileSource`
instances and means of registering / unregistering `FileSource` factories
- Split `DefaultFileSource` into smaller parts
- Add `DatabaseFileSource` interface and it's default implementation
- Remove inter-dependencies between concrete `FileSource` classes
* [build] Add files to next build system
* [core] Add generic property setters / getters
* [core] Remove setOnlineStatus from OnlineFileSource interface
* [core] Hide threading implementation details from DatabaseFileSource interface
* [core] Make DB file source methods virtual
* [core] Add documentation for DatabaseFileSource and rename one method
* [core] Use simple callback instead of ActorRef
* [core] Remove ActorRef from OnlineFileSource public header
* [core] Add callback to FileSource::forward async API
* [core] Pass OfflineRegionDefinition by value
* [core] Update tests to use modular file sources
* [core] Update unit tests
* [core] Update unit tests after rebase
* [core] Backport low prio fix for cached requests
* [core] Backport pack database
* [core] Return removed factory from unRegisterFileSourceFactory
* [core] Rename shadowed args in onlinefilesource
* [core] Remove simple std::function callback aliases
* [core] Expose online file source property keys in public header file
* [test-runner] Add proxy file source test runner
* [cache] Update mbgl-cache utility to use new file source
* [metrics] Rebaseline binary size metrics
* [offline] Update offline utility
* [core] Update changelog
96 lines
3.1 KiB
C++
96 lines
3.1 KiB
C++
#include <mbgl/storage/file_source.hpp>
|
|
#include <mbgl/style/conversion/json.hpp>
|
|
#include <mbgl/style/conversion/tileset.hpp>
|
|
#include <mbgl/style/layer.hpp>
|
|
#include <mbgl/style/source_observer.hpp>
|
|
#include <mbgl/style/sources/vector_source.hpp>
|
|
#include <mbgl/style/sources/vector_source_impl.hpp>
|
|
#include <mbgl/tile/tile.hpp>
|
|
#include <mbgl/util/async_request.hpp>
|
|
#include <mbgl/util/constants.hpp>
|
|
#include <mbgl/util/exception.hpp>
|
|
#include <mbgl/util/mapbox.hpp>
|
|
|
|
namespace mbgl {
|
|
namespace style {
|
|
|
|
VectorSource::VectorSource(std::string id, variant<std::string, Tileset> urlOrTileset_, optional<float> maxZoom_,
|
|
optional<float> minZoom_)
|
|
: Source(makeMutable<Impl>(std::move(id))),
|
|
urlOrTileset(std::move(urlOrTileset_)),
|
|
maxZoom(std::move(maxZoom_)),
|
|
minZoom(std::move(minZoom_)) {}
|
|
|
|
VectorSource::~VectorSource() = default;
|
|
|
|
const VectorSource::Impl& VectorSource::impl() const {
|
|
return static_cast<const Impl&>(*baseImpl);
|
|
}
|
|
|
|
const variant<std::string, Tileset>& VectorSource::getURLOrTileset() const {
|
|
return urlOrTileset;
|
|
}
|
|
|
|
optional<std::string> VectorSource::getURL() const {
|
|
if (urlOrTileset.is<Tileset>()) {
|
|
return {};
|
|
}
|
|
|
|
return urlOrTileset.get<std::string>();
|
|
}
|
|
|
|
void VectorSource::loadDescription(FileSource& fileSource) {
|
|
if (urlOrTileset.is<Tileset>()) {
|
|
baseImpl = makeMutable<Impl>(impl(), urlOrTileset.get<Tileset>());
|
|
loaded = true;
|
|
observer->onSourceLoaded(*this);
|
|
return;
|
|
}
|
|
|
|
if (req) {
|
|
return;
|
|
}
|
|
|
|
const auto& url = urlOrTileset.get<std::string>();
|
|
req = fileSource.request(Resource::source(url), [this, url](Response res) {
|
|
if (res.error) {
|
|
observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error(res.error->message)));
|
|
} else if (res.notModified) {
|
|
return;
|
|
} else if (res.noContent) {
|
|
observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error("unexpectedly empty TileJSON")));
|
|
} else {
|
|
conversion::Error error;
|
|
optional<Tileset> tileset = conversion::convertJSON<Tileset>(*res.data, error);
|
|
if (!tileset) {
|
|
observer->onSourceError(*this, std::make_exception_ptr(util::StyleParseException(error.message)));
|
|
return;
|
|
}
|
|
if (maxZoom) {
|
|
tileset->zoomRange.max = *maxZoom;
|
|
}
|
|
if (minZoom) {
|
|
tileset->zoomRange.min = *minZoom;
|
|
}
|
|
util::mapbox::canonicalizeTileset(*tileset, url, getType(), util::tileSize);
|
|
bool changed = impl().tileset != *tileset;
|
|
|
|
baseImpl = makeMutable<Impl>(impl(), *tileset);
|
|
loaded = true;
|
|
|
|
observer->onSourceLoaded(*this);
|
|
|
|
if (changed) {
|
|
observer->onSourceChanged(*this);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
bool VectorSource::supportsLayerType(const mbgl::style::LayerTypeInfo* info) const {
|
|
return mbgl::underlying_type(Tile::Kind::Geometry) == mbgl::underlying_type(info->tileKind);
|
|
}
|
|
|
|
} // namespace style
|
|
} // namespace mbgl
|