diff options
Diffstat (limited to 'src/mbgl/map')
-rw-r--r-- | src/mbgl/map/map.cpp | 70 | ||||
-rw-r--r-- | src/mbgl/map/map_impl.cpp | 62 | ||||
-rw-r--r-- | src/mbgl/map/map_impl.hpp | 29 | ||||
-rw-r--r-- | src/mbgl/map/map_options.cpp | 45 |
4 files changed, 96 insertions, 110 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index f545fc8095..b22a9ee2f2 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -27,24 +27,16 @@ namespace mbgl { using namespace style; -Map::Map(RendererFrontend& rendererFrontend, - MapObserver& mapObserver, - const Size size, - const float pixelRatio, - FileSource& fileSource, +Map::Map(RendererFrontend& frontend, + MapObserver& observer, Scheduler& scheduler, - const MapOptions& options) - : impl(std::make_unique<Impl>(*this, - rendererFrontend, - mapObserver, - fileSource, - scheduler, - size, - pixelRatio, - options.mapMode(), - options.constrainMode(), - options.viewportMode(), - options.crossSourceCollisions())) {} + const MapOptions& mapOptions, + const ResourceOptions& resourceOptions) + : impl(std::make_unique<Impl>(frontend, observer, scheduler, + FileSource::getSharedFileSource(resourceOptions), + mapOptions)) {} + +Map::Map(std::unique_ptr<Impl> impl_) : impl(std::move(impl_)) {} Map::~Map() = default; @@ -139,9 +131,7 @@ CameraOptions Map::getCameraOptions(const EdgeInsets& padding) const { } void Map::jumpTo(const CameraOptions& camera) { - impl->cameraMutated = true; - impl->transform.jumpTo(camera); - impl->onUpdate(); + impl->jumpTo(camera); } void Map::easeTo(const CameraOptions& camera, const AnimationOptions& animation) { @@ -214,8 +204,13 @@ CameraOptions cameraForLatLngs(const std::vector<LatLng>& latLngs, const Transfo scaleY -= (padding.top() + padding.bottom()) / height; minScale = util::min(scaleX, scaleY); } - double zoom = transform.getZoom() + util::log2(minScale); - zoom = util::clamp(zoom, transform.getState().getMinZoom(), transform.getState().getMaxZoom()); + + double zoom = transform.getZoom(); + if (minScale > 0) { + zoom = util::clamp(zoom + util::log2(minScale), transform.getState().getMinZoom(), transform.getState().getMaxZoom()); + } else { + Log::Error(Event::General, "Unable to calculate appropriate zoom level for bounds. Vertical or horizontal padding is greater than map's height or width."); + } // Calculate the center point of a virtual bounds that is extended in all directions by padding. ScreenCoordinate centerPixel = nePixel + swPixel; @@ -312,48 +307,37 @@ BoundOptions Map::getBounds() const { .withMaxZoom(impl->transform.getState().getMaxZoom()); } -#pragma mark - Size +#pragma mark - Map options void Map::setSize(const Size size) { impl->transform.resize(size); impl->onUpdate(); } -Size Map::getSize() const { - return impl->transform.getState().getSize(); -} - -#pragma mark - North Orientation - void Map::setNorthOrientation(NorthOrientation orientation) { impl->transform.setNorthOrientation(orientation); impl->onUpdate(); } -NorthOrientation Map::getNorthOrientation() const { - return impl->transform.getNorthOrientation(); -} - -#pragma mark - Constrain mode - void Map::setConstrainMode(mbgl::ConstrainMode mode) { impl->transform.setConstrainMode(mode); impl->onUpdate(); } -ConstrainMode Map::getConstrainMode() const { - return impl->transform.getConstrainMode(); -} - -#pragma mark - Viewport mode - void Map::setViewportMode(mbgl::ViewportMode mode) { impl->transform.setViewportMode(mode); impl->onUpdate(); } -ViewportMode Map::getViewportMode() const { - return impl->transform.getViewportMode(); +MapOptions Map::getMapOptions() const { + return std::move(MapOptions() + .withMapMode(impl->mode) + .withConstrainMode(impl->transform.getConstrainMode()) + .withViewportMode(impl->transform.getViewportMode()) + .withCrossSourceCollisions(impl->crossSourceCollisions) + .withNorthOrientation(impl->transform.getNorthOrientation()) + .withSize(impl->transform.getState().getSize()) + .withPixelRatio(impl->pixelRatio)); } #pragma mark - Projection mode diff --git a/src/mbgl/map/map_impl.cpp b/src/mbgl/map/map_impl.cpp index 84cf324722..1ec7255822 100644 --- a/src/mbgl/map/map_impl.cpp +++ b/src/mbgl/map/map_impl.cpp @@ -1,39 +1,31 @@ #include <mbgl/layermanager/layer_manager.hpp> #include <mbgl/map/map_impl.hpp> #include <mbgl/renderer/update_parameters.hpp> +#include <mbgl/storage/file_source.hpp> #include <mbgl/style/style_impl.hpp> #include <mbgl/util/exception.hpp> namespace mbgl { -Map::Impl::Impl(Map& map_, - RendererFrontend& frontend, - MapObserver& mapObserver, - FileSource& fileSource_, +Map::Impl::Impl(RendererFrontend& frontend_, + MapObserver& observer_, Scheduler& scheduler_, - Size size_, - float pixelRatio_, - MapMode mode_, - ConstrainMode constrainMode_, - ViewportMode viewportMode_, - bool crossSourceCollisions_) - : map(map_), - observer(mapObserver), - rendererFrontend(frontend), - fileSource(fileSource_), - scheduler(scheduler_), - transform(observer, - constrainMode_, - viewportMode_), - mode(mode_), - pixelRatio(pixelRatio_), - crossSourceCollisions(crossSourceCollisions_), - style(std::make_unique<style::Style>(scheduler, fileSource, pixelRatio)), - annotationManager(*style) { - + std::shared_ptr<FileSource> fileSource_, + const MapOptions& mapOptions) + : observer(observer_), + rendererFrontend(frontend_), + scheduler(scheduler_), + transform(observer, mapOptions.constrainMode(), mapOptions.viewportMode()), + mode(mapOptions.mapMode()), + pixelRatio(mapOptions.pixelRatio()), + crossSourceCollisions(mapOptions.crossSourceCollisions()), + fileSource(std::move(fileSource_)), + style(std::make_unique<style::Style>(scheduler, *fileSource, pixelRatio)), + annotationManager(*style) { + transform.setNorthOrientation(mapOptions.northOrientation()); style->impl->setObserver(this); rendererFrontend.setObserver(*this); - transform.resize(size_); + transform.resize(mapOptions.size()); } Map::Impl::~Impl() { @@ -73,7 +65,7 @@ void Map::Impl::onUpdate() { style->impl->getSourceImpls(), style->impl->getLayerImpls(), annotationManager, - fileSource, + *fileSource, prefetchZoomDelta, bool(stillImageRequest), crossSourceCollisions @@ -90,7 +82,7 @@ void Map::Impl::onStyleLoading() { void Map::Impl::onStyleLoaded() { if (!cameraMutated) { - map.jumpTo(style->getDefaultCamera()); + jumpTo(style->getDefaultCamera()); } if (LayerManager::annotationsEnabled) { annotationManager.onStyleLoaded(); @@ -173,4 +165,20 @@ void Map::Impl::onDidFinishRenderingMap() { } }; +void Map::Impl::jumpTo(const CameraOptions& camera) { + cameraMutated = true; + transform.jumpTo(camera); + onUpdate(); +} + +void Map::Impl::onStyleImageMissing(const std::string& id, std::function<void()> done) { + + if (style->getImage(id) == nullptr) { + observer.onStyleImageMissing(id); + } + + done(); + onUpdate(); +} + } // namespace mbgl diff --git a/src/mbgl/map/map_impl.hpp b/src/mbgl/map/map_impl.hpp index 32dc728b70..f233f78275 100644 --- a/src/mbgl/map/map_impl.hpp +++ b/src/mbgl/map/map_impl.hpp @@ -1,14 +1,15 @@ #pragma once +#include <mbgl/actor/actor.hpp> #include <mbgl/actor/scheduler.hpp> #include <mbgl/annotation/annotation_manager.hpp> #include <mbgl/map/map.hpp> #include <mbgl/map/map_observer.hpp> +#include <mbgl/map/map_options.hpp> #include <mbgl/map/mode.hpp> #include <mbgl/map/transform.hpp> #include <mbgl/renderer/renderer_frontend.hpp> #include <mbgl/renderer/renderer_observer.hpp> -#include <mbgl/storage/file_source.hpp> #include <mbgl/style/observer.hpp> #include <mbgl/style/source.hpp> #include <mbgl/style/style.hpp> @@ -16,6 +17,9 @@ namespace mbgl { +class FileSource; +class ResourceTransform; + struct StillImageRequest { StillImageRequest(Map::StillImageCallback&& callback_) : callback(std::move(callback_)) { @@ -26,20 +30,7 @@ struct StillImageRequest { class Map::Impl : public style::Observer, public RendererObserver { public: - Impl(Map&, - RendererFrontend&, - MapObserver&, - FileSource&, - Scheduler&, - - Size size, - float pixelRatio, - - MapMode, - ConstrainMode, - ViewportMode, - bool crossSourceCollisions); - + Impl(RendererFrontend&, MapObserver&, Scheduler&, std::shared_ptr<FileSource>, const MapOptions&); ~Impl() final; // StyleObserver @@ -56,11 +47,13 @@ public: void onDidFinishRenderingFrame(RenderMode, bool) final; void onWillStartRenderingMap() final; void onDidFinishRenderingMap() final; + void onStyleImageMissing(const std::string&, std::function<void()>) final; + + // Map + void jumpTo(const CameraOptions&); - Map& map; MapObserver& observer; RendererFrontend& rendererFrontend; - FileSource& fileSource; Scheduler& scheduler; Transform transform; @@ -71,6 +64,8 @@ public: MapDebugOptions debugOptions { MapDebugOptions::NoDebug }; + std::shared_ptr<FileSource> fileSource; + std::unique_ptr<style::Style> style; AnnotationManager annotationManager; diff --git a/src/mbgl/map/map_options.cpp b/src/mbgl/map/map_options.cpp index 118fcaf3df..4cebb6adab 100644 --- a/src/mbgl/map/map_options.cpp +++ b/src/mbgl/map/map_options.cpp @@ -1,7 +1,4 @@ #include <mbgl/map/map_options.hpp> -#include <mbgl/util/constants.hpp> - -#include <cassert> namespace mbgl { @@ -10,14 +7,16 @@ public: MapMode mapMode = MapMode::Continuous; ConstrainMode constrainMode = ConstrainMode::HeightOnly; ViewportMode viewportMode = ViewportMode::Default; - std::string cachePath; - std::string assetRoot; - uint64_t maximumSize{mbgl::util::DEFAULT_MAX_CACHE_SIZE}; + NorthOrientation orientation = NorthOrientation::Upwards; bool crossSourceCollisions = true; + Size size = { 64, 64 }; + float pixelRatio = 1.0; }; -MapOptions::MapOptions() : impl_(std::make_shared<MapOptions::Impl>()) {} +// These requires the complete type of Impl. +MapOptions::MapOptions() : impl_(std::make_unique<Impl>()) {} MapOptions::~MapOptions() = default; +MapOptions::MapOptions(MapOptions&&) noexcept = default; MapOptions& MapOptions::withMapMode(MapMode mode) { impl_->mapMode = mode; @@ -46,40 +45,40 @@ ViewportMode MapOptions::viewportMode() const { return impl_->viewportMode; } -MapOptions& MapOptions::withCachePath(std::string path) { - impl_->cachePath = std::move(path); +MapOptions& MapOptions::withCrossSourceCollisions(bool enableCollisions) { + impl_->crossSourceCollisions = enableCollisions; return *this; } -const std::string& MapOptions::cachePath() const { - return impl_->cachePath; +bool MapOptions::crossSourceCollisions() const { + return impl_->crossSourceCollisions; } -MapOptions& MapOptions::withAssetRoot(std::string path) { - impl_->assetRoot = std::move(path); +MapOptions& MapOptions::withNorthOrientation(NorthOrientation orientation) { + impl_->orientation = orientation; return *this; } -const std::string& MapOptions::assetRoot() const { - return impl_->assetRoot; +NorthOrientation MapOptions::northOrientation() const { + return impl_->orientation; } -MapOptions& MapOptions::withMaximumCacheSize(uint64_t size) { - impl_->maximumSize = size; +MapOptions& MapOptions::withSize(Size size_) { + impl_->size = size_; return *this; } -uint64_t MapOptions::maximumCacheSize() const { - return impl_->maximumSize; +Size MapOptions::size() const { + return impl_->size; } -MapOptions& MapOptions::withCrossSourceCollisions(bool enableCollisions) { - impl_->crossSourceCollisions = enableCollisions; +MapOptions& MapOptions::withPixelRatio(float ratio) { + impl_->pixelRatio = ratio; return *this; } -bool MapOptions::crossSourceCollisions() const { - return impl_->crossSourceCollisions; +float MapOptions::pixelRatio() const { + return impl_->pixelRatio; } } // namespace mbgl |