diff options
author | Jesse Bounds <jesse@rebounds.net> | 2017-02-08 12:27:12 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-08 12:27:12 -0800 |
commit | 06a8ed79598beae923b795dea711834b4775f6b0 (patch) | |
tree | 65afbaaf19bee1e7ed7508d6c3b49ee88aa6fc37 /platform/darwin/test/MGLStyleValueTests.swift | |
parent | 6d69686a12f5fb3761e3318410f5626198d0b92c (diff) | |
download | qtlocation-mapboxgl-06a8ed79598beae923b795dea711834b4775f6b0.tar.gz |
Add back MGLStyleFunction and re-document MGLStyleValue (#7943)
[ios, macos] Add back MGLStyleFunction and re-document MGLStyleValue
Diffstat (limited to 'platform/darwin/test/MGLStyleValueTests.swift')
-rw-r--r-- | platform/darwin/test/MGLStyleValueTests.swift | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/platform/darwin/test/MGLStyleValueTests.swift b/platform/darwin/test/MGLStyleValueTests.swift index 066232329f..afdc2ef9a3 100644 --- a/platform/darwin/test/MGLStyleValueTests.swift +++ b/platform/darwin/test/MGLStyleValueTests.swift @@ -38,6 +38,7 @@ extension MGLStyleValueTests { 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<NSNumber>(interpolationBase: 1.0, stops: [1: MGLStyleValue(rawValue: 0), @@ -63,6 +64,66 @@ extension MGLStyleValueTests { options: nil ) XCTAssertEqual(symbolStyleLayer.iconAllowsOverlap, expectedIconAllowsOverlapStyleValue) + + /// + // creating and using MGLStyleFunctions directly + /// + + let circleRadiusStops: [NSNumber: MGLStyleValue<NSNumber>] = [ + 0: MGLStyleValue(rawValue: 10), + 20: MGLStyleValue(rawValue: 5) + ] + let circleRadiusFunction = MGLStyleFunction<NSNumber>( + interpolationBase: 1.0, + stops: circleRadiusStops + ) + circleStyleLayer.circleRadius = circleRadiusFunction + let expectedCircleRadiusFunction = MGLStyleValue<NSNumber>( + 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<NSValue>] = [ + 0: MGLStyleValue<NSValue>(rawValue: circleTranslationValueOne), + 10: MGLStyleValue<NSValue>(rawValue: circleTranslationValueTwo) + ] + let circleTranslationFunction = MGLStyleFunction<NSValue>( + interpolationBase: 1.0, + stops: circleTranslationStops + ) + circleStyleLayer.circleTranslation = circleTranslationFunction + let expectedCircleTranslationFunction = MGLStyleValue<NSValue>( + 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<NSNumber>] = [ + 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() { @@ -293,6 +354,15 @@ extension MGLStyleValueTests { } } + // get value back as base class + if let returnedCircleRadius = circleStyleLayer.circleRadius as? MGLStyleFunction<NSNumber> { + if let returnedStops = returnedCircleRadius.stops as NSDictionary? as? [NSNumber: [NSNumber: MGLStyleValue<NSNumber>]] { + let lhs: MGLStyleValue<NSNumber> = returnedStops[0]!.values.first! + let rhs: MGLStyleValue<NSNumber> = radiusCompositeExponentialOrIntervalStops[0]!.values.first! + XCTAssertEqual(lhs, rhs) + } + } + // data-driven, composite function with inner interval color stop values nested in outer camera stops let expectedCompositeIntervalValue = MGLStyleValue<NSNumber>( interpolationMode: .interval, |