From 360e5bf631229e2aec71780a515a42e32d4c28e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Tue, 7 Feb 2017 18:26:49 -0800 Subject: [ios, macos] Fixed runtime styling deprecation warnings --- platform/darwin/test/MGLStyleTests.mm | 3 + platform/darwin/test/MGLStyleValueTests.m | 102 +++++++++++++++++++++++++- platform/darwin/test/MGLStyleValueTests.swift | 91 ----------------------- platform/macos/app/MapDocument.m | 12 +-- 4 files changed, 110 insertions(+), 98 deletions(-) diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm index ed86a252fa..c50330d488 100644 --- a/platform/darwin/test/MGLStyleTests.mm +++ b/platform/darwin/test/MGLStyleTests.mm @@ -246,7 +246,10 @@ } - (void)testClasses { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" XCTAssertEqual(self.style.styleClasses.count, 0); +#pragma clang diagnostic pop } - (void)testImages { diff --git a/platform/darwin/test/MGLStyleValueTests.m b/platform/darwin/test/MGLStyleValueTests.m index fe6096584d..cd6eec8324 100644 --- a/platform/darwin/test/MGLStyleValueTests.m +++ b/platform/darwin/test/MGLStyleValueTests.m @@ -7,7 +7,107 @@ @implementation MGLStyleValueTests - (void)testStoplessFunction { - XCTAssertThrowsSpecificNamed([MGLStyleValue valueWithStops:@{}], NSException, NSInvalidArgumentException, @"Stopless function should raise an exception"); + XCTAssertThrowsSpecificNamed([MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential cameraStops:@{} options:nil], NSException, NSInvalidArgumentException, @"Stopless function should raise an exception"); +} + +- (void)testDeprecatedFunctions { + MGLShapeSource *shapeSource = [[MGLShapeSource alloc] initWithIdentifier:@"test" + shape:nil + options:nil]; + MGLSymbolStyleLayer *symbolStyleLayer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"symbolLayer" + source:shapeSource]; + MGLCircleStyleLayer *circleStyleLayer = [[MGLCircleStyleLayer alloc] initWithIdentifier:@"circleLayer" + source:shapeSource]; + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + // deprecated function, stops with float values + NSDictionary *> *stops = @{ + @1: [MGLStyleValue valueWithRawValue:@0], + @2: [MGLStyleValue valueWithRawValue:@1], + @3: [MGLStyleValue valueWithRawValue:@2], + @4: [MGLStyleValue valueWithRawValue:@0], + }; + MGLStyleValue *iconHaloBlurStyleValue = + [MGLStyleValue valueWithInterpolationBase:1.0 stops:stops]; + symbolStyleLayer.iconHaloBlur = iconHaloBlurStyleValue; + XCTAssertEqualObjects(symbolStyleLayer.iconHaloBlur, iconHaloBlurStyleValue); + + // deprecated function, stops with boolean values + stops = @{ + @1: [MGLStyleValue valueWithRawValue:@YES], + @2: [MGLStyleValue valueWithRawValue:@NO], + @3: [MGLStyleValue valueWithRawValue:@YES], + @4: [MGLStyleValue valueWithRawValue:@NO], + }; + MGLStyleValue *iconAllowsOverlapStyleValue = + [MGLStyleValue valueWithInterpolationBase:1.0 stops:stops]; + symbolStyleLayer.iconAllowsOverlap = iconAllowsOverlapStyleValue; + // iconAllowsOverlap is boolean so mgl and mbgl conversions will coerce the developers stops into interval stops + MGLStyleValue *expectedIconAllowsOverlapStyleValue = + [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeInterval + cameraStops:stops + options:nil]; + XCTAssertEqualObjects(symbolStyleLayer.iconAllowsOverlap, expectedIconAllowsOverlapStyleValue); + + /// + // creating and using MGLStyleFunctions directly + /// + + NSDictionary *> *circleRadiusStops = @{ + @0: [MGLStyleValue valueWithRawValue:@10], + @20: [MGLStyleValue valueWithRawValue:@5], + }; + MGLStyleFunction *circleRadiusFunction = + [MGLStyleFunction functionWithInterpolationBase:1.0 + stops:circleRadiusStops]; + circleStyleLayer.circleRadius = circleRadiusFunction; + MGLStyleValue *expectedCircleRadiusFunction = + [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential + cameraStops:circleRadiusStops + options:nil]; + // setting a data driven property to an MGLStyleFunction should return an exponential camera function + XCTAssertEqualObjects(circleStyleLayer.circleRadius, expectedCircleRadiusFunction); + + CGVector circleTranslationOne = CGVectorMake(100, 0); + CGVector circleTranslationTwo = CGVectorMake(0, 0); +#if TARGET_OS_IPHONE + NSValue *circleTranslationValueOne = [NSValue valueWithCGVector:circleTranslationOne]; + NSValue *circleTranslationValueTwo = [NSValue valueWithCGVector:circleTranslationTwo]; +#else + NSValue *circleTranslationValueOne = [NSValue value:&circleTranslationOne withObjCType:@encode(CGVector)]; + NSValue *circleTranslationValueTwo = [NSValue value:&circleTranslationTwo withObjCType:@encode(CGVector)]; +#endif + + NSDictionary *> *circleTranslationStops = @{ + @0: [MGLStyleValue valueWithRawValue:circleTranslationValueOne], + @10: [MGLStyleValue valueWithRawValue:circleTranslationValueTwo], + }; + MGLStyleFunction *circleTranslationFunction = + [MGLStyleFunction functionWithInterpolationBase:1.0 + stops:circleTranslationStops]; + circleStyleLayer.circleTranslation = circleTranslationFunction; + MGLStyleValue *expectedCircleTranslationFunction = + [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential + cameraStops:circleTranslationStops + options:nil]; + // setting a non-data driven, interpolatable property to an MGLStyleFunction should return an exponential camera function + XCTAssertEqualObjects(circleStyleLayer.circleTranslation, expectedCircleTranslationFunction); + + NSDictionary *> *iconOptionalStops = @{ + @0: [MGLStyleValue valueWithRawValue:@NO], + @20: [MGLStyleValue valueWithRawValue:@YES], + }; + MGLStyleFunction *iconOptionalFunction = + [MGLStyleFunction valueWithInterpolationBase:1.0 + stops:iconOptionalStops]; + symbolStyleLayer.iconOptional = iconOptionalFunction; + MGLStyleValue *expectedIconOptionalFunction = + [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeInterval + cameraStops:iconOptionalStops + options:nil]; + XCTAssertEqualObjects(symbolStyleLayer.iconOptional, expectedIconOptionalFunction); +#pragma clang diagnostic pop } @end diff --git a/platform/darwin/test/MGLStyleValueTests.swift b/platform/darwin/test/MGLStyleValueTests.swift index afdc2ef9a3..a8c4aaf71a 100644 --- a/platform/darwin/test/MGLStyleValueTests.swift +++ b/platform/darwin/test/MGLStyleValueTests.swift @@ -35,97 +35,6 @@ extension MGLStyleValueTests { XCTAssertEqual(circleStyleLayer.circleScaleAlignment, expectedCircleScaleAlignmentValue) } - func testDeprecatedFunctions() { - let shapeSource = MGLShapeSource(identifier: "test", shape: nil, options: nil) - let symbolStyleLayer = MGLSymbolStyleLayer(identifier: "symbolLayer", source: shapeSource) - let circleStyleLayer = MGLCircleStyleLayer(identifier: "circleLayer", source: shapeSource) - - // deprecated function, stops with float values - let iconHaloBlurStyleValue = MGLStyleValue(interpolationBase: 1.0, stops: [1: MGLStyleValue(rawValue: 0), - 2: MGLStyleValue(rawValue: 1), - 3: MGLStyleValue(rawValue: 2), - 4: MGLStyleValue(rawValue: 3)]) - symbolStyleLayer.iconHaloBlur = iconHaloBlurStyleValue - XCTAssertEqual(symbolStyleLayer.iconHaloBlur!, iconHaloBlurStyleValue) - - // deprecated function, stops with boolean values - let stops: [NSNumber: MGLStyleValue] = [ - 1: MGLStyleValue(rawValue: true), - 2: MGLStyleValue(rawValue: false), - 3: MGLStyleValue(rawValue: true), - 4: MGLStyleValue(rawValue: false), - ] - let iconAllowsOverlapStyleValue = MGLStyleValue(interpolationBase: 1, stops: stops) - symbolStyleLayer.iconAllowsOverlap = iconAllowsOverlapStyleValue - // iconAllowsOverlap is boolean so mgl and mbgl conversions will coerce the developers stops into interval stops - let expectedIconAllowsOverlapStyleValue = MGLStyleValue( - interpolationMode: .interval, - cameraStops: stops, - options: nil - ) - XCTAssertEqual(symbolStyleLayer.iconAllowsOverlap, expectedIconAllowsOverlapStyleValue) - - /// - // creating and using MGLStyleFunctions directly - /// - - let circleRadiusStops: [NSNumber: MGLStyleValue] = [ - 0: MGLStyleValue(rawValue: 10), - 20: MGLStyleValue(rawValue: 5) - ] - let circleRadiusFunction = MGLStyleFunction( - interpolationBase: 1.0, - stops: circleRadiusStops - ) - circleStyleLayer.circleRadius = circleRadiusFunction - let expectedCircleRadiusFunction = MGLStyleValue( - interpolationMode: .exponential, - cameraStops: - circleRadiusStops, - options: nil - ) - // setting a data driven property to an MGLStyleFunction should return an exponential camera function - XCTAssertEqual(circleStyleLayer.circleRadius, expectedCircleRadiusFunction) - - var circleTranslationOne = CGVector(dx: 100, dy: 0) - let circleTranslationValueOne = NSValue(bytes: &circleTranslationOne, objCType: "{CGVector=dd}") - var circleTranslationTwo = CGVector(dx: 0, dy: 0) - let circleTranslationValueTwo = NSValue(bytes: &circleTranslationTwo, objCType: "{CGVector=dd}") - - let circleTranslationStops: [NSNumber: MGLStyleValue] = [ - 0: MGLStyleValue(rawValue: circleTranslationValueOne), - 10: MGLStyleValue(rawValue: circleTranslationValueTwo) - ] - let circleTranslationFunction = MGLStyleFunction( - interpolationBase: 1.0, - stops: circleTranslationStops - ) - circleStyleLayer.circleTranslation = circleTranslationFunction - let expectedCircleTranslationFunction = MGLStyleValue( - interpolationMode: .exponential, - cameraStops: circleTranslationStops, - options: nil - ) - // setting a non-data driven, interpolatable property to an MGLStyleFunction should return an exponential camera function - XCTAssertEqual(circleStyleLayer.circleTranslation, expectedCircleTranslationFunction) - - let iconOptionalStops: [NSNumber: MGLStyleValue] = [ - 0: MGLStyleValue(rawValue: false), - 20: MGLStyleValue(rawValue: true) - ] - let iconOptionalFunction = MGLStyleFunction( - interpolationBase: 1.0, - stops: iconOptionalStops - ) - symbolStyleLayer.iconOptional = iconOptionalFunction - let expectedIconOptionalFunction = MGLStyleValue( - interpolationMode: .interval, - cameraStops: iconOptionalStops, - options: nil - ) - XCTAssertEqual(symbolStyleLayer.iconOptional, expectedIconOptionalFunction) - } - func testFunctionsWithNonDataDrivenProperties() { let shapeSource = MGLShapeSource(identifier: "test", shape: nil, options: nil) let circleStyleLayer = MGLCircleStyleLayer(identifier: "circleLayer", source: shapeSource) diff --git a/platform/macos/app/MapDocument.m b/platform/macos/app/MapDocument.m index 62ddd2ce60..6f63542527 100644 --- a/platform/macos/app/MapDocument.m +++ b/platform/macos/app/MapDocument.m @@ -689,11 +689,11 @@ NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id valueWithStops:@{ + MGLStyleValue *colorFunction = [MGLStyleValue valueWithInterpolationMode:MGLInterpolationModeExponential cameraStops:@{ @0.0: [MGLStyleValue valueWithRawValue:[NSColor redColor]], @10.0: [MGLStyleValue valueWithRawValue:[NSColor yellowColor]], @20.0: [MGLStyleValue valueWithRawValue:[NSColor blackColor]], - }]; + } options:nil]; fillStyleLayer.fillColor = colorFunction; NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"amsterdam" ofType:@"geojson"]; @@ -715,11 +715,11 @@ NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id ) *MBXFlattenedShapes(NS_ARRAY_OF(id )annotation { if ([annotation isKindOfClass:[DroppedPinAnnotation class]]) { - DroppedPinAnnotation *droppedPin = annotation; + DroppedPinAnnotation *droppedPin = (DroppedPinAnnotation *)annotation; [droppedPin resume]; } } - (void)mapView:(MGLMapView *)mapView didDeselectAnnotation:(id )annotation { if ([annotation isKindOfClass:[DroppedPinAnnotation class]]) { - DroppedPinAnnotation *droppedPin = annotation; + DroppedPinAnnotation *droppedPin = (DroppedPinAnnotation *)annotation; [droppedPin pause]; } } -- cgit v1.2.1