summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLStyleLayerManager.mm
diff options
context:
space:
mode:
authorMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2018-12-17 16:03:38 +0200
committerMikhail Pozdnyakov <mikhail.pozdnyakov@mapbox.com>2018-12-18 18:57:16 +0200
commita408b2f5d5708e4b9fb7a870b4b58cd96eee9609 (patch)
tree1da7cfcda6c695a30bf00bb67d7b22655df2f991 /platform/darwin/src/MGLStyleLayerManager.mm
parentfbe7874db50e343740f3d065a8c06e7ceb07002e (diff)
downloadqtlocation-mapboxgl-a408b2f5d5708e4b9fb7a870b4b58cd96eee9609.tar.gz
[mac, ios] Enable core-only layers
`LayerManagerDarwin` can add layer types that are enabled only for JSON style. It allows to exclude the SDK wrappers for these layers from the project and decrease binary size.
Diffstat (limited to 'platform/darwin/src/MGLStyleLayerManager.mm')
-rw-r--r--platform/darwin/src/MGLStyleLayerManager.mm38
1 files changed, 29 insertions, 9 deletions
diff --git a/platform/darwin/src/MGLStyleLayerManager.mm b/platform/darwin/src/MGLStyleLayerManager.mm
index bdcc303de5..a05e24bd9d 100644
--- a/platform/darwin/src/MGLStyleLayerManager.mm
+++ b/platform/darwin/src/MGLStyleLayerManager.mm
@@ -38,22 +38,33 @@ MGLStyleLayer* LayerManagerDarwin::createPeer(style::Layer* layer) {
}
void LayerManagerDarwin::addLayerType(std::unique_ptr<LayerPeerFactory> factory) {
- auto* coreFactory = factory->getCoreLayerFactory();
- std::string type{coreFactory->getTypeInfo()->type};
+ 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()) {
- typeToFactory.emplace(std::make_pair(std::move(type), coreFactory));
+ NSCAssert(typeToFactory.find(type) == typeToFactory.end(), @"A layer type can be registered only once.");
+ typeToFactory.emplace(std::make_pair(std::move(type), factory));
}
- factories.emplace_back(std::move(factory));
}
LayerPeerFactory* LayerManagerDarwin::getPeerFactory(const mbgl::style::LayerTypeInfo* typeInfo) {
- assert(typeInfo);
- for (const auto& factory: factories) {
+ for (const auto& factory: peerFactories) {
if (factory->getCoreLayerFactory()->getTypeInfo() == typeInfo) {
return factory.get();
}
}
- assert(false);
return nullptr;
}
@@ -63,8 +74,17 @@ LayerFactory* LayerManagerDarwin::getFactory(const std::string& type) noexcept {
}
LayerFactory* LayerManagerDarwin::getFactory(const mbgl::style::LayerTypeInfo* info) noexcept {
- LayerPeerFactory* peerFactory = getPeerFactory(info);
- return (peerFactory != nullptr) ? peerFactory->getCoreLayerFactory() : nullptr;
+ if (LayerPeerFactory* peerFactory = getPeerFactory(info)) {
+ return peerFactory->getCoreLayerFactory();
+ }
+
+ for (const auto& factory: coreFactories) {
+ if (factory->getTypeInfo() == info) {
+ return factory.get();
+ }
+ }
+
+ return nullptr;
}
// static