summaryrefslogtreecommitdiff
path: root/platform/ios/app/MBXViewController.m
diff options
context:
space:
mode:
authorJesse Bounds <jesse@rebounds.net>2017-01-04 07:35:25 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-02-02 09:44:42 -0800
commit22b3834caa5fe3ae91cf957124a3f1ad1d165cee (patch)
tree95439ccd498c414acfec70dc41b94ab9591f18c8 /platform/ios/app/MBXViewController.m
parentf562ecdfc3a08f7b9b0c2be938f237852a82d374 (diff)
downloadqtlocation-mapboxgl-22b3834caa5fe3ae91cf957124a3f1ad1d165cee.tar.gz
[ios, macos] Add support for data-driven property functions
Diffstat (limited to 'platform/ios/app/MBXViewController.m')
-rw-r--r--platform/ios/app/MBXViewController.m132
1 files changed, 85 insertions, 47 deletions
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m
index 56290d022d..7df54ba65b 100644
--- a/platform/ios/app/MBXViewController.m
+++ b/platform/ios/app/MBXViewController.m
@@ -6,8 +6,6 @@
#import "MBXAnnotationView.h"
#import "MBXUserLocationAnnotationView.h"
-#import "MGLFillStyleLayer.h"
-
#import <Mapbox/Mapbox.h>
#import <objc/runtime.h>
@@ -72,6 +70,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsRuntimeStylingRows) {
MBXSettingsRuntimeStylingRasterSource,
MBXSettingsRuntimeStylingCountryLabels,
MBXSettingsRuntimeStylingRouteLine,
+ MBXSettingsRuntimeStylingDDSPolygon,
};
typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
@@ -336,6 +335,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
@"Style Raster Source",
[NSString stringWithFormat:@"Label Countries in %@", (_usingLocaleBasedCountryLabels ? @"Local Language" : [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[self bestLanguageForUser]])],
@"Add Route Line",
+ @"Dynamically Style Polygon",
]];
break;
case MBXSettingsMiscellaneous:
@@ -497,6 +497,9 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
case MBXSettingsRuntimeStylingRouteLine:
[self styleRouteLine];
break;
+ case MBXSettingsRuntimeStylingDDSPolygon:
+ [self stylePolygonWithDDS];
+ break;
default:
NSAssert(NO, @"All runtime styling setting rows should be implemented");
break;
@@ -739,22 +742,24 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
- (void)styleWaterLayer
{
MGLFillStyleLayer *waterLayer = (MGLFillStyleLayer *)[self.mapView.style layerWithIdentifier:@"water"];
- MGLStyleValue *waterColorFunction = [MGLStyleValue<UIColor *> valueWithStops:@{
- @6.0f: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor yellowColor]],
- @8.0f: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor blueColor]],
- @10.0f: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor redColor]],
- @12.0f: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor greenColor]],
- @14.0f: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor blueColor]],
- }];
+ NSDictionary *waterColorStops = @{@6.0f: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor yellowColor]],
+ @8.0f: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor blueColor]],
+ @10.0f: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor redColor]],
+ @12.0f: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor greenColor]],
+ @14.0f: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor blueColor]]};
+ MGLStyleValue *waterColorFunction = [MGLStyleValue<UIColor *> valueWithInterpolationMode:MGLInterpolationModeExponential
+ cameraStops:waterColorStops
+ options: nil];
waterLayer.fillColor = waterColorFunction;
- MGLStyleValue *fillAntialiasedFunction = [MGLStyleValue<NSNumber *> valueWithStops:@{
- @11: [MGLStyleValue<NSNumber *> valueWithRawValue:@YES],
- @12: [MGLStyleValue<NSNumber *> valueWithRawValue:@NO],
- @13: [MGLStyleValue<NSNumber *> valueWithRawValue:@YES],
- @14: [MGLStyleValue<NSNumber *> valueWithRawValue:@NO],
- @15: [MGLStyleValue<NSNumber *> valueWithRawValue:@YES],
- }];
+ NSDictionary *fillAntialiasedStops = @{@11: [MGLStyleValue<NSNumber *> valueWithRawValue:@YES],
+ @12: [MGLStyleValue<NSNumber *> valueWithRawValue:@NO],
+ @13: [MGLStyleValue<NSNumber *> valueWithRawValue:@YES],
+ @14: [MGLStyleValue<NSNumber *> valueWithRawValue:@NO],
+ @15: [MGLStyleValue<NSNumber *> valueWithRawValue:@YES]};
+ MGLStyleValue *fillAntialiasedFunction = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeInterval
+ cameraStops:fillAntialiasedStops
+ options:nil];
waterLayer.fillAntialiased = fillAntialiasedFunction;
}
@@ -763,21 +768,23 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
MGLLineStyleLayer *roadLayer = (MGLLineStyleLayer *)[self.mapView.style layerWithIdentifier:@"road-primary"];
roadLayer.lineColor = [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor blackColor]];
- MGLStyleValue *lineWidthFunction = [MGLStyleValue<NSNumber *> valueWithStops:@{
- @5: [MGLStyleValue<NSNumber *> valueWithRawValue:@5],
- @10: [MGLStyleValue<NSNumber *> valueWithRawValue:@15],
- @15: [MGLStyleValue<NSNumber *> valueWithRawValue:@30],
- }];
-
- MGLStyleValue *roadLineColor = [MGLStyleValue<UIColor *> valueWithStops:@{
- @10: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor purpleColor]],
- @13: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor yellowColor]],
- @16: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor cyanColor]],
- }];
- roadLayer.lineColor = roadLineColor;
+ NSDictionary *lineWidthStops = @{@5: [MGLStyleValue<NSNumber *> valueWithRawValue:@5],
+ @10: [MGLStyleValue<NSNumber *> valueWithRawValue:@15],
+ @15: [MGLStyleValue<NSNumber *> valueWithRawValue:@30]};
+ MGLStyleValue *lineWidthFunction = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeExponential
+ cameraStops:lineWidthStops
+ options:nil];
roadLayer.lineWidth = lineWidthFunction;
roadLayer.lineGapWidth = lineWidthFunction;
+ NSDictionary *roadLineColorStops = @{@10: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor purpleColor]],
+ @13: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor yellowColor]],
+ @16: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor cyanColor]]};
+ MGLStyleValue *roadLineColor = [MGLStyleValue<UIColor *> valueWithInterpolationMode:MGLInterpolationModeExponential
+ cameraStops:roadLineColorStops
+ options: nil];
+ roadLayer.lineColor = roadLineColor;
+
roadLayer.visible = YES;
roadLayer.maximumZoomLevel = 15;
roadLayer.minimumZoomLevel = 13;
@@ -790,10 +797,10 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
[self.mapView.style addSource:rasterSource];
MGLRasterStyleLayer *rasterLayer = [[MGLRasterStyleLayer alloc] initWithIdentifier:@"my-raster-layer" source:rasterSource];
- MGLStyleValue *opacityFunction = [MGLStyleValue<NSNumber *> valueWithStops:@{
- @20.0f: [MGLStyleValue<NSNumber *> valueWithRawValue:@1.0f],
- @5.0f: [MGLStyleValue<NSNumber *> valueWithRawValue:@0.0f],
- }];
+ MGLStyleValue *opacityFunction = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeExponential
+ cameraStops:@{@20.0f: [MGLStyleValue<NSNumber *> valueWithRawValue:@1.0f],
+ @5.0f: [MGLStyleValue<NSNumber *> valueWithRawValue:@0.0f]}
+ options:nil];
rasterLayer.rasterOpacity = opacityFunction;
[self.mapView.style addLayer:rasterLayer];
}
@@ -822,7 +829,7 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
self.mapView.style.transitionDuration = 5;
self.mapView.style.transitionDelay = 1;
MGLFillStyleLayer *buildingLayer = (MGLFillStyleLayer *)[self.mapView.style layerWithIdentifier:@"building"];
- buildingLayer.fillColor = [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor blackColor]];
+ buildingLayer.fillColor = [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor purpleColor]];
}
- (void)styleFerryLayer
@@ -857,18 +864,6 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
});
}
-+ (MGLStyleConstantValue<NSValue *> *)testEnum:(NSUInteger)value type:(const char *)type
-{
- return [MGLStyleConstantValue<NSValue *> valueWithRawValue:[NSValue value:&value withObjCType:type]];
-}
-
-+ (MGLStyleFunction<NSValue *> *)testEnumFunction:(NSUInteger)value type:(const char *)type
-{
- return [MGLStyleFunction<NSValue *> valueWithStops:@{
- @18: [self testEnum:value type:type],
- }];
-}
-
- (void)styleFilteredLines
{
// set style and focus on lower 48
@@ -1204,6 +1199,48 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
[self.mapView.style addLayer:routeLayer];
}
+- (void)stylePolygonWithDDS {
+ CLLocationCoordinate2D leftCoords[] = {
+ {37.73081027834234, -122.49412536621094},
+ {37.7566013348511, -122.49412536621094},
+ {37.7566013348511, -122.46253967285156},
+ {37.73081027834234, -122.46253967285156},
+ {37.73081027834234, -122.49412536621094},
+ };
+ CLLocationCoordinate2D rightCoords[] = {
+ {37.73135334055843, -122.44640350341795},
+ {37.75741564287944, -122.44640350341795},
+ {37.75741564287944, -122.41310119628906},
+ {37.73135334055843, -122.41310119628906},
+ {37.73135334055843, -122.44640350341795},
+ };
+ MGLPolygonFeature *leftFeature = [MGLPolygonFeature polygonWithCoordinates:leftCoords count:5];
+ leftFeature.attributes = @{@"fill": @(YES)};
+
+ MGLPolygonFeature *rightFeature = [MGLPolygonFeature polygonWithCoordinates:rightCoords count:5];
+ rightFeature.attributes = @{@"opacity": @(0.5)};
+
+ MGLShapeSource *shapeSource = [[MGLShapeSource alloc] initWithIdentifier:@"shape-source" features:@[leftFeature, rightFeature] options:nil];
+ [self.mapView.style addSource:shapeSource];
+
+ // 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];
+ NSDictionary *stops = @{@(YES): [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor greenColor]]};
+ NSDictionary *fillColorOptions = @{MGLStyleFunctionOptionDefaultValue: [MGLStyleValue<UIColor *> valueWithRawValue:[UIColor redColor]]};
+ fillStyleLayer.fillColor = [MGLStyleValue<UIColor *> valueWithInterpolationMode:MGLInterpolationModeCategorical
+ sourceStops:stops
+ attributeName:@"fill"
+ options:fillColorOptions];
+
+ // source, identity function that sets any feature with an "opacity" attribute to use that value and anything without to 1.0
+ NSDictionary *fillOpacityOptions = @{MGLStyleFunctionOptionDefaultValue: [MGLStyleValue<NSNumber *> valueWithRawValue:@(1.0)]};
+ fillStyleLayer.fillOpacity = [MGLStyleValue<NSNumber *> valueWithInterpolationMode:MGLInterpolationModeIdentity
+ sourceStops:nil
+ attributeName:@"opacity"
+ options:fillOpacityOptions];
+ [self.mapView.style addLayer:fillStyleLayer];
+}
+
- (void)styleLabelLanguageForLayersNamed:(NSArray<NSString *> *)layers
{
_usingLocaleBasedCountryLabels = !_usingLocaleBasedCountryLabels;
@@ -1219,8 +1256,9 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
if ([label.rawValue hasPrefix:@"{name"]) {
layer.text = [MGLStyleValue valueWithRawValue:language];
}
- } else if ([layer.text isKindOfClass:[MGLStyleFunction class]]) {
- MGLStyleFunction *function = (MGLStyleFunction<NSString *> *)layer.text;
+ }
+ else if ([layer.text isKindOfClass:[MGLCameraStyleFunction class]]) {
+ MGLCameraStyleFunction *function = (MGLCameraStyleFunction<NSString *> *)layer.text;
[function.stops enumerateKeysAndObjectsUsingBlock:^(id zoomLevel, id stop, BOOL *done) {
if ([stop isKindOfClass:[MGLStyleConstantValue class]]) {
MGLStyleConstantValue *label = (MGLStyleConstantValue<NSString *> *)stop;