diff options
Diffstat (limited to 'platform/darwin/src/MGLStyle.mm')
-rw-r--r-- | platform/darwin/src/MGLStyle.mm | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/platform/darwin/src/MGLStyle.mm b/platform/darwin/src/MGLStyle.mm index 347fc2be24..c75572052b 100644 --- a/platform/darwin/src/MGLStyle.mm +++ b/platform/darwin/src/MGLStyle.mm @@ -1,6 +1,32 @@ #import "MGLStyle.h" +#import "MGLMapView_Private.hpp" +#import "MGLStyleLayer.h" +#import "MGLFillStyleLayer.h" +#import "MGLLineStyleLayer.h" +#import "MGLCircleStyleLayer.h" +#import "MGLSymbolStyleLayer.h" +#import "MGLRasterStyleLayer.h" +#import "MGLBackgroundStyleLayer.h" + +#import "MGLStyle_Private.hpp" +#import "MGLStyleLayer_Private.hpp" +#import "MGLSource_Private.hpp" +#import "MGLSource.h" + #import <mbgl/util/default_styles.hpp> +#include <mbgl/style/layers/fill_layer.hpp> +#include <mbgl/style/layers/line_layer.hpp> +#include <mbgl/style/layers/symbol_layer.hpp> +#include <mbgl/style/layers/raster_layer.hpp> +#include <mbgl/style/layers/circle_layer.hpp> +#include <mbgl/style/layers/background_layer.hpp> +#include <mbgl/style/sources/geojson_source.hpp> +#include <mbgl/mbgl.hpp> + +@interface MGLStyle() +@property (nonatomic, weak) MGLMapView *mapView; +@end @implementation MGLStyle @@ -54,4 +80,74 @@ static NSURL *MGLStyleURL_emerald; return MGLStyleURL_emerald; } +- (mbgl::style::Layer *)mbglLayerWithIdentifier:(NSString *)identifier +{ + return self.mapView.mbglMap->getLayer(identifier.UTF8String); +} + +- (mbgl::style::Source *)mbglSourceWithIdentifier:(NSString *)identifier +{ + return self.mapView.mbglMap->getSource(identifier.UTF8String); +} + +- (id <MGLStyleLayer>)layerWithIdentifier:(NSString *)identifier +{ + auto layer = self.mapView.mbglMap->getLayer(identifier.UTF8String); + + Class clazz = [self classFromLayer:layer]; + + id <MGLStyleLayer, MGLStyleLayer_Private> styleLayer = [[clazz alloc] init]; + styleLayer.layerIdentifier = identifier; + styleLayer.layer = layer; + styleLayer.mapView = self.mapView; + + return styleLayer; +} + +- (Class)classFromLayer:(mbgl::style::Layer *)layer +{ + if (layer->is<mbgl::style::FillLayer>()) { + return MGLFillStyleLayer.class; + } else if (layer->is<mbgl::style::LineLayer>()) { + return MGLLineStyleLayer.class; + } else if (layer->is<mbgl::style::SymbolLayer>()) { + return MGLSymbolStyleLayer.class; + } else if (layer->is<mbgl::style::RasterLayer>()) { + return MGLRasterStyleLayer.class; + } else if (layer->is<mbgl::style::CircleLayer>()) { + return MGLCircleStyleLayer.class; + } else if (layer->is<mbgl::style::BackgroundLayer>()) { + return MGLBackgroundStyleLayer.class; + } + [NSException raise:@"Layer type not handled" format:@""]; + return Nil; +} + +- (void)removeLayer:(id <MGLStyleLayer_Private>)styleLayer +{ + self.mapView.mbglMap->removeLayer(styleLayer.layer->getID()); +} + +- (void)addLayer:(id <MGLStyleLayer, MGLStyleLayer_Private>)styleLayer +{ + self.mapView.mbglMap->addLayer(std::unique_ptr<mbgl::style::Layer>(styleLayer.layer)); +} + +- (void)insertLayer:(id <MGLStyleLayer, MGLStyleLayer_Private>)styleLayer + belowLayer:(id <MGLStyleLayer, MGLStyleLayer_Private>)belowLayer +{ + const mbgl::optional<std::string> belowLayerId{[belowLayer layerIdentifier].UTF8String}; + self.mapView.mbglMap->addLayer(std::unique_ptr<mbgl::style::Layer>(styleLayer.layer), belowLayerId); +} + +- (void)addSource:(MGLSource *)source +{ + self.mapView.mbglMap->addSource(std::move([source mbgl_source])); +} + +- (void)removeSource:(MGLSource *)source +{ + self.mapView.mbglMap->removeSource(source.sourceIdentifier.UTF8String); +} + @end |