summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Guerra <fabian.guerra@mapbox.com>2018-03-06 11:27:56 -0500
committerFabian Guerra <fabian.guerra@mapbox.com>2018-03-14 19:47:00 -0400
commit0ccfbd0cce519a494ef38b01ebe61a40a745c325 (patch)
tree4e2e477a53cc5835773d963b4f78e4c246a25ca6
parent399a3ee18dcdaa8f9d436823db45ce761a429f2d (diff)
downloadqtlocation-mapboxgl-0ccfbd0cce519a494ef38b01ebe61a40a745c325.tar.gz
[ios] Update NSExpression usage to the MGLAdditions helper methods.
-rw-r--r--platform/ios/app/MBXViewController.m119
1 files changed, 64 insertions, 55 deletions
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m
index 18e8229c8f..0d72e434ec 100644
--- a/platform/ios/app/MBXViewController.m
+++ b/platform/ios/app/MBXViewController.m
@@ -927,10 +927,10 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
if (buildingLayer.fillColor) {
layer.fillExtrusionColor = buildingLayer.fillColor;
} else {
- layer.fillExtrusionColor = [NSExpression expressionForConstantValue:[UIColor whiteColor]];
+ layer.fillExtrusionColor = [NSExpression mgl_expressionForColor:[UIColor whiteColor]];
}
- layer.fillExtrusionOpacity = [NSExpression expressionForConstantValue:@0.75];
+ layer.fillExtrusionOpacity = [NSExpression mgl_expressionForValue:@0.75];
}
MGLStyleLayer* labelLayer = [self.mapView.style layerWithIdentifier:@"waterway-label"];
@@ -951,23 +951,21 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
@10.0f: [UIColor redColor],
@12.0f: [UIColor greenColor],
@14.0f: [UIColor blueColor]};
- MGLNSExpressionBuilder *expressionBuilder = [MGLNSExpressionBuilder expressionBuilderWithFunction:MGLExpressionStyleFunctionZoomLevel
- interpolateCurveType:MGLInterpolateCurveTypeLinear
- parameters:nil
- steps:waterColorStops];
-// waterLayer.fillColor = [NSExpression expressionWithFormat:
-// @"FUNCTION($zoomLevel, 'mgl_interpolateWithCurveType:parameters:stops:', 'linear', nil, %@)",
-// waterColorStops];
- waterLayer.fillColor = expressionBuilder.expression;
+ NSExpression *fillColorExpression = [NSExpression mgl_expressionForInterpolateFunction:MGLExpressionStyleFunctionZoomLevel
+ curveType:MGLExpressionInterpolationModeLinear steps:waterColorStops];
+
+ waterLayer.fillColor = fillColorExpression;
NSDictionary *fillAntialiasedStops = @{@11: @YES,
@12: @NO,
@13: @YES,
@14: @NO,
@15: @YES};
- waterLayer.fillAntialiased = [NSExpression expressionWithFormat:
- @"FUNCTION($zoomLevel, 'mgl_stepWithMinimum:stops:', false, %@)",
- fillAntialiasedStops];
+ NSExpression *fillAntialiased = [NSExpression mgl_expressionForStepFunction:MGLExpressionStyleFunctionZoomLevel
+ defaultValue:@NO
+ stops:fillAntialiasedStops];
+
+ waterLayer.fillAntialiased = fillAntialiased;
}
- (void)styleRoadLayer
@@ -978,18 +976,19 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
NSDictionary *lineWidthStops = @{@5: @5,
@10: @15,
@15: @30};
- NSExpression *lineWidthExpression = [NSExpression expressionWithFormat:
- @"FUNCTION($zoomLevel, 'mgl_interpolateWithCurveType:parameters:stops:', 'linear', nil, %@)",
- lineWidthStops];
+ NSExpression *lineWidthExpression = [NSExpression mgl_expressionForInterpolateFunction:MGLExpressionStyleFunctionZoomLevel
+ curveType:MGLExpressionInterpolationModeLinear
+ steps:lineWidthStops];
+
roadLayer.lineWidth = lineWidthExpression;
roadLayer.lineGapWidth = lineWidthExpression;
NSDictionary *roadLineColorStops = @{@10: [UIColor purpleColor],
@13: [UIColor yellowColor],
@16: [UIColor cyanColor]};
- roadLayer.lineColor = [NSExpression expressionWithFormat:
- @"FUNCTION($zoomLevel, 'mgl_interpolateWithCurveType:parameters:stops:', 'linear', nil, %@)",
- roadLineColorStops];
+ roadLayer.lineColor = [NSExpression mgl_expressionForInterpolateFunction:MGLExpressionStyleFunctionZoomLevel
+ curveType:MGLExpressionInterpolationModeLinear
+ steps:roadLineColorStops];
roadLayer.visible = YES;
roadLayer.maximumZoomLevel = 15;
@@ -1005,9 +1004,9 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
MGLRasterStyleLayer *rasterLayer = [[MGLRasterStyleLayer alloc] initWithIdentifier:@"my-raster-layer" source:rasterSource];
NSDictionary *opacityStops = @{@20.0f: @1.0f,
@5.0f: @0.0f};
- rasterLayer.rasterOpacity = [NSExpression expressionWithFormat:
- @"FUNCTION($zoomLevel, 'mgl_interpolateWithCurveType:parameters:stops:', 'linear', nil, %@)",
- opacityStops];
+ rasterLayer.rasterOpacity = [NSExpression mgl_expressionForInterpolateFunction:MGLExpressionStyleFunctionZoomLevel
+ curveType:MGLExpressionInterpolationModeLinear
+ steps:opacityStops];
[self.mapView.style addLayer:rasterLayer];
}
@@ -1019,7 +1018,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
[self.mapView.style addSource:source];
MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"test" source:source];
- fillLayer.fillColor = [NSExpression expressionForConstantValue:[UIColor purpleColor]];
+ fillLayer.fillColor = [NSExpression mgl_expressionForColor:[UIColor purpleColor]];
[self.mapView.style addLayer:fillLayer];
}
@@ -1027,7 +1026,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
- (void)styleSymbolLayer
{
MGLSymbolStyleLayer *stateLayer = (MGLSymbolStyleLayer *)[self.mapView.style layerWithIdentifier:@"state-label-lg"];
- stateLayer.textColor = [NSExpression expressionForConstantValue:[UIColor redColor]];
+ stateLayer.textColor = [NSExpression mgl_expressionForColor:[UIColor redColor]];
}
- (void)styleBuildingLayer
@@ -1035,13 +1034,13 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
MGLTransition transition = { 5, 1 };
self.mapView.style.transition = transition;
MGLFillStyleLayer *buildingLayer = (MGLFillStyleLayer *)[self.mapView.style layerWithIdentifier:@"building"];
- buildingLayer.fillColor = [NSExpression expressionForConstantValue:[UIColor purpleColor]];
+ buildingLayer.fillColor = [NSExpression mgl_expressionForColor:[UIColor purpleColor]];
}
- (void)styleFerryLayer
{
MGLLineStyleLayer *ferryLineLayer = (MGLLineStyleLayer *)[self.mapView.style layerWithIdentifier:@"ferry"];
- ferryLineLayer.lineColor = [NSExpression expressionForConstantValue:[UIColor redColor]];
+ ferryLineLayer.lineColor = [NSExpression mgl_expressionForColor:[UIColor redColor]];
}
- (void)removeParkLayer
@@ -1065,8 +1064,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
statesLayer.predicate = [NSPredicate predicateWithFormat:@"name == 'Texas'"];
// paint properties
- statesLayer.fillColor = [NSExpression expressionForConstantValue:[UIColor redColor]];
- statesLayer.fillOpacity = [NSExpression expressionForConstantValue:@0.25];
+ statesLayer.fillColor = [NSExpression mgl_expressionForColor:[UIColor redColor]];
+ statesLayer.fillOpacity = [NSExpression mgl_expressionForValue:@0.25];
});
}
@@ -1085,9 +1084,9 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
countiesLayer.predicate = [NSPredicate predicateWithFormat:@"NAME10 == 'Washington'"];
// paint properties
- countiesLayer.lineColor = [NSExpression expressionForConstantValue:[UIColor redColor]];
- countiesLayer.lineOpacity = [NSExpression expressionForConstantValue:@0.75];
- countiesLayer.lineWidth = [NSExpression expressionForConstantValue:@5];
+ countiesLayer.lineColor = [NSExpression mgl_expressionForColor:[UIColor redColor]];
+ countiesLayer.lineOpacity = [NSExpression mgl_expressionForValue:@0.75];
+ countiesLayer.lineWidth = [NSExpression mgl_expressionForValue:@5];
});
}
@@ -1106,8 +1105,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
regionsLayer.predicate = [NSPredicate predicateWithFormat:@"HRRNUM >= %@ AND HRRNUM < 300", @(200)];
// paint properties
- regionsLayer.fillColor = [NSExpression expressionForConstantValue:[UIColor blueColor]];
- regionsLayer.fillOpacity = [NSExpression expressionForConstantValue:@0.5];
+ regionsLayer.fillColor = [NSExpression mgl_expressionForColor:[UIColor blueColor]];
+ regionsLayer.fillOpacity = [NSExpression mgl_expressionForValue:@0.5];
});
}
@@ -1137,8 +1136,8 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
[self.mapView.style addSource:source];
MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:queryLayerID source:source];
- fillLayer.fillColor = [NSExpression expressionForConstantValue:[UIColor blueColor]];
- fillLayer.fillOpacity = [NSExpression expressionForConstantValue:@0.5];
+ fillLayer.fillColor = [NSExpression mgl_expressionForColor:[UIColor blueColor]];
+ fillLayer.fillOpacity = [NSExpression mgl_expressionForValue:@0.5];
[self.mapView.style addLayer:fillLayer];
});
}
@@ -1191,7 +1190,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
MGLFillStyleLayer *layer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"leaf-fill-layer" source:source];
layer.predicate = [NSPredicate predicateWithFormat:@"color = 'red'"];
- layer.fillColor = [NSExpression expressionForConstantValue:[UIColor redColor]];
+ layer.fillColor = [NSExpression mgl_expressionForColor:[UIColor redColor]];
[self.mapView.style addLayer:layer];
NSString *geoJSON = @"{\"type\": \"Feature\", \"properties\": {\"color\": \"green\"}, \"geometry\": { \"type\": \"Point\", \"coordinates\": [ -114.06847000122069, 51.050459433092655 ] }}";
@@ -1202,7 +1201,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
[self.mapView.style addSource:pointSource];
MGLCircleStyleLayer *circleLayer = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"leaf-circle-layer" source:pointSource];
- circleLayer.circleColor = [NSExpression expressionForConstantValue:[UIColor greenColor]];
+ circleLayer.circleColor = [NSExpression mgl_expressionForColor:[UIColor greenColor]];
circleLayer.predicate = [NSPredicate predicateWithFormat:@"color = 'green'"];
[self.mapView.style addLayer:circleLayer];
@@ -1219,7 +1218,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
[self.mapView.style addSource:plainShapeSource];
MGLFillStyleLayer *plainFillLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"leaf-plain-fill-layer" source:plainShapeSource];
- plainFillLayer.fillColor = [NSExpression expressionForConstantValue:[UIColor yellowColor]];
+ plainFillLayer.fillColor = [NSExpression mgl_expressionForColor:[UIColor yellowColor]];
[self.mapView.style addLayer:plainFillLayer];
}
@@ -1296,7 +1295,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
[self.mapView.style addSource:source];
MGLFillStyleLayer *layer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"mutable-data-layer-features-id" source:source];
- layer.fillColor = [NSExpression expressionForConstantValue:[UIColor redColor]];
+ layer.fillColor = [NSExpression mgl_expressionForColor:[UIColor redColor]];
[self.mapView.style addLayer:layer];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
@@ -1329,14 +1328,14 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
[self.mapView.style addSource:vectorSource];
MGLBackgroundStyleLayer *backgroundLayer = [[MGLBackgroundStyleLayer alloc] initWithIdentifier:@"style-vector-background-layer-id"];
- backgroundLayer.backgroundColor = [NSExpression expressionForConstantValue:[UIColor blackColor]];
+ backgroundLayer.backgroundColor = [NSExpression mgl_expressionForColor:[UIColor blackColor]];
[self.mapView.style addLayer:backgroundLayer];
MGLLineStyleLayer *lineLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"style-vector-line-layer-id" source:vectorSource];
lineLayer.sourceLayerIdentifier = @"contour";
- lineLayer.lineJoin = [NSExpression expressionForConstantValue:@"round"];
- lineLayer.lineCap = [NSExpression expressionForConstantValue:@"round"];
- lineLayer.lineColor = [NSExpression expressionForConstantValue:[UIColor greenColor]];
+ lineLayer.lineJoin = [NSExpression mgl_expressionForString:@"round"];
+ lineLayer.lineCap = [NSExpression mgl_expressionForString:@"round"];
+ lineLayer.lineColor = [NSExpression mgl_expressionForColor:[UIColor greenColor]];
[self.mapView.style addLayer:lineLayer];
}
@@ -1414,19 +1413,19 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
[self.mapView.style addSource:routeSource];
MGLLineStyleLayer *baseRouteLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"style-base-route-layer" source:routeSource];
- baseRouteLayer.lineColor = [NSExpression expressionForConstantValue:[UIColor orangeColor]];
- baseRouteLayer.lineWidth = [NSExpression expressionForConstantValue:@20];
- baseRouteLayer.lineOpacity = [NSExpression expressionForConstantValue:@0.5];
- baseRouteLayer.lineCap = [NSExpression expressionForConstantValue:@"round"];
- baseRouteLayer.lineJoin = [NSExpression expressionForConstantValue:@"round"];
+ baseRouteLayer.lineColor = [NSExpression mgl_expressionForColor:[UIColor orangeColor]];
+ baseRouteLayer.lineWidth = [NSExpression mgl_expressionForValue:@20];
+ baseRouteLayer.lineOpacity = [NSExpression mgl_expressionForValue:@0.5];
+ baseRouteLayer.lineCap = [NSExpression mgl_expressionForString:@"round"];
+ baseRouteLayer.lineJoin = [NSExpression mgl_expressionForString:@"round"];
[self.mapView.style addLayer:baseRouteLayer];
MGLLineStyleLayer *routeLayer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"style-route-layer" source:routeSource];
- routeLayer.lineColor = [NSExpression expressionForConstantValue:[UIColor whiteColor]];
- routeLayer.lineWidth = [NSExpression expressionForConstantValue:@15];
- routeLayer.lineOpacity = [NSExpression expressionForConstantValue:@0.8];
- routeLayer.lineCap = [NSExpression expressionForConstantValue:@"round"];
- routeLayer.lineJoin = [NSExpression expressionForConstantValue:@"round"];
+ routeLayer.lineColor = [NSExpression mgl_expressionForColor:[UIColor whiteColor]];
+ routeLayer.lineWidth = [NSExpression mgl_expressionForValue:@15];
+ routeLayer.lineOpacity = [NSExpression mgl_expressionForValue:@0.8];
+ routeLayer.lineCap = [NSExpression mgl_expressionForString:@"round"];
+ routeLayer.lineJoin = [NSExpression mgl_expressionForString:@"round"];
[self.mapView.style addLayer:routeLayer];
}
@@ -1456,10 +1455,15 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
// source, categorical function that sets any feature with a "fill" attribute value of true to red color and anything without to green
MGLFillStyleLayer *fillStyleLayer = [[MGLFillStyleLayer alloc] initWithIdentifier:@"fill-layer" source:shapeSource];
- fillStyleLayer.fillColor = [NSExpression expressionWithFormat:@"TERNARY(fill == YES, %@, %@)", [UIColor greenColor], [UIColor redColor]];
+ fillStyleLayer.fillColor = [NSExpression mgl_expressionForTernaryFunction:@"fill == YES"
+ trueExpression:[NSExpression mgl_expressionForColor:[UIColor greenColor]]
+ falseExpresssion:[NSExpression mgl_expressionForColor:[UIColor redColor]]];
+
// source, identity function that sets any feature with an "opacity" attribute to use that value and anything without to 1.0
- fillStyleLayer.fillOpacity = [NSExpression expressionWithFormat:@"TERNARY(opacity != nil, opacity, 1.0)"];
+ fillStyleLayer.fillOpacity = [NSExpression mgl_expressionForTernaryFunction:@"opacity != nil"
+ trueExpression:[NSExpression expressionForKeyPath:@"opacity"]
+ falseExpresssion:[NSExpression mgl_expressionForValue:@1.0]];
[self.mapView.style addLayer:fillStyleLayer];
}
@@ -1871,6 +1875,11 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
return nil;
}
+- (void)mapView:(MGLMapView *)mapView didSelectAnnotation:(id<MGLAnnotation>)annotation
+{
+ NSLog(@"%@", annotation);
+}
+
- (UIView *)mapView:(__unused MGLMapView *)mapView leftCalloutAccessoryViewForAnnotation:(__unused id<MGLAnnotation>)annotation
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];