diff options
Diffstat (limited to 'src/mbgl/map')
-rw-r--r-- | src/mbgl/map/map.cpp | 28 | ||||
-rw-r--r-- | src/mbgl/map/map_impl.cpp | 46 | ||||
-rw-r--r-- | src/mbgl/map/map_impl.hpp | 19 |
3 files changed, 64 insertions, 29 deletions
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 061669f560..f48cd86680 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -33,7 +33,8 @@ Map::Map(RendererFrontend& frontend, : impl(std::make_unique<Impl>( frontend, observer, - FileSourceManager::get() ? FileSourceManager::get()->getFileSource(ResourceLoader, resourceOptions) : nullptr, +// FileSourceManager::get() ? FileSourceManager::get()->getFileSource(ResourceLoader, resourceOptions) : nullptr, + resourceOptions, mapOptions)) {} Map::Map(std::unique_ptr<Impl> impl_) : impl(std::move(impl_)) {} @@ -87,13 +88,14 @@ const style::Style& Map::getStyle() const { return *impl->style; } -void Map::setStyle(std::unique_ptr<Style> style) { +std::shared_ptr<Style> Map::getStylePointer() +{ + return impl->style; +} + +void Map::setStyle(const std::shared_ptr<Style>& style) { assert(style); - impl->onStyleLoading(); - impl->style = std::move(style); - if (LayerManager::annotationsEnabled) { - impl->annotationManager.setStyle(*impl->style); - } + impl->setStyle(style); } #pragma mark - Transitions @@ -399,26 +401,26 @@ std::vector<LatLng> Map::latLngsForPixels(const std::vector<ScreenCoordinate>& s void Map::addAnnotationImage(std::unique_ptr<style::Image> image) { if (LayerManager::annotationsEnabled) { - impl->annotationManager.addImage(std::move(image)); + impl->style->impl->annotationManager.addImage(std::move(image)); } } void Map::removeAnnotationImage(const std::string& id) { if (LayerManager::annotationsEnabled) { - impl->annotationManager.removeImage(id); + impl->style->impl->annotationManager.removeImage(id); } } double Map::getTopOffsetPixelsForAnnotationImage(const std::string& id) { if (LayerManager::annotationsEnabled) { - return impl->annotationManager.getTopOffsetPixelsForImage(id); + return impl->style->impl->annotationManager.getTopOffsetPixelsForImage(id); } return 0.0; } AnnotationID Map::addAnnotation(const Annotation& annotation) { if (LayerManager::annotationsEnabled) { - auto result = impl->annotationManager.addAnnotation(annotation); + auto result = impl->style->impl->annotationManager.addAnnotation(annotation); impl->onUpdate(); return result; } @@ -427,7 +429,7 @@ AnnotationID Map::addAnnotation(const Annotation& annotation) { void Map::updateAnnotation(AnnotationID id, const Annotation& annotation) { if (LayerManager::annotationsEnabled) { - if (impl->annotationManager.updateAnnotation(id, annotation)) { + if (impl->style->impl->annotationManager.updateAnnotation(id, annotation)) { impl->onUpdate(); } } @@ -435,7 +437,7 @@ void Map::updateAnnotation(AnnotationID id, const Annotation& annotation) { void Map::removeAnnotation(AnnotationID annotation) { if (LayerManager::annotationsEnabled) { - impl->annotationManager.removeAnnotation(annotation); + impl->style->impl->annotationManager.removeAnnotation(annotation); impl->onUpdate(); } } diff --git a/src/mbgl/map/map_impl.cpp b/src/mbgl/map/map_impl.cpp index af18720916..bdb6848794 100644 --- a/src/mbgl/map/map_impl.cpp +++ b/src/mbgl/map/map_impl.cpp @@ -9,7 +9,7 @@ namespace mbgl { Map::Impl::Impl(RendererFrontend& frontend_, MapObserver& observer_, - std::shared_ptr<FileSource> fileSource_, + const ResourceOptions &resourceOptions_, const MapOptions& mapOptions) : observer(observer_), rendererFrontend(frontend_), @@ -17,11 +17,27 @@ Map::Impl::Impl(RendererFrontend& frontend_, mode(mapOptions.mapMode()), pixelRatio(mapOptions.pixelRatio()), crossSourceCollisions(mapOptions.crossSourceCollisions()), - fileSource(std::move(fileSource_)), - style(std::make_unique<style::Style>(fileSource, pixelRatio)), - annotationManager(*style) { + style(std::make_shared<style::Style>(resourceOptions_, pixelRatio)) { + init(mapOptions); +} + +Map::Impl::Impl(RendererFrontend &frontend_, + MapObserver &observer_, + std::shared_ptr<FileSource> fileSource_, + const MapOptions &mapOptions) + : observer(observer_), + rendererFrontend(frontend_), + transform(observer, mapOptions.constrainMode(), mapOptions.viewportMode()), + mode(mapOptions.mapMode()), + pixelRatio(mapOptions.pixelRatio()), + crossSourceCollisions(mapOptions.crossSourceCollisions()), + style(std::make_shared<style::Style>(fileSource_, pixelRatio)) { + init(mapOptions); +} + +void Map::Impl::init(const MapOptions& mapOptions) { transform.setNorthOrientation(mapOptions.northOrientation()); - style->impl->setObserver(this); + style->impl->addObserver(this); rendererFrontend.setObserver(*this); transform.resize(mapOptions.size()); } @@ -62,8 +78,8 @@ void Map::Impl::onUpdate() { style->impl->getImageImpls(), style->impl->getSourceImpls(), style->impl->getLayerImpls(), - annotationManager, - fileSource, + style->impl->annotationManager, + style->impl->fileSource, prefetchZoomDelta, bool(stillImageRequest), crossSourceCollisions @@ -82,9 +98,7 @@ void Map::Impl::onStyleLoaded() { if (!cameraMutated) { jumpTo(style->getDefaultCamera()); } - if (LayerManager::annotationsEnabled) { - annotationManager.onStyleLoaded(); - } + observer.onDidFinishLoadingStyle(); } @@ -169,6 +183,18 @@ void Map::Impl::jumpTo(const CameraOptions& camera) { onUpdate(); } +void Map::Impl::setStyle(const std::shared_ptr<style::Style>& style_) +{ + onStyleLoading(); + style->impl->removeObserver(this); + style = style_; + style->impl->addObserver(this); + if (style->impl->isLoaded()) + onStyleLoaded(); + else if (style->impl->getLastError()) + onStyleError(style->impl->getLastError()); +} + void Map::Impl::onStyleImageMissing(const std::string& id, std::function<void()> done) { if (!style->getImage(id)) observer.onStyleImageMissing(id); diff --git a/src/mbgl/map/map_impl.hpp b/src/mbgl/map/map_impl.hpp index 416662f9e5..4cb0b63890 100644 --- a/src/mbgl/map/map_impl.hpp +++ b/src/mbgl/map/map_impl.hpp @@ -1,6 +1,5 @@ #pragma once -#include <mbgl/annotation/annotation_manager.hpp> #include <mbgl/map/map.hpp> #include <mbgl/map/map_observer.hpp> #include <mbgl/map/map_options.hpp> @@ -28,7 +27,14 @@ struct StillImageRequest { class Map::Impl : public style::Observer, public RendererObserver { public: - Impl(RendererFrontend&, MapObserver&, std::shared_ptr<FileSource>, const MapOptions&); + Impl(RendererFrontend&, + MapObserver&, + const ResourceOptions&, + const MapOptions&); + Impl(RendererFrontend&, + MapObserver&, + std::shared_ptr<FileSource>, + const MapOptions&); // Used in tests ~Impl() final; // StyleObserver @@ -50,6 +56,7 @@ public: // Map void jumpTo(const CameraOptions&); + void setStyle(const std::shared_ptr<style::Style>& style); MapObserver& observer; RendererFrontend& rendererFrontend; @@ -62,10 +69,7 @@ public: MapDebugOptions debugOptions { MapDebugOptions::NoDebug }; - std::shared_ptr<FileSource> fileSource; - - std::unique_ptr<style::Style> style; - AnnotationManager annotationManager; + std::shared_ptr<style::Style> style; bool cameraMutated = false; @@ -74,6 +78,9 @@ public: bool loading = false; bool rendererFullyLoaded; std::unique_ptr<StillImageRequest> stillImageRequest; + +private: + void init(const MapOptions&); }; } // namespace mbgl |