diff options
author | jmkiley <jordan.kiley@mapbox.com> | 2020-02-19 11:11:59 -0800 |
---|---|---|
committer | jmkiley <jordan.kiley@mapbox.com> | 2020-02-19 11:11:59 -0800 |
commit | cf37e87df42bcf740d2b093212bef5ac794d235f (patch) | |
tree | 3cdc3522af7766ed289b7c7ba9913421b4a8516c | |
parent | b64ed754442b894f3914a4191798fbd2f2bc8cd9 (diff) | |
download | qtlocation-mapboxgl-upstream/jmkiley-ios-color-conversion.tar.gz |
[ios] Add separate mgl_color conversion method for expressionsupstream/jmkiley-ios-color-conversion
-rw-r--r-- | platform/darwin/src/MGLStyleValue_Private.h | 2 | ||||
-rw-r--r-- | platform/ios/app/MBXViewController.m | 16 | ||||
-rw-r--r-- | platform/ios/src/UIColor+MGLAdditions.h | 2 | ||||
-rw-r--r-- | platform/ios/src/UIColor+MGLAdditions.mm | 8 |
4 files changed, 21 insertions, 7 deletions
diff --git a/platform/darwin/src/MGLStyleValue_Private.h b/platform/darwin/src/MGLStyleValue_Private.h index 43f0b9d282..3b14ea700b 100644 --- a/platform/darwin/src/MGLStyleValue_Private.h +++ b/platform/darwin/src/MGLStyleValue_Private.h @@ -214,7 +214,7 @@ private: // Private utilities for converting from mgl to mbgl values // Color void getMBGLValue(MGLColor *rawValue, mbgl::Color &mbglValue) { - mbglValue = rawValue.mgl_color; + mbglValue = rawValue.mgl_colorForPremultipliedValue; } // Image diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 82a68e074a..e308b9f582 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -1014,11 +1014,11 @@ CLLocationCoordinate2D randomWorldCoordinate() { - (void)styleWaterLayer { MGLFillStyleLayer *waterLayer = (MGLFillStyleLayer *)[self.mapView.style layerWithIdentifier:@"water"]; - NSDictionary *waterColorStops = @{@6.0f: [UIColor yellowColor], - @8.0f: [UIColor blueColor], - @10.0f: [UIColor redColor], - @12.0f: [UIColor greenColor], - @14.0f: [UIColor blueColor]}; + NSDictionary *waterColorStops = @{@6.0f: [[UIColor yellowColor] colorWithAlphaComponent:0.5], + @8.0f: [[UIColor blueColor] colorWithAlphaComponent:0.5], + @10.0f: [[UIColor redColor] colorWithAlphaComponent:0.5], + @12.0f: [[UIColor greenColor] colorWithAlphaComponent:0.5], + @14.0f: [[UIColor blueColor] colorWithAlphaComponent:0.5]}; NSExpression *fillColorExpression = [NSExpression mgl_expressionForInterpolatingExpression:NSExpression.zoomLevelVariableExpression withCurveType:MGLExpressionInterpolationModeLinear parameters:nil @@ -1084,9 +1084,13 @@ CLLocationCoordinate2D randomWorldCoordinate() { [self.mapView.style addSource:source]; MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"test" source:source]; - fillLayer.fillColor = [NSExpression expressionForConstantValue:[UIColor purpleColor]]; + fillLayer.fillColor = [NSExpression expressionForConstantValue:[[UIColor blueColor] colorWithAlphaComponent:0.75]]; [self.mapView.style addLayer:fillLayer]; + [self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(52.3667, 4.8945) zoomLevel:9 animated:NO]; + UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 120, 140)]; + blueView.backgroundColor = [[UIColor blueColor] colorWithAlphaComponent:0.75]; + [self.view addSubview:blueView]; } - (void)styleSymbolLayer diff --git a/platform/ios/src/UIColor+MGLAdditions.h b/platform/ios/src/UIColor+MGLAdditions.h index 19702fa105..86c8daff59 100644 --- a/platform/ios/src/UIColor+MGLAdditions.h +++ b/platform/ios/src/UIColor+MGLAdditions.h @@ -7,6 +7,8 @@ - (mbgl::Color)mgl_color; +- (mbgl::Color)mgl_colorForPremultipliedValue; + - (mbgl::style::PropertyValue<mbgl::Color>)mgl_colorPropertyValue; + (UIColor *)mgl_colorWithColor:(mbgl::Color)color; diff --git a/platform/ios/src/UIColor+MGLAdditions.mm b/platform/ios/src/UIColor+MGLAdditions.mm index 68e77f5b10..281ac79ba8 100644 --- a/platform/ios/src/UIColor+MGLAdditions.mm +++ b/platform/ios/src/UIColor+MGLAdditions.mm @@ -12,6 +12,14 @@ return { static_cast<float>(r*a), static_cast<float>(g*a), static_cast<float>(b*a), static_cast<float>(a) }; } +- (mbgl::Color)mgl_colorForPremultipliedValue +{ + CGFloat r, g, b, a; + [self getRed:&r green:&g blue:&b alpha:&a]; + + return { static_cast<float>(r), static_cast<float>(g), static_cast<float>(b), static_cast<float>(a) }; +} + - (mbgl::style::PropertyValue<mbgl::Color>)mgl_colorPropertyValue { mbgl::Color color = self.mgl_color; |