blob: a05e24bd9db75b2192ccc667486cec100fdeadc1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
#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) {
if (auto* factory = getPeerFactory(layer->getTypeInfo())) {
return factory->createPeer(layer);
}
return nullptr;
}
void LayerManagerDarwin::addLayerType(std::unique_ptr<LayerPeerFactory> factory) {
NSCAssert(getFactory(factory->getCoreLayerFactory()->getTypeInfo()) == nullptr,
@"A layer factory with the given info is already added.");
registerCoreFactory(factory->getCoreLayerFactory());
peerFactories.emplace_back(std::move(factory));
}
void LayerManagerDarwin::addLayerTypeCoreOnly(std::unique_ptr<LayerFactory> factory) {
NSCAssert(getFactory(factory->getTypeInfo()) == nullptr,
@"A layer factory with the given info is already added.");
registerCoreFactory(factory.get());
coreFactories.emplace_back(std::move(factory));
}
void LayerManagerDarwin::registerCoreFactory(LayerFactory* factory) {
std::string type{factory->getTypeInfo()->type};
if (!type.empty()) {
NSCAssert(typeToFactory.find(type) == typeToFactory.end(), @"A layer type can be registered only once.");
typeToFactory.emplace(std::make_pair(std::move(type), factory));
}
}
LayerPeerFactory* LayerManagerDarwin::getPeerFactory(const mbgl::style::LayerTypeInfo* typeInfo) {
for (const auto& factory: peerFactories) {
if (factory->getCoreLayerFactory()->getTypeInfo() == typeInfo) {
return factory.get();
}
}
return nullptr;
}
LayerFactory* LayerManagerDarwin::getFactory(const std::string& type) noexcept {
auto search = typeToFactory.find(type);
return (search != typeToFactory.end()) ? search->second : nullptr;
}
LayerFactory* LayerManagerDarwin::getFactory(const mbgl::style::LayerTypeInfo* info) noexcept {
if (LayerPeerFactory* peerFactory = getPeerFactory(info)) {
return peerFactory->getCoreLayerFactory();
}
for (const auto& factory: coreFactories) {
if (factory->getTypeInfo() == info) {
return factory.get();
}
}
return nullptr;
}
// static
LayerManagerDarwin* LayerManagerDarwin::get() noexcept {
static LayerManagerDarwin impl;
return &impl;
}
// static
LayerManager* LayerManager::get() noexcept {
return LayerManagerDarwin::get();
}
const bool LayerManager::annotationsEnabled = true;
} // namespace mbgl
|