summaryrefslogtreecommitdiff
path: root/platform/ios/app
diff options
context:
space:
mode:
authorFredrik Karlsson <bjorn.fredrik.karlsson@gmail.com>2016-08-11 13:14:45 -0400
committerGitHub <noreply@github.com>2016-08-11 13:14:45 -0400
commit2354c87411ce88c581e02f93445a66a2158bd7b0 (patch)
treea7deb9a3b1b0f24e2a876dedc13fbd1c6b22947e /platform/ios/app
parentb0cb8715ed74678b4d0f05829fa71a590e41b2f6 (diff)
downloadqtlocation-mapboxgl-2354c87411ce88c581e02f93445a66a2158bd7b0.tar.gz
Runtime styling API for iOS/macOS (#5727)
* [ios] wip runtime styling * [ios, macos] Outlined header templates * [ios, macos] cleanup and use appropiate data types * [ios, macos] removed refs to mbgl and added convenient color methods on UIColor and NSColor * [ios, macos] updated header template, included doc string * [ios, macos] outlined template for layer implementation files * [ios, macos] moved script to platform/darwin and updated comments * [ios, macos] Cleaned up the implementation template * [ios, macos] removed unused function and added support for more datatypes * [ios, macos] overhauling the type protocols * [ios, macos] removed unnecessary style classes * [ios, macos] added support for more types * [ios, macos] fixed string and number prop values * [ios, macos] enum getters * [ios, macos] added removeLayer() and removed unused layer ref * [ios, macos] fixed remaining layer types and converted style layer into a protocol * [ios, macos] fixed addLayer() and added example for line layer * [ios] GeoJSON source now works * [ios] fixed raster layer and raster source * [ios] fixed attr prop number and outlined prop function * [ios] wip functions * [ios] bool and float function fix * [ios] cleanup * [macos] fixed support for macos * [ios] fixed string functions * [ios] extended array functions * [ios] added tests and fixed a few bugs * [ios] less verbose functions and improved tests * [ios, macos] Removed unnecessary use of default arguments Default arguments aren’t supported in Node v4, and they aren’t needed here anyways, because we’re only testing for truthiness. * [ios, macos] Enum setters Rely on a macro instead of category methods to specialize the setter implementation for enum attributes, since generic types are disallowed in Objective-C method signatures and mbgl::style::PropertyType must be type-qualified. * [ios, macos] Got macOS closer to parity w/ iOS Added various classes and test classes to the macOS workspace. Also fixed lots of compiler errors and updated macosapp runtime styling example to use the new dictionary syntax for function stops. Updated all conversions from Objective-C stops to C++ stops to enumerate over the dictionary. Fixed compiler errors in enum setter implementations. Also corrected path to script in generated file comments. * [ios, macos] Added EJS templates to project * [ios, macos] Code formatting Made code format more consistent. * [ios, macos] Spelled out ID Cocoa convention is to always spell out “ID” as “identifier”, in part to avoid confusion with the id keyword. Also, URL is capitalized in most contexts, including property names. * [ios, macos] Grouped related headers together * [ios, macos] Cleaned up layer transformation Also added support for converting background layers into Objective-C. * [ios, macos] Cleaned up tests Also made the tests work on macOS by introducing a new window to host the map. * [ios, macos] Replaced TODOs with #warnings * [ios] convert array based property values * [ios, macos] color function/undefined getter * [ios, macos] fixed function/undefined getters for bool and float properties * [ios, macos] more function/undefined property getters * [ios, macos] more type conversion and cleanup * [ios, macos] disable macos runtime styling tests for now * [ios, macos] cleaned up style code script * [ios, macos] more type conversion * [ios] added a base layer to handle visibility min/max zoom * [macos] fixed base layer * [ios, macos] use accessor methods * [ios, macos] cleanup * [ios, macos] add geojson to ios and macos * [macos] rebase fix * [ios, macos] fixed enum getters and added tests for enums * [ios, macos] added an update method to base layer * [ios, macos] added some documentation * [ios, macos] docs * [ios, macos] removed refs to filters for now * [ios, macos] various tail work * [ios, macos] missing import and incorrect type
Diffstat (limited to 'platform/ios/app')
-rw-r--r--platform/ios/app/MBXViewController.m96
1 files changed, 96 insertions, 0 deletions
diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m
index ef91c847be..df1c446c21 100644
--- a/platform/ios/app/MBXViewController.m
+++ b/platform/ios/app/MBXViewController.m
@@ -4,6 +4,7 @@
#import "MBXCustomCalloutView.h"
#import "MBXOfflinePacksTableViewController.h"
#import "MBXAnnotationView.h"
+#import "MGLFillStyleLayer.h"
#import <Mapbox/Mapbox.h>
@@ -200,6 +201,7 @@ static NSString * const MBXViewControllerAnnotationViewReuseIdentifer = @"MBXVie
@"Start World Tour",
@"Add Custom Callout Point",
@"Remove Annotations",
+ @"Runtime styling",
nil];
if (self.debugLoggingEnabled)
@@ -277,6 +279,10 @@ static NSString * const MBXViewControllerAnnotationViewReuseIdentifer = @"MBXVie
{
[self.mapView removeAnnotations:self.mapView.annotations];
}
+ else if (buttonIndex == actionSheet.firstOtherButtonIndex + 16)
+ {
+ [self testRuntimeStyling];
+ }
else if (buttonIndex == actionSheet.numberOfButtons - 2 && self.debugLoggingEnabled)
{
NSString *fileContents = [NSString stringWithContentsOfFile:[self telemetryDebugLogfilePath] encoding:NSUTF8StringEncoding error:nil];
@@ -436,6 +442,96 @@ static NSString * const MBXViewControllerAnnotationViewReuseIdentifer = @"MBXVie
[self.mapView showAnnotations:@[annotation] animated:YES];
}
+- (void)testRuntimeStyling
+{
+ [self styleWaterLayer];
+ [self styleRoadLayer];
+ [self styleRasterLayer];
+ [self styleGeoJSONSource];
+ [self styleSymbolLayer];
+
+ MGLFillStyleLayer *buildingLayer = (MGLFillStyleLayer *)[self.mapView.style layerWithIdentifier:@"building"];
+ buildingLayer.fillColor = [UIColor blackColor];
+
+ MGLLineStyleLayer *ferryLineLayer = (MGLLineStyleLayer *)[self.mapView.style layerWithIdentifier:@"ferry"];
+ ferryLineLayer.lineColor = [UIColor redColor];
+
+ MGLFillStyleLayer *parkLayer = (MGLFillStyleLayer *)[self.mapView.style layerWithIdentifier:@"park"];
+ [self.mapView.style removeLayer:parkLayer];
+}
+
+- (void)styleSymbolLayer
+{
+ MGLSymbolStyleLayer *stateLayer = (MGLSymbolStyleLayer *)[self.mapView.style layerWithIdentifier:@"state-label-lg"];
+ stateLayer.textColor = [UIColor redColor];
+}
+
+- (void)styleGeoJSONSource
+{
+ NSURL *geoJSONURL = [NSURL URLWithString:@"https://dl.dropboxusercontent.com/u/5285447/amsterdam.geojson"];
+ MGLGeoJSONSource *source = [[MGLGeoJSONSource alloc] initWithSourceIdentifier:@"ams" URL:geoJSONURL];
+ [self.mapView.style addSource:source];
+
+ MGLFillStyleLayer *fillLayer = [[MGLFillStyleLayer alloc] initWithLayerIdentifier:@"test" sourceIdentifier:@"ams"];
+ fillLayer.fillColor = [UIColor purpleColor];
+ [self.mapView.style addLayer:fillLayer];
+}
+
+- (void)styleRasterLayer
+{
+ NSURL *rasterURL = [NSURL URLWithString:@"mapbox://mapbox.satellite"];
+ MGLRasterSource *rasterSource = [[MGLRasterSource alloc] initWithSourceIdentifier:@"my-raster-source" URL:rasterURL tileSize:512];
+ [self.mapView.style addSource:rasterSource];
+
+ MGLRasterStyleLayer *rasterLayer = [[MGLRasterStyleLayer alloc] initWithLayerIdentifier:@"my-raster-layer" sourceIdentifier:@"my-raster-source"];
+ MGLStyleAttributeFunction *opacityFunction = [[MGLStyleAttributeFunction alloc] init];
+ opacityFunction.stops = @{@20.0f: @1.0f,
+ @5.0f: @0.0f};
+ rasterLayer.rasterOpacity = opacityFunction;
+ [self.mapView.style addLayer:rasterLayer];
+}
+
+- (void)styleWaterLayer
+{
+ MGLFillStyleLayer *waterLayer = (MGLFillStyleLayer *)[self.mapView.style layerWithIdentifier:@"water"];
+ MGLStyleAttributeFunction *waterColorFunction = [[MGLStyleAttributeFunction alloc] init];
+ waterColorFunction.stops = @{@6.0f: [UIColor yellowColor],
+ @8.0f: [UIColor blueColor],
+ @10.0f: [UIColor redColor],
+ @12.0f: [UIColor greenColor],
+ @14.0f: [UIColor blueColor]};
+ waterLayer.fillColor = waterColorFunction;
+
+ MGLStyleAttributeFunction *fillAntialias = [[MGLStyleAttributeFunction alloc] init];
+ fillAntialias.stops = @{@11: @YES,
+ @12: @NO,
+ @13: @YES,
+ @14: @NO,
+ @15: @YES};
+ waterLayer.fillAntialias = fillAntialias;
+
+ [waterLayer update];
+}
+
+- (void)styleRoadLayer
+{
+ MGLLineStyleLayer *roadLayer = (MGLLineStyleLayer *)[self.mapView.style layerWithIdentifier:@"road-primary"];
+ roadLayer.lineColor = [UIColor blackColor];
+ MGLStyleAttributeFunction *lineWidthFunction = [[MGLStyleAttributeFunction alloc] init];
+
+ MGLStyleAttributeFunction *roadLineColor = [[MGLStyleAttributeFunction alloc] init];
+ roadLineColor.stops = @{@10: [UIColor purpleColor],
+ @13: [UIColor yellowColor],
+ @16: [UIColor cyanColor]};
+ roadLayer.lineColor = roadLineColor;
+ roadLayer.lineWidth = lineWidthFunction;
+ roadLayer.lineGapWidth = lineWidthFunction;
+
+ roadLayer.visible = YES;
+ roadLayer.maximumZoomLevel = 15;
+ roadLayer.minimumZoomLevel = 13;
+}
+
- (IBAction)handleLongPress:(UILongPressGestureRecognizer *)longPress
{
if (longPress.state == UIGestureRecognizerStateBegan)