diff options
author | Jesse Bounds <jesse@rebounds.net> | 2016-11-14 16:59:30 -0800 |
---|---|---|
committer | Jesse Bounds <jesse@rebounds.net> | 2016-11-22 19:53:54 -0800 |
commit | 13e0f9e527366dce43f59055fde17818f443e356 (patch) | |
tree | 83b3ca4e2b0f103575c28335ac39fc76b7ec33a5 /platform/darwin/src/MGLFillStyleLayer.mm | |
parent | 4e4e05ef50808a27d7a9a46c830d05165bd85e94 (diff) | |
download | qtlocation-mapboxgl-13e0f9e527366dce43f59055fde17818f443e356.tar.gz |
[ios, macos] Refactor runtime styling enumeration properties
Correctly map SDK runtime styling enumerations to mbgl
equivalents. Also, add category methods to NSValue so enums
can be wrapped up with less of the details of how they
are layed out in memory in Objective-C.
Diffstat (limited to 'platform/darwin/src/MGLFillStyleLayer.mm')
-rw-r--r-- | platform/darwin/src/MGLFillStyleLayer.mm | 60 |
1 files changed, 34 insertions, 26 deletions
diff --git a/platform/darwin/src/MGLFillStyleLayer.mm b/platform/darwin/src/MGLFillStyleLayer.mm index 5aed779c86..24c8a90f7f 100644 --- a/platform/darwin/src/MGLFillStyleLayer.mm +++ b/platform/darwin/src/MGLFillStyleLayer.mm @@ -10,6 +10,15 @@ #include <mbgl/style/layers/fill_layer.hpp> +namespace mbgl { + + MBGL_DEFINE_ENUM(MGLFillTranslateAnchor, { + { MGLFillTranslateAnchorMap, "map" }, + { MGLFillTranslateAnchorViewport, "viewport" }, + }); + +} + @interface MGLFillStyleLayer () @property (nonatomic) mbgl::style::FillLayer *rawLayer; @@ -26,34 +35,30 @@ if (self = [super initWithIdentifier:identifier source:source]) { auto layer = std::make_unique<mbgl::style::FillLayer>(identifier.UTF8String, source.identifier.UTF8String); _pendingLayer = std::move(layer); - self.rawLayer = _pendingLayer.get(); + _rawLayer = _pendingLayer.get(); } return self; } - - - (NSString *)sourceLayerIdentifier { - auto layerID = self.rawLayer->getSourceLayer(); + auto layerID = _rawLayer->getSourceLayer(); return layerID.empty() ? nil : @(layerID.c_str()); } - (void)setSourceLayerIdentifier:(NSString *)sourceLayerIdentifier { - self.rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); + _rawLayer->setSourceLayer(sourceLayerIdentifier.UTF8String ?: ""); } - (void)setPredicate:(NSPredicate *)predicate { - self.rawLayer->setFilter(predicate.mgl_filter); + _rawLayer->setFilter(predicate.mgl_filter); } - (NSPredicate *)predicate { - return [NSPredicate mgl_predicateWithFilter:self.rawLayer->getFilter()]; + return [NSPredicate mgl_predicateWithFilter:_rawLayer->getFilter()]; } - - #pragma mark - Adding to and removing from a map view - (void)addToMapView:(MGLMapView *)mapView @@ -75,78 +80,81 @@ { auto removedLayer = mapView.mbglMap->removeLayer(self.identifier.UTF8String); _pendingLayer = std::move(reinterpret_cast<std::unique_ptr<mbgl::style::FillLayer> &>(removedLayer)); - self.rawLayer = _pendingLayer.get(); + _rawLayer = _pendingLayer.get(); } #pragma mark - Accessing the Paint Attributes - (void)setFillAntialias:(MGLStyleValue<NSNumber *> *)fillAntialias { auto mbglValue = MGLStyleValueTransformer<bool, NSNumber *>().toPropertyValue(fillAntialias); - self.rawLayer->setFillAntialias(mbglValue); + _rawLayer->setFillAntialias(mbglValue); } - (MGLStyleValue<NSNumber *> *)fillAntialias { - auto propertyValue = self.rawLayer->getFillAntialias() ?: self.rawLayer->getDefaultFillAntialias(); + auto propertyValue = _rawLayer->getFillAntialias() ?: _rawLayer->getDefaultFillAntialias(); return MGLStyleValueTransformer<bool, NSNumber *>().toStyleValue(propertyValue); } - (void)setFillOpacity:(MGLStyleValue<NSNumber *> *)fillOpacity { auto mbglValue = MGLStyleValueTransformer<float, NSNumber *>().toPropertyValue(fillOpacity); - self.rawLayer->setFillOpacity(mbglValue); + _rawLayer->setFillOpacity(mbglValue); } - (MGLStyleValue<NSNumber *> *)fillOpacity { - auto propertyValue = self.rawLayer->getFillOpacity() ?: self.rawLayer->getDefaultFillOpacity(); + auto propertyValue = _rawLayer->getFillOpacity() ?: _rawLayer->getDefaultFillOpacity(); return MGLStyleValueTransformer<float, NSNumber *>().toStyleValue(propertyValue); } - (void)setFillColor:(MGLStyleValue<MGLColor *> *)fillColor { auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue(fillColor); - self.rawLayer->setFillColor(mbglValue); + _rawLayer->setFillColor(mbglValue); } - (MGLStyleValue<MGLColor *> *)fillColor { - auto propertyValue = self.rawLayer->getFillColor() ?: self.rawLayer->getDefaultFillColor(); + auto propertyValue = _rawLayer->getFillColor() ?: _rawLayer->getDefaultFillColor(); return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(propertyValue); } - (void)setFillOutlineColor:(MGLStyleValue<MGLColor *> *)fillOutlineColor { auto mbglValue = MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toPropertyValue(fillOutlineColor); - self.rawLayer->setFillOutlineColor(mbglValue); + _rawLayer->setFillOutlineColor(mbglValue); } - (MGLStyleValue<MGLColor *> *)fillOutlineColor { - auto propertyValue = self.rawLayer->getFillOutlineColor() ?: self.rawLayer->getDefaultFillOutlineColor(); + auto propertyValue = _rawLayer->getFillOutlineColor() ?: _rawLayer->getDefaultFillOutlineColor(); return MGLStyleValueTransformer<mbgl::Color, MGLColor *>().toStyleValue(propertyValue); } - (void)setFillTranslate:(MGLStyleValue<NSValue *> *)fillTranslate { auto mbglValue = MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toPropertyValue(fillTranslate); - self.rawLayer->setFillTranslate(mbglValue); + _rawLayer->setFillTranslate(mbglValue); } - (MGLStyleValue<NSValue *> *)fillTranslate { - auto propertyValue = self.rawLayer->getFillTranslate() ?: self.rawLayer->getDefaultFillTranslate(); + auto propertyValue = _rawLayer->getFillTranslate() ?: _rawLayer->getDefaultFillTranslate(); return MGLStyleValueTransformer<std::array<float, 2>, NSValue *>().toStyleValue(propertyValue); } - (void)setFillTranslateAnchor:(MGLStyleValue<NSValue *> *)fillTranslateAnchor { - auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *>().toPropertyValue(fillTranslateAnchor); - self.rawLayer->setFillTranslateAnchor(mbglValue); + auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, + NSValue *, + mbgl::style::TranslateAnchorType, + MGLFillTranslateAnchor>().toEnumPropertyValue(fillTranslateAnchor); + _rawLayer->setFillTranslateAnchor(mbglValue); } - (MGLStyleValue<NSValue *> *)fillTranslateAnchor { - auto propertyValue = self.rawLayer->getFillTranslateAnchor() ?: self.rawLayer->getDefaultFillTranslateAnchor(); - return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *>().toStyleValue(propertyValue); + auto propertyValue = _rawLayer->getFillTranslateAnchor() ?: _rawLayer->getDefaultFillTranslateAnchor(); + return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLFillTranslateAnchor>().toEnumStyleValue(propertyValue); } - (void)setFillPattern:(MGLStyleValue<NSString *> *)fillPattern { auto mbglValue = MGLStyleValueTransformer<std::string, NSString *>().toPropertyValue(fillPattern); - self.rawLayer->setFillPattern(mbglValue); + _rawLayer->setFillPattern(mbglValue); } - (MGLStyleValue<NSString *> *)fillPattern { - auto propertyValue = self.rawLayer->getFillPattern() ?: self.rawLayer->getDefaultFillPattern(); + auto propertyValue = _rawLayer->getFillPattern() ?: _rawLayer->getDefaultFillPattern(); return MGLStyleValueTransformer<std::string, NSString *>().toStyleValue(propertyValue); } |