summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLStyleLayerManager.mm
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2018-11-12 17:22:54 +0200
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2018-11-19 22:31:20 +0200
commit8077055b1ad5bb7324b81c9b199176124240237b (patch)
tree715e92591a4187469614f726566eaeefe2757e15 /platform/darwin/src/MGLStyleLayerManager.mm
parent8ac87ec5cb2374d212a31942ca19ce395704eb69 (diff)
downloadqtlocation-mapboxgl-8077055b1ad5bb7324b81c9b199176124240237b.tar.gz
[ios, macos] Layer manager for Darwin platforms
The newly introduced `MGLStyleLayerManager` is now responsible for creating both style layer objects and their obj C peers on Darwin.
Diffstat (limited to 'platform/darwin/src/MGLStyleLayerManager.mm')
-rw-r--r--platform/darwin/src/MGLStyleLayerManager.mm84
1 files changed, 84 insertions, 0 deletions
diff --git a/platform/darwin/src/MGLStyleLayerManager.mm b/platform/darwin/src/MGLStyleLayerManager.mm
new file mode 100644
index 0000000000..2cb919dd9d
--- /dev/null
+++ b/platform/darwin/src/MGLStyleLayerManager.mm
@@ -0,0 +1,84 @@
+#import "MGLStyleLayerManager.h"
+
+#import "MGLBackgroundStyleLayer_Private.h"
+#import "MGLCircleStyleLayer_Private.h"
+#import "MGLFillExtrusionStyleLayer_Private.h"
+#import "MGLFillStyleLayer_Private.h"
+#import "MGLHeatmapStyleLayer_Private.h"
+#import "MGLHillshadeStyleLayer_Private.h"
+#import "MGLLineStyleLayer_Private.h"
+#import "MGLRasterStyleLayer_Private.h"
+#import "MGLSymbolStyleLayer_Private.h"
+#import "MGLOpenGLStyleLayer_Private.h"
+
+#include <vector>
+
+namespace mbgl {
+
+LayerManagerDarwin::LayerManagerDarwin() {
+ addLayerType(std::make_unique<FillStyleLayerPeerFactory>());
+ addLayerType(std::make_unique<LineStyleLayerPeerFactory>());
+ addLayerType(std::make_unique<CircleStyleLayerPeerFactory>());
+ addLayerType(std::make_unique<SymbolStyleLayerPeerFactory>());
+ addLayerType(std::make_unique<RasterStyleLayerPeerFactory>());
+ addLayerType(std::make_unique<BackgroundStyleLayerPeerFactory>());
+ addLayerType(std::make_unique<HillshadeStyleLayerPeerFactory>());
+ addLayerType(std::make_unique<FillExtrusionStyleLayerPeerFactory>());
+ addLayerType(std::make_unique<HeatmapStyleLayerPeerFactory>());
+ addLayerType(std::make_unique<OpenGLStyleLayerPeerFactory>());
+}
+
+LayerManagerDarwin::~LayerManagerDarwin() = default;
+
+MGLStyleLayer* LayerManagerDarwin::createPeer(style::Layer* layer) {
+ auto* typeInfo = layer->getTypeInfo();
+ assert(typeInfo);
+ for (const auto& factory: factories) {
+ if (factory->getCoreLayerFactory()->getTypeInfo() == typeInfo) {
+ return factory->createPeer(layer);
+ }
+ }
+ assert(false);
+ return nullptr;
+}
+
+void LayerManagerDarwin::addLayerType(std::unique_ptr<LayerPeerFactory> factory) {
+ auto* coreFactory = factory->getCoreLayerFactory();
+ std::string type{coreFactory->getTypeInfo()->type};
+ if (!type.empty()) {
+ typeToFactory.emplace(std::make_pair(std::move(type), coreFactory));
+ }
+ factories.emplace_back(std::move(factory));
+}
+
+std::unique_ptr<style::Layer> LayerManagerDarwin::createLayer(const std::string& type,
+ const std::string& id,
+ const style::conversion::Convertible& value,
+ style::conversion::Error& error) noexcept {
+ auto search = typeToFactory.find(type);
+ if (search != typeToFactory.end()) {
+ auto layer = search->second->createLayer(id, value);
+ if (!layer) {
+ error.message = "Error parsing a layer of type: " + type;
+ }
+ return layer;
+ }
+ error.message = "Unsupported layer type: " + type;
+ return nullptr;
+}
+
+// static
+LayerManagerDarwin* LayerManagerDarwin::get() noexcept {
+ static LayerManagerDarwin impl;
+ return &impl;
+}
+
+namespace style {
+
+// static
+LayerManager* LayerManager::get() noexcept {
+ return LayerManagerDarwin::get();
+}
+
+} // namespace style
+} // namespace mbgl