[core, ios, macos] Added layers and sources properties to MGLStyle
Added new layers and sources properties to MGLStyle that contain all the style’s layers and sources, respectively. These properties are KVC-compliant with all the mutable to-many methods. Layers are ordered from topmost to bottommost, for consistency with Cocoa APIs where front/first means top and back/last means bottom. Also added storage for mbgl::style::Source in MGLSource proper for wrapping AnnotationSource. Until the style finishes loading, its name property is set to nil. Fixes #6003.
This commit is contained in:
committed by
Minh Nguyễn
parent
f71dd14bb7
commit
850b70ff91
@@ -157,11 +157,13 @@ public:
|
||||
void removeAnnotation(AnnotationID);
|
||||
|
||||
// Sources
|
||||
std::vector<style::Source*> getSources();
|
||||
style::Source* getSource(const std::string& sourceID);
|
||||
void addSource(std::unique_ptr<style::Source>);
|
||||
std::unique_ptr<style::Source> removeSource(const std::string& sourceID);
|
||||
|
||||
// Layers
|
||||
std::vector<style::Layer*> getLayers();
|
||||
style::Layer* getLayer(const std::string& layerID);
|
||||
void addLayer(std::unique_ptr<style::Layer>, const optional<std::string>& beforeLayerID = {});
|
||||
std::unique_ptr<style::Layer> removeLayer(const std::string& layerID);
|
||||
|
||||
@@ -51,6 +51,9 @@
|
||||
- (void)removeFromMapView:(MGLMapView *)mapView
|
||||
{
|
||||
auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String);
|
||||
if (!removedLayer) {
|
||||
return;
|
||||
}
|
||||
_pendingLayer = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::BackgroundLayer> &>(removedLayer));
|
||||
_rawLayer = _pendingLayer.get();
|
||||
}
|
||||
|
||||
@@ -83,6 +83,9 @@ namespace mbgl {
|
||||
- (void)removeFromMapView:(MGLMapView *)mapView
|
||||
{
|
||||
auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String);
|
||||
if (!removedLayer) {
|
||||
return;
|
||||
}
|
||||
_pendingLayer = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::CircleLayer> &>(removedLayer));
|
||||
_rawLayer = _pendingLayer.get();
|
||||
}
|
||||
|
||||
@@ -78,6 +78,9 @@ namespace mbgl {
|
||||
- (void)removeFromMapView:(MGLMapView *)mapView
|
||||
{
|
||||
auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String);
|
||||
if (!removedLayer) {
|
||||
return;
|
||||
}
|
||||
_pendingLayer = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::FillLayer> &>(removedLayer));
|
||||
_rawLayer = _pendingLayer.get();
|
||||
}
|
||||
|
||||
@@ -90,6 +90,9 @@ namespace mbgl {
|
||||
- (void)removeFromMapView:(MGLMapView *)mapView
|
||||
{
|
||||
auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String);
|
||||
if (!removedLayer) {
|
||||
return;
|
||||
}
|
||||
_pendingLayer = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::LineLayer> &>(removedLayer));
|
||||
_rawLayer = _pendingLayer.get();
|
||||
}
|
||||
|
||||
@@ -50,6 +50,9 @@
|
||||
- (void)removeFromMapView:(MGLMapView *)mapView
|
||||
{
|
||||
auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String);
|
||||
if (!removedLayer) {
|
||||
return;
|
||||
}
|
||||
_pendingLayer = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::RasterLayer> &>(removedLayer));
|
||||
_rawLayer = _pendingLayer.get();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,14 @@
|
||||
|
||||
#include <mbgl/style/source.hpp>
|
||||
|
||||
@interface MGLSource ()
|
||||
|
||||
// Even though this class is abstract, MGLStyle uses it to represent some
|
||||
// special internal source types like mbgl::AnnotationSource.
|
||||
@property (nonatomic) mbgl::style::Source *rawSource;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MGLSource
|
||||
|
||||
- (instancetype)initWithIdentifier:(NSString *)identifier
|
||||
@@ -12,6 +20,20 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)addToMapView:(MGLMapView *)mapView {
|
||||
[NSException raise:NSInvalidArgumentException format:
|
||||
@"The source %@ cannot be added to the style. "
|
||||
@"Make sure the source was created as a member of a concrete subclass of MGLSource.",
|
||||
self];
|
||||
}
|
||||
|
||||
- (void)removeFromMapView:(MGLMapView *)mapView {
|
||||
[NSException raise:NSInvalidArgumentException format:
|
||||
@"The source %@ cannot be removed from the style. "
|
||||
@"Make sure the source was created as a member of a concrete subclass of MGLSource.",
|
||||
self];
|
||||
}
|
||||
|
||||
- (NSString *)description {
|
||||
return [NSString stringWithFormat:@"<%@: %p; identifier = %@>",
|
||||
NSStringFromClass([self class]), (void *)self, self.identifier];
|
||||
|
||||
@@ -176,6 +176,11 @@ static const NSInteger MGLStyleDefaultVersion = 9;
|
||||
|
||||
#pragma mark Managing Sources
|
||||
|
||||
/**
|
||||
A set containing the style’s sources.
|
||||
*/
|
||||
@property (nonatomic, strong) NS_MUTABLE_SET_OF(MGLSource *) *sources;
|
||||
|
||||
/**
|
||||
Returns a source with the given identifier in the current style.
|
||||
|
||||
@@ -200,6 +205,12 @@ static const NSInteger MGLStyleDefaultVersion = 9;
|
||||
|
||||
#pragma mark Managing Style Layers
|
||||
|
||||
/**
|
||||
The layers included in the style, arranged according to their front-to-back
|
||||
ordering on the screen.
|
||||
*/
|
||||
@property (nonatomic, strong) NS_MUTABLE_ARRAY_OF(MGLStyleLayer *) *layers;
|
||||
|
||||
/**
|
||||
Returns a style layer with the given identifier in the current style.
|
||||
|
||||
@@ -217,13 +228,31 @@ static const NSInteger MGLStyleDefaultVersion = 9;
|
||||
*/
|
||||
- (void)addLayer:(MGLStyleLayer *)layer;
|
||||
|
||||
/**
|
||||
Inserts a new layer into the style at the given index.
|
||||
|
||||
@param layer The layer to insert.
|
||||
@param index The index at which to insert the layer. An index of 0 would send
|
||||
the layer to the back; an index equal to the number of objects in the
|
||||
`layers` property would bring the layer to the front.
|
||||
*/
|
||||
- (void)insertLayer:(MGLStyleLayer *)layer atIndex:(NSUInteger)index;
|
||||
|
||||
/**
|
||||
Inserts a new layer below another layer.
|
||||
|
||||
@param layer Layer to be inserted.
|
||||
@param belowLayer A layer that's already on the map view.
|
||||
@param layer The layer to insert.
|
||||
@param sibling An existing layer in the style.
|
||||
*/
|
||||
- (void)insertLayer:(MGLStyleLayer *)layer belowLayer:(MGLStyleLayer *)otherLayer;
|
||||
- (void)insertLayer:(MGLStyleLayer *)layer belowLayer:(MGLStyleLayer *)sibling;
|
||||
|
||||
/**
|
||||
Inserts a new layer above another layer.
|
||||
|
||||
@param layer The layer to insert.
|
||||
@param sibling An existing layer in the style.
|
||||
*/
|
||||
- (void)insertLayer:(MGLStyleLayer *)layer aboveLayer:(MGLStyleLayer *)sibling;
|
||||
|
||||
/**
|
||||
Removes a layer from the map view.
|
||||
|
||||
@@ -101,7 +101,8 @@ static NSURL *MGLStyleURL_emerald;
|
||||
#pragma mark Metadata
|
||||
|
||||
- (NSString *)name {
|
||||
return @(self.mapView.mbglMap->getStyleName().c_str());
|
||||
std::string name = self.mapView.mbglMap->getStyleName();
|
||||
return name.empty() ? nil : @(name.c_str());
|
||||
}
|
||||
|
||||
- (NSURL *)URL {
|
||||
@@ -110,13 +111,43 @@ static NSURL *MGLStyleURL_emerald;
|
||||
|
||||
#pragma mark Sources
|
||||
|
||||
- (NS_MUTABLE_SET_OF(MGLSource *) *)sources {
|
||||
auto rawSources = self.mapView.mbglMap->getSources();
|
||||
NSMutableSet *sources = [NSMutableSet setWithCapacity:rawSources.size()];
|
||||
for (auto rawSource = rawSources.begin(); rawSource != rawSources.end(); ++rawSource) {
|
||||
MGLSource *source = [self sourceFromMBGLSource:*rawSource];
|
||||
[sources addObject:source];
|
||||
}
|
||||
return sources;
|
||||
}
|
||||
|
||||
- (void)setSources:(NS_MUTABLE_SET_OF(MGLSource *) *)sources {
|
||||
for (MGLSource *source in self.sources) {
|
||||
[self removeSource:source];
|
||||
}
|
||||
for (MGLSource *source in sources) {
|
||||
[self addSource:source];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSUInteger)countOfSources {
|
||||
auto rawSources = self.mapView.mbglMap->getSources();
|
||||
return rawSources.size();
|
||||
}
|
||||
|
||||
- (MGLSource *)memberOfSources:(MGLSource *)object {
|
||||
return [self sourceWithIdentifier:object.identifier];
|
||||
}
|
||||
|
||||
- (MGLSource *)sourceWithIdentifier:(NSString *)identifier
|
||||
{
|
||||
auto mbglSource = self.mapView.mbglMap->getSource(identifier.UTF8String);
|
||||
if (!mbglSource) {
|
||||
return nil;
|
||||
}
|
||||
auto rawSource = self.mapView.mbglMap->getSource(identifier.UTF8String);
|
||||
return rawSource ? [self sourceFromMBGLSource:rawSource] : nil;
|
||||
}
|
||||
|
||||
- (MGLSource *)sourceFromMBGLSource:(mbgl::style::Source *)mbglSource {
|
||||
NSString *identifier = @(mbglSource->getID().c_str());
|
||||
|
||||
// TODO: Fill in options specific to the respective source classes
|
||||
// https://github.com/mapbox/mapbox-gl-native/issues/6584
|
||||
MGLSource *source;
|
||||
@@ -160,13 +191,93 @@ static NSURL *MGLStyleURL_emerald;
|
||||
|
||||
#pragma mark Style layers
|
||||
|
||||
- (MGLStyleLayer *)layerWithIdentifier:(NSString *)identifier
|
||||
- (NS_MUTABLE_ARRAY_OF(MGLStyleLayer *) *)layers
|
||||
{
|
||||
auto mbglLayer = self.mapView.mbglMap->getLayer(identifier.UTF8String);
|
||||
if (!mbglLayer) {
|
||||
auto layers = self.mapView.mbglMap->getLayers();
|
||||
NSMutableArray *styleLayers = [NSMutableArray arrayWithCapacity:layers.size()];
|
||||
for (auto layer = layers.rbegin(); layer != layers.rend(); ++layer) {
|
||||
MGLStyleLayer *styleLayer = [self layerFromMBGLLayer:*layer];
|
||||
[styleLayers addObject:styleLayer];
|
||||
}
|
||||
return styleLayers;
|
||||
}
|
||||
|
||||
- (void)setLayers:(NS_MUTABLE_ARRAY_OF(MGLStyleLayer *) *)layers {
|
||||
for (MGLStyleLayer *layer in self.layers.reverseObjectEnumerator) {
|
||||
[self removeLayer:layer];
|
||||
}
|
||||
for (MGLStyleLayer *layer in layers.reverseObjectEnumerator) {
|
||||
[self addLayer:layer];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSUInteger)countOfLayers
|
||||
{
|
||||
return self.mapView.mbglMap->getLayers().size();
|
||||
}
|
||||
|
||||
- (MGLStyleLayer *)objectInLayersAtIndex:(NSUInteger)index
|
||||
{
|
||||
auto layers = self.mapView.mbglMap->getLayers();
|
||||
if (index > layers.size() - 1) {
|
||||
[NSException raise:NSRangeException
|
||||
format:@"No style layer at index %lu.", (unsigned long)index];
|
||||
return nil;
|
||||
}
|
||||
auto layer = layers.at(layers.size() - 1 - index);
|
||||
return [self layerFromMBGLLayer:layer];
|
||||
}
|
||||
|
||||
- (void)getLayers:(MGLStyleLayer **)buffer range:(NSRange)inRange
|
||||
{
|
||||
auto layers = self.mapView.mbglMap->getLayers();
|
||||
if (NSMaxRange(inRange) > layers.size()) {
|
||||
[NSException raise:NSRangeException
|
||||
format:@"Style layer range %@ is out of bounds.", NSStringFromRange(inRange)];
|
||||
}
|
||||
NSUInteger i = 0;
|
||||
for (auto layer = *(layers.rbegin() + inRange.location); i < inRange.length; ++layer, ++i) {
|
||||
MGLStyleLayer *styleLayer = [self layerFromMBGLLayer:layer];
|
||||
buffer[i] = styleLayer;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)insertObject:(MGLStyleLayer *)styleLayer inLayersAtIndex:(NSUInteger)index
|
||||
{
|
||||
if (!styleLayer.rawLayer) {
|
||||
[NSException raise:NSInvalidArgumentException format:
|
||||
@"The style layer %@ cannot be inserted into the style. "
|
||||
@"Make sure the style layer was created as a member of a concrete subclass of MGLStyleLayer.",
|
||||
styleLayer];
|
||||
}
|
||||
auto layers = self.mapView.mbglMap->getLayers();
|
||||
if (index > layers.size()) {
|
||||
[NSException raise:NSRangeException
|
||||
format:@"Cannot insert style layer at out-of-bounds index %lu.", (unsigned long)index];
|
||||
} else if (index == 0) {
|
||||
[styleLayer addToMapView:self.mapView];
|
||||
} else {
|
||||
MGLStyleLayer *sibling = [self layerFromMBGLLayer:layers.at(layers.size() - index)];
|
||||
[styleLayer addToMapView:self.mapView belowLayer:sibling];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)removeObjectFromLayersAtIndex:(NSUInteger)index
|
||||
{
|
||||
auto layers = self.mapView.mbglMap->getLayers();
|
||||
if (index > layers.size() - 1) {
|
||||
[NSException raise:NSRangeException
|
||||
format:@"Cannot remove style layer at out-of-bounds index %lu.", (unsigned long)index];
|
||||
}
|
||||
auto layer = layers.at(layers.size() - 1 - index);
|
||||
self.mapView.mbglMap->removeLayer(layer->getID());
|
||||
}
|
||||
|
||||
- (MGLStyleLayer *)layerFromMBGLLayer:(mbgl::style::Layer *)mbglLayer
|
||||
{
|
||||
NSParameterAssert(mbglLayer);
|
||||
|
||||
NSString *identifier = @(mbglLayer->getID().c_str());
|
||||
MGLStyleLayer *styleLayer;
|
||||
if (auto fillLayer = mbglLayer->as<mbgl::style::FillLayer>()) {
|
||||
MGLSource *source = [self sourceWithIdentifier:@(fillLayer->getSourceID().c_str())];
|
||||
@@ -195,6 +306,12 @@ static NSURL *MGLStyleURL_emerald;
|
||||
return styleLayer;
|
||||
}
|
||||
|
||||
- (MGLStyleLayer *)layerWithIdentifier:(NSString *)identifier
|
||||
{
|
||||
auto mbglLayer = self.mapView.mbglMap->getLayer(identifier.UTF8String);
|
||||
return mbglLayer ? [self layerFromMBGLLayer:mbglLayer] : nil;
|
||||
}
|
||||
|
||||
- (void)removeLayer:(MGLStyleLayer *)layer
|
||||
{
|
||||
if (!layer.rawLayer) {
|
||||
@@ -217,7 +334,11 @@ static NSURL *MGLStyleURL_emerald;
|
||||
[layer addToMapView:self.mapView];
|
||||
}
|
||||
|
||||
- (void)insertLayer:(MGLStyleLayer *)layer belowLayer:(MGLStyleLayer *)otherLayer
|
||||
- (void)insertLayer:(MGLStyleLayer *)layer atIndex:(NSUInteger)index {
|
||||
[self insertObject:layer inLayersAtIndex:index];
|
||||
}
|
||||
|
||||
- (void)insertLayer:(MGLStyleLayer *)layer belowLayer:(MGLStyleLayer *)sibling
|
||||
{
|
||||
if (!layer.rawLayer) {
|
||||
[NSException raise:NSInvalidArgumentException
|
||||
@@ -226,14 +347,58 @@ static NSURL *MGLStyleURL_emerald;
|
||||
@"Make sure the style layer was created as a member of a concrete subclass of MGLStyleLayer.",
|
||||
layer];
|
||||
}
|
||||
if (!otherLayer.rawLayer) {
|
||||
if (!sibling.rawLayer) {
|
||||
[NSException raise:NSInvalidArgumentException
|
||||
format:
|
||||
@"A style layer cannot be placed before %@ in the style. "
|
||||
@"Make sure otherLayer was obtained using -[MGLStyle layerWithIdentifier:].",
|
||||
otherLayer];
|
||||
@"A style layer cannot be placed below %@ in the style. "
|
||||
@"Make sure sibling was obtained using -[MGLStyle layerWithIdentifier:].",
|
||||
sibling];
|
||||
}
|
||||
[layer addToMapView:self.mapView belowLayer:otherLayer];
|
||||
[self willChangeValueForKey:@"layers"];
|
||||
[layer addToMapView:self.mapView belowLayer:sibling];
|
||||
[self didChangeValueForKey:@"layers"];
|
||||
}
|
||||
|
||||
- (void)insertLayer:(MGLStyleLayer *)layer aboveLayer:(MGLStyleLayer *)sibling {
|
||||
if (!layer.rawLayer) {
|
||||
[NSException raise:NSInvalidArgumentException
|
||||
format:
|
||||
@"The style layer %@ cannot be added to the style. "
|
||||
@"Make sure the style layer was created as a member of a concrete subclass of MGLStyleLayer.",
|
||||
layer];
|
||||
}
|
||||
if (!sibling.rawLayer) {
|
||||
[NSException raise:NSInvalidArgumentException
|
||||
format:
|
||||
@"A style layer cannot be placed above %@ in the style. "
|
||||
@"Make sure sibling was obtained using -[MGLStyle layerWithIdentifier:].",
|
||||
sibling];
|
||||
}
|
||||
|
||||
auto layers = self.mapView.mbglMap->getLayers();
|
||||
std::string siblingIdentifier = sibling.identifier.UTF8String;
|
||||
NSUInteger index = 0;
|
||||
for (auto layer : layers) {
|
||||
if (layer->getID() == siblingIdentifier) {
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
[self willChangeValueForKey:@"layers"];
|
||||
if (index + 1 > layers.size()) {
|
||||
[NSException raise:NSInvalidArgumentException
|
||||
format:
|
||||
@"A style layer cannot be placed above %@ in the style. "
|
||||
@"Make sure sibling was obtained using -[MGLStyle layerWithIdentifier:].",
|
||||
sibling];
|
||||
} else if (index + 1 == layers.size()) {
|
||||
[layer addToMapView:self.mapView];
|
||||
} else {
|
||||
MGLStyleLayer *sibling = [self layerFromMBGLLayer:layers.at(index + 1)];
|
||||
[layer addToMapView:self.mapView belowLayer:sibling];
|
||||
}
|
||||
[self didChangeValueForKey:@"layers"];
|
||||
}
|
||||
|
||||
#pragma mark Style classes
|
||||
@@ -270,6 +435,11 @@ static NSURL *MGLStyleURL_emerald;
|
||||
self.mapView.mbglMap->setClasses(newAppliedClasses);
|
||||
}
|
||||
|
||||
- (NSUInteger)countOfStyleClasses {
|
||||
const auto &classes = self.mapView.mbglMap->getClasses();
|
||||
return classes.size();
|
||||
}
|
||||
|
||||
- (BOOL)hasStyleClass:(NSString *)styleClass
|
||||
{
|
||||
return styleClass && self.mapView.mbglMap->hasClass([styleClass UTF8String]);
|
||||
|
||||
@@ -120,6 +120,9 @@ namespace mbgl {
|
||||
- (void)removeFromMapView:(MGLMapView *)mapView
|
||||
{
|
||||
auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String);
|
||||
if (!removedLayer) {
|
||||
return;
|
||||
}
|
||||
_pendingLayer = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::<%- camelize(type) %>Layer> &>(removedLayer));
|
||||
_rawLayer = _pendingLayer.get();
|
||||
}
|
||||
|
||||
@@ -137,6 +137,9 @@ namespace mbgl {
|
||||
- (void)removeFromMapView:(MGLMapView *)mapView
|
||||
{
|
||||
auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String);
|
||||
if (!removedLayer) {
|
||||
return;
|
||||
}
|
||||
_pendingLayer = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::SymbolLayer> &>(removedLayer));
|
||||
_rawLayer = _pendingLayer.get();
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
std::unique_ptr<mbgl::style::VectorSource> _pendingSource;
|
||||
}
|
||||
|
||||
static NSString *MGLVectorSourceType = @"vector";
|
||||
|
||||
- (instancetype)initWithIdentifier:(NSString *)identifier URL:(NSURL *)url
|
||||
{
|
||||
if (self = [super initWithIdentifier:identifier])
|
||||
|
||||
@@ -803,6 +803,10 @@ AnnotationIDs Map::queryPointAnnotations(const ScreenBox& box) {
|
||||
|
||||
#pragma mark - Style API
|
||||
|
||||
std::vector<style::Source*> Map::getSources() {
|
||||
return impl->style ? impl->style->getSources() : std::vector<style::Source*>();
|
||||
}
|
||||
|
||||
style::Source* Map::getSource(const std::string& sourceID) {
|
||||
if (impl->style) {
|
||||
impl->styleMutated = true;
|
||||
@@ -825,8 +829,12 @@ std::unique_ptr<Source> Map::removeSource(const std::string& sourceID) {
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<style::Layer*> Map::getLayers() {
|
||||
return impl->style ? impl->style->getLayers() : std::vector<style::Layer*>();
|
||||
}
|
||||
|
||||
style::Layer* Map::getLayer(const std::string& layerID) {
|
||||
Layer* Map::getLayer(const std::string& layerID) {
|
||||
if (impl->style) {
|
||||
impl->styleMutated = true;
|
||||
return impl->style->getLayer(layerID);
|
||||
|
||||
@@ -165,6 +165,15 @@ std::vector<const Layer*> Style::getLayers() const {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<Layer*> Style::getLayers() {
|
||||
std::vector<Layer*> result;
|
||||
result.reserve(layers.size());
|
||||
for (auto& layer : layers) {
|
||||
result.push_back(layer.get());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<Layer>>::const_iterator Style::findLayer(const std::string& id) const {
|
||||
return std::find_if(layers.begin(), layers.end(), [&](const auto& layer) {
|
||||
return layer->baseImpl->id == id;
|
||||
@@ -312,6 +321,24 @@ void Style::recalculate(float z, const TimePoint& timePoint, MapMode mode) {
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<const Source*> Style::getSources() const {
|
||||
std::vector<const Source*> result;
|
||||
result.reserve(sources.size());
|
||||
for (const auto& source : sources) {
|
||||
result.push_back(source.get());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<Source*> Style::getSources() {
|
||||
std::vector<Source*> result;
|
||||
result.reserve(sources.size());
|
||||
for (auto& source : sources) {
|
||||
result.push_back(source.get());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Source* Style::getSource(const std::string& id) const {
|
||||
const auto it = std::find_if(sources.begin(), sources.end(), [&](const auto& source) {
|
||||
return source->getID() == id;
|
||||
|
||||
@@ -64,11 +64,14 @@ public:
|
||||
return lastError;
|
||||
}
|
||||
|
||||
std::vector<const Source*> getSources() const;
|
||||
std::vector<Source*> getSources();
|
||||
Source* getSource(const std::string& id) const;
|
||||
void addSource(std::unique_ptr<Source>);
|
||||
std::unique_ptr<Source> removeSource(const std::string& sourceID);
|
||||
|
||||
std::vector<const Layer*> getLayers() const;
|
||||
std::vector<Layer*> getLayers();
|
||||
Layer* getLayer(const std::string& id) const;
|
||||
Layer* addLayer(std::unique_ptr<Layer>,
|
||||
optional<std::string> beforeLayerID = {});
|
||||
|
||||
Reference in New Issue
Block a user