From 1f4e3e0f6e1a568007f647102459e50cb98b63ca Mon Sep 17 00:00:00 2001 From: Julian Rex Date: Thu, 26 Apr 2018 12:40:26 -0400 Subject: [ios, macos] Raise exceptions for empty expression stops dictionaries (#9539) --- platform/darwin/src/NSExpression+MGLAdditions.mm | 16 ++++++++++++++-- platform/darwin/test/MGLExpressionTests.mm | 10 ++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) (limited to 'platform/darwin') diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index c82a7dc008..8db839c5da 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -1258,9 +1258,15 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { NSArray *controlPoints = [self.arguments[curveTypeIndex + 1].collection mgl_jsonExpressionObject]; [interpolationArray addObjectsFromArray:controlPoints]; } + + NSDictionary *stops = self.arguments[curveTypeIndex + 2].constantValue; + + if (stops.count == 0) { + [NSException raise:NSInvalidArgumentException format:@"‘stops‘ dictionary argument to ‘%@’ function must not be empty.", self.function]; + } + NSMutableArray *expressionObject = [NSMutableArray arrayWithObjects:@"interpolate", interpolationArray, nil]; [expressionObject addObject:(isAftermarketFunction ? self.arguments.firstObject : self.operand).mgl_jsonExpressionObject]; - NSDictionary *stops = self.arguments[curveTypeIndex + 2].constantValue; for (NSNumber *key in [stops.allKeys sortedArrayUsingSelector:@selector(compare:)]) { [expressionObject addObject:key]; [expressionObject addObject:[stops[key] mgl_jsonExpressionObject]]; @@ -1272,8 +1278,14 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { BOOL isAftermarketFunction = [self.function isEqualToString:@"mgl_step:from:stops:"]; NSUInteger minimumIndex = isAftermarketFunction ? 1 : 0; id minimum = self.arguments[minimumIndex].mgl_jsonExpressionObject; - NSMutableArray *expressionObject = [NSMutableArray arrayWithObjects:@"step", (isAftermarketFunction ? self.arguments.firstObject : self.operand).mgl_jsonExpressionObject, minimum, nil]; NSDictionary *stops = self.arguments[minimumIndex + 1].constantValue; + + if (stops.count == 0) { + [NSException raise:NSInvalidArgumentException format:@"‘stops‘ dictionary argument to ‘%@’ function must not be empty.", self.function]; + } + + NSMutableArray *expressionObject = [NSMutableArray arrayWithObjects:@"step", (isAftermarketFunction ? self.arguments.firstObject : self.operand).mgl_jsonExpressionObject, minimum, nil]; + for (NSNumber *key in [stops.allKeys sortedArrayUsingSelector:@selector(compare:)]) { [expressionObject addObject:key]; [expressionObject addObject:[stops[key] mgl_jsonExpressionObject]]; diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm index d54e961b00..9c75dedaa3 100644 --- a/platform/darwin/test/MGLExpressionTests.mm +++ b/platform/darwin/test/MGLExpressionTests.mm @@ -710,6 +710,16 @@ using namespace std::string_literals; XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); } + { + NSDictionary *stops = @{}; + NSExpression *expression = [NSExpression expressionWithFormat:@"mgl_interpolate:withCurveType:parameters:stops:(x, 'cubic-bezier', { 0.42, 0, 0.58, 1 }, %@)", stops]; + XCTAssertThrowsSpecificNamed(expression.mgl_jsonExpressionObject, NSException, NSInvalidArgumentException); + } + { + NSDictionary *stops = @{}; + NSExpression *expression = [NSExpression expressionWithFormat:@"mgl_step:from:stops:($zoomLevel, 11, %@)", stops]; + XCTAssertThrowsSpecificNamed(expression.mgl_jsonExpressionObject, NSException, NSInvalidArgumentException); + } } - (void)testMatchExpressionObject { -- cgit v1.2.1 From 4f7999fd1cec34e9beaf130d30897548d8dbca4a Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Tue, 24 Apr 2018 19:21:50 -0400 Subject: [ios, macos] Accept Xcode 9.3 project suggestions - Fix duplicate NSExpression+MGLAdditions.h and fix target membership - Explicitly cast NSUInteger to unsigned long before printing --- platform/darwin/src/NSExpression+MGLAdditions.mm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'platform/darwin') diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index 8db839c5da..633f433a8f 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -1218,7 +1218,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { case NSAnyKeyExpressionType: case NSBlockExpressionType: [NSException raise:NSInvalidArgumentException - format:@"Expression type %lu not yet implemented.", self.expressionType]; + format:@"Expression type %lu not yet implemented.", (unsigned long)self.expressionType]; } // NSKeyPathSpecifierExpression @@ -1240,11 +1240,11 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { if (self.arguments.count < expectedArgumentCount) { [NSException raise:NSInvalidArgumentException format: @"Too few arguments to ‘%@’ function; expected %lu arguments.", - self.function, expectedArgumentCount]; + self.function, (unsigned long)expectedArgumentCount]; } else if (self.arguments.count > expectedArgumentCount) { [NSException raise:NSInvalidArgumentException format: @"%lu unexpected arguments to ‘%@’ function; expected %lu arguments.", - self.arguments.count - expectedArgumentCount, self.function, expectedArgumentCount]; + self.arguments.count - (unsigned long)expectedArgumentCount, self.function, (unsigned long)expectedArgumentCount]; } BOOL isAftermarketFunction = [self.function isEqualToString:@"mgl_interpolate:withCurveType:parameters:stops:"]; -- cgit v1.2.1 From 5a147f6335314defeed26c570ebcfe217e2af5d9 Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Tue, 24 Apr 2018 20:32:43 -0400 Subject: [ios, macos] Fix possible retain cycles in blocks Prompted by enabling CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF. --- platform/darwin/src/MGLMapSnapshotter.mm | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'platform/darwin') diff --git a/platform/darwin/src/MGLMapSnapshotter.mm b/platform/darwin/src/MGLMapSnapshotter.mm index 11a5442761..6449a7fd4f 100644 --- a/platform/darwin/src/MGLMapSnapshotter.mm +++ b/platform/darwin/src/MGLMapSnapshotter.mm @@ -122,8 +122,7 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64; _snapshotCallback = std::make_unique>(*mbgl::Scheduler::GetCurrent(), [=](std::exception_ptr mbglError, mbgl::PremultipliedImage image, mbgl::MapSnapshotter::Attributions attributions, mbgl::MapSnapshotter::PointForFn pointForFn) { __typeof__(self) strongSelf = weakSelf; strongSelf.loading = false; - - + if (mbglError) { NSString *description = @(mbgl::util::toString(mbglError).c_str()); NSDictionary *userInfo = @{NSLocalizedDescriptionKey: description}; @@ -145,9 +144,13 @@ const CGFloat MGLSnapshotterMinimumPixelSize = 64; } _snapshotCallback = NULL; }); - dispatch_async(queue, ^{ - _mbglMapSnapshotter->snapshot(_snapshotCallback->self()); + dispatch_async(queue, ^{ + __typeof__(self) strongSelf = weakSelf; + if (!strongSelf) { + return; + } + strongSelf->_mbglMapSnapshotter->snapshot(strongSelf->_snapshotCallback->self()); }); } -- cgit v1.2.1 From ea59ba8209604c91b76abb31e6be15932bcb3430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Fri, 27 Apr 2018 12:07:28 -0700 Subject: [android, ios, macos] Added Korean localization --- .../darwin/resources/ko.lproj/Foundation.strings | 297 +++++++++++++++++++++ .../resources/ko.lproj/Foundation.stringsdict | 48 ++++ 2 files changed, 345 insertions(+) create mode 100644 platform/darwin/resources/ko.lproj/Foundation.strings create mode 100644 platform/darwin/resources/ko.lproj/Foundation.stringsdict (limited to 'platform/darwin') diff --git a/platform/darwin/resources/ko.lproj/Foundation.strings b/platform/darwin/resources/ko.lproj/Foundation.strings new file mode 100644 index 0000000000..68e6cf86fc --- /dev/null +++ b/platform/darwin/resources/ko.lproj/Foundation.strings @@ -0,0 +1,297 @@ +/* Clock position format, long: {hours} o’clock */ +"CLOCK_FMT_LONG" = "%@ 시"; + +/* Clock position format, medium: {hours} o’clock */ +"CLOCK_FMT_MEDIUM" = "%@ 시"; + +/* Clock position format, short: {hours}:00 */ +"CLOCK_FMT_SHORT" = "%@:00"; + +/* East, long */ +"COMPASS_E_LONG" = "동쪽"; + +/* East, short */ +"COMPASS_E_SHORT" = "동"; + +/* East by north, long */ +"COMPASS_EbN_LONG" = "동미북쪽"; + +/* East by north, short */ +"COMPASS_EbN_SHORT" = "동미북"; + +/* East by south, long */ +"COMPASS_EbS_LONG" = "동미남쪽"; + +/* East by south, short */ +"COMPASS_EbS_SHORT" = "동미남"; + +/* East-northeast, long */ +"COMPASS_ENE_LONG" = "동북동쪽"; + +/* East-northeast, short */ +"COMPASS_ENE_SHORT" = "동북동"; + +/* East-southeast, long */ +"COMPASS_ESE_LONG" = "동남동쪽"; + +/* East-southeast, short */ +"COMPASS_ESE_SHORT" = "동남동"; + +/* North, long */ +"COMPASS_N_LONG" = "북쪽"; + +/* North, short */ +"COMPASS_N_SHORT" = "북"; + +/* North by east, long */ +"COMPASS_NbE_LONG" = "북미동쪽"; + +/* North by east, short */ +"COMPASS_NbE_SHORT" = "북미동"; + +/* North by west, long */ +"COMPASS_NbW_LONG" = "북미서쪽"; + +/* North by west, short */ +"COMPASS_NbW_SHORT" = "북미서"; + +/* Northeast, long */ +"COMPASS_NE_LONG" = "북동쪽"; + +/* Northeast, short */ +"COMPASS_NE_SHORT" = "북동"; + +/* Northeast by east, long */ +"COMPASS_NEbE_LONG" = "북동미동쪽"; + +/* Northeast by east, short */ +"COMPASS_NEbE_SHORT" = "북동미동"; + +/* Northeast by north, long */ +"COMPASS_NEbN_LONG" = "북동미북쪽"; + +/* Northeast by north, short */ +"COMPASS_NEbN_SHORT" = "북동미북"; + +/* North-northeast, long */ +"COMPASS_NNE_LONG" = "북북동쪽"; + +/* North-northeast, short */ +"COMPASS_NNE_SHORT" = "북북동"; + +/* North-northwest, long */ +"COMPASS_NNW_LONG" = "북북서쪽"; + +/* North-northwest, short */ +"COMPASS_NNW_SHORT" = "북북서"; + +/* Northwest, long */ +"COMPASS_NW_LONG" = "북서쪽"; + +/* Northwest, short */ +"COMPASS_NW_SHORT" = "북서"; + +/* Northwest by north, long */ +"COMPASS_NWbN_LONG" = "북서미북쪽"; + +/* Northwest by north, short */ +"COMPASS_NWbN_SHORT" = "북서미북"; + +/* Northwest by west, long */ +"COMPASS_NWbW_LONG" = "북서미서쪽"; + +/* Northwest by west, short */ +"COMPASS_NWbW_SHORT" = "북서미서"; + +/* South, long */ +"COMPASS_S_LONG" = "남쪽"; + +/* South, short */ +"COMPASS_S_SHORT" = "남"; + +/* South by east, long */ +"COMPASS_SbE_LONG" = "남미동쪽"; + +/* South by east, short */ +"COMPASS_SbE_SHORT" = "남미동"; + +/* South by west, long */ +"COMPASS_SbW_LONG" = "남미서"; + +/* South by west, short */ +"COMPASS_SbW_SHORT" = "남미서"; + +/* Southeast, long */ +"COMPASS_SE_LONG" = "남동쪽"; + +/* Southeast, short */ +"COMPASS_SE_SHORT" = "남동"; + +/* Southeast by east, long */ +"COMPASS_SEbE_LONG" = "남동미동쪽"; + +/* Southeast by east, short */ +"COMPASS_SEbE_SHORT" = "남동미동"; + +/* Southeast by south, long */ +"COMPASS_SEbS_LONG" = "남동미남쪽"; + +/* Southeast by south, short */ +"COMPASS_SEbS_SHORT" = "남동미남"; + +/* South-southeast, long */ +"COMPASS_SSE_LONG" = "남남동쪽"; + +/* South-southeast, short */ +"COMPASS_SSE_SHORT" = "남남동"; + +/* South-southwest, long */ +"COMPASS_SSW_LONG" = "남남서쪽"; + +/* South-southwest, short */ +"COMPASS_SSW_SHORT" = "남남서"; + +/* Southwest, long */ +"COMPASS_SW_LONG" = "남서쪽"; + +/* Southwest, short */ +"COMPASS_SW_SHORT" = "남서"; + +/* Southwest by south, long */ +"COMPASS_SWbS_LONG" = "남서미남쪽"; + +/* Southwest by south, short */ +"COMPASS_SWbS_SHORT" = "남서미남"; + +/* Southwest by west, long */ +"COMPASS_SWbW_LONG" = "남서미서쪽"; + +/* Southwest by west, short */ +"COMPASS_SWbW_SHORT" = "남서미서"; + +/* West, long */ +"COMPASS_W_LONG" = "서쪽"; + +/* West, short */ +"COMPASS_W_SHORT" = "서"; + +/* West by north, long */ +"COMPASS_WbN_LONG" = "서미북쪽"; + +/* West by north, short */ +"COMPASS_WbN_SHORT" = "서미북"; + +/* West by south, long */ +"COMPASS_WbS_LONG" = "서미남쪽"; + +/* West by south, short */ +"COMPASS_WbS_SHORT" = "서미남"; + +/* West-northwest, long */ +"COMPASS_WNW_LONG" = "서북서쪽"; + +/* West-northwest, short */ +"COMPASS_WNW_SHORT" = "서북서"; + +/* West-southwest, long */ +"COMPASS_WSW_LONG" = "서남서쪽"; + +/* West-southwest, short */ +"COMPASS_WSW_SHORT" = "서남서"; + +/* Degrees format, long */ +"COORD_DEG_LONG" = "%d 도"; + +/* Degrees format, medium: {degrees} */ +"COORD_DEG_MEDIUM" = "%d°"; + +/* Degrees format, short: {degrees} */ +"COORD_DEG_SHORT" = "%d°"; + +/* Coordinate format, long: {degrees}{minutes} */ +"COORD_DM_LONG" = "%1$@ 와 %2$@"; + +/* Coordinate format, medium: {degrees}{minutes} */ +"COORD_DM_MEDIUM" = "%1$@%2$@"; + +/* Coordinate format, short: {degrees}{minutes} */ +"COORD_DM_SHORT" = "%1$@%2$@"; + +/* Coordinate format, long: {degrees}{minutes}{seconds} */ +"COORD_DMS_LONG" = "%1$@, %2$@, 와 %3$@"; + +/* Coordinate format, medium: {degrees}{minutes}{seconds} */ +"COORD_DMS_MEDIUM" = "%1$@%2$@%3$@"; + +/* Coordinate format, short: {degrees}{minutes}{seconds} */ +"COORD_DMS_SHORT" = "%1$@%2$@%3$@"; + +/* East longitude format, long: {longitude} */ +"COORD_E_LONG" = "%@ 동쪽"; + +/* East longitude format, medium: {longitude} */ +"COORD_E_MEDIUM" = "%@ 동쪽"; + +/* East longitude format, short: {longitude} */ +"COORD_E_SHORT" = "%@동"; + +/* Coordinate pair format, long: {latitude}, {longitude} */ +"COORD_FMT_LONG" = "%1$@ by %2$@"; + +/* Coordinate pair format, medium: {latitude}, {longitude} */ +"COORD_FMT_MEDIUM" = "%1$@, %2$@"; + +/* Coordinate pair format, short: {latitude}, {longitude} */ +"COORD_FMT_SHORT" = "%1$@, %2$@"; + +/* Minutes format, long */ +"COORD_MIN_LONG" = "%d 분"; + +/* Minutes format, medium: {minutes} */ +"COORD_MIN_MEDIUM" = "%d′"; + +/* Minutes format, short: {minutes} */ +"COORD_MIN_SHORT" = "%d′"; + +/* North latitude format, long: {latitude} */ +"COORD_N_LONG" = "%@ 북쪽"; + +/* North latitude format, medium: {latitude} */ +"COORD_N_MEDIUM" = "%@ 북쪽"; + +/* North latitude format, short: {latitude} */ +"COORD_N_SHORT" = "%@북"; + +/* South latitude format, long: {latitude} */ +"COORD_S_LONG" = "%@ 남쪽"; + +/* South latitude format, medium: {latitude} */ +"COORD_S_MEDIUM" = "%@ 남쪽"; + +/* South latitude format, short: {latitude} */ +"COORD_S_SHORT" = "%@남"; + +/* Seconds format, long */ +"COORD_SEC_LONG" = "%d 초"; + +/* Seconds format, medium: {seconds} */ +"COORD_SEC_MEDIUM" = "%d″"; + +/* Seconds format, short: {seconds} */ +"COORD_SEC_SHORT" = "%d″"; + +/* West longitude format, long: {longitude} */ +"COORD_W_LONG" = "%@ 서쪽"; + +/* West longitude format, medium: {longitude} */ +"COORD_W_MEDIUM" = "%@ 서쪽"; + +/* West longitude format, short: {longitude} */ +"COORD_W_SHORT" = "%@서"; + +/* OpenStreetMap full name attribution */ +"OSM_FULL_NAME" = "오픈스트리트맵"; + +/* OpenStreetMap short name attribution */ +"OSM_SHORT_NAME" = "오픈스트리트맵"; + diff --git a/platform/darwin/resources/ko.lproj/Foundation.stringsdict b/platform/darwin/resources/ko.lproj/Foundation.stringsdict new file mode 100644 index 0000000000..56d26aa949 --- /dev/null +++ b/platform/darwin/resources/ko.lproj/Foundation.stringsdict @@ -0,0 +1,48 @@ + + + + + COORD_DEG_LONG + + NSStringLocalizedFormatKey + %#@degrees@ + degrees + + NSStringFormatSpecTypeKey + NSStringPluralRuleType + NSStringFormatValueTypeKey + d + other + %d 도 + + + COORD_MIN_LONG + + NSStringLocalizedFormatKey + %#@minutes@ + minutes + + NSStringFormatSpecTypeKey + NSStringPluralRuleType + NSStringFormatValueTypeKey + d + other + %d 분 + + + COORD_SEC_LONG + + NSStringLocalizedFormatKey + %#@seconds@ + seconds + + NSStringFormatSpecTypeKey + NSStringPluralRuleType + NSStringFormatValueTypeKey + d + other + %d 초 + + + + -- cgit v1.2.1 From 8b713d937343c8c4aafb1387279c1eec11e5ab95 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 2 May 2018 12:34:50 -0700 Subject: [ios, macos] Avoid implicit capture of MBGLOfflineRegionObserver this pointer MBGLOfflineRegionObserver is owned by the offline database thread, and might be destroyed by the time the dispatch_async completes. Instead of implicitly capturing this, capture a copy of the MBGLOfflinePack weak pointer. --- platform/darwin/src/MGLOfflinePack.mm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'platform/darwin') diff --git a/platform/darwin/src/MGLOfflinePack.mm b/platform/darwin/src/MGLOfflinePack.mm index 60a7b55531..4653021a58 100644 --- a/platform/darwin/src/MGLOfflinePack.mm +++ b/platform/darwin/src/MGLOfflinePack.mm @@ -227,19 +227,22 @@ NSError *MGLErrorFromResponseError(mbgl::Response::Error error) { @end void MBGLOfflineRegionObserver::statusChanged(mbgl::OfflineRegionStatus status) { + __weak MGLOfflinePack *weakPack = pack; dispatch_async(dispatch_get_main_queue(), ^{ - [pack offlineRegionStatusDidChange:status]; + [weakPack offlineRegionStatusDidChange:status]; }); } void MBGLOfflineRegionObserver::responseError(mbgl::Response::Error error) { + __weak MGLOfflinePack *weakPack = pack; dispatch_async(dispatch_get_main_queue(), ^{ - [pack didReceiveError:MGLErrorFromResponseError(error)]; + [weakPack didReceiveError:MGLErrorFromResponseError(error)]; }); } void MBGLOfflineRegionObserver::mapboxTileCountLimitExceeded(uint64_t limit) { + __weak MGLOfflinePack *weakPack = pack; dispatch_async(dispatch_get_main_queue(), ^{ - [pack didReceiveMaximumAllowedMapboxTiles:limit]; + [weakPack didReceiveMaximumAllowedMapboxTiles:limit]; }); } -- cgit v1.2.1 From 844a8244097c18ae12e9c14baaaaad8a2f7ef436 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Soto Date: Thu, 3 May 2018 09:11:42 -0400 Subject: [ios, macos] Fix broken link to predicates and expressions guide. (#11818) --- platform/darwin/docs/guides/For Style Authors.md.ejs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'platform/darwin') diff --git a/platform/darwin/docs/guides/For Style Authors.md.ejs b/platform/darwin/docs/guides/For Style Authors.md.ejs index 2ae6602224..b0ded7bc03 100644 --- a/platform/darwin/docs/guides/For Style Authors.md.ejs +++ b/platform/darwin/docs/guides/For Style Authors.md.ejs @@ -272,7 +272,7 @@ Each property representing a layout or paint attribute is set to an but you create the former using a very different syntax. `NSExpression`’s format string syntax is reminiscent of a spreadsheet formula or an expression in a database query. See the -“[Predicates and Expressions](Predicates and Expressions.md)” guide for an +“[Predicates and Expressions](predicates-and-expressions.html)” guide for an overview of the expression support in this SDK. This SDK no longer supports style functions; use expressions instead. @@ -427,5 +427,5 @@ In style JSON | In the format string `["any", f0, …, fn]` | `p0 OR … OR pn` `["none", f0, …, fn]` | `NOT (p0 OR … OR pn)` -See the “[Predicates and Expressions](Predicates and Expressions.md)” guide for +See the “[Predicates and Expressions](predicates-and-expressions.html)” guide for a full description of the supported operators and operand types. -- cgit v1.2.1 From f6da3ba9be27ff9b279730603c517c4cb5e57007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Thu, 3 May 2018 21:48:58 +0200 Subject: iOS: Add custom layer example to debugging app (#7734) --- platform/darwin/app/LimeGreenStyleLayer.h | 5 +++ platform/darwin/app/LimeGreenStyleLayer.m | 58 +++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 platform/darwin/app/LimeGreenStyleLayer.h create mode 100644 platform/darwin/app/LimeGreenStyleLayer.m (limited to 'platform/darwin') diff --git a/platform/darwin/app/LimeGreenStyleLayer.h b/platform/darwin/app/LimeGreenStyleLayer.h new file mode 100644 index 0000000000..35480963a4 --- /dev/null +++ b/platform/darwin/app/LimeGreenStyleLayer.h @@ -0,0 +1,5 @@ +#import + +@interface LimeGreenStyleLayer : MGLOpenGLStyleLayer + +@end diff --git a/platform/darwin/app/LimeGreenStyleLayer.m b/platform/darwin/app/LimeGreenStyleLayer.m new file mode 100644 index 0000000000..98e96381b6 --- /dev/null +++ b/platform/darwin/app/LimeGreenStyleLayer.m @@ -0,0 +1,58 @@ +#import "LimeGreenStyleLayer.h" +@import GLKit; + +@implementation LimeGreenStyleLayer { + GLuint _program; + GLuint _vertexShader; + GLuint _fragmentShader; + GLuint _buffer; + GLuint _aPos; +} + +- (void)didMoveToMapView:(MGLMapView *)mapView { + static const GLchar *vertexShaderSource = "attribute vec2 a_pos; void main() { gl_Position = vec4(a_pos, 1, 1); }"; + static const GLchar *fragmentShaderSource = "void main() { gl_FragColor = vec4(0, 0.5, 0, 0.5); }"; + + _program = glCreateProgram(); + _vertexShader = glCreateShader(GL_VERTEX_SHADER); + _fragmentShader = glCreateShader(GL_FRAGMENT_SHADER); + + glShaderSource(_vertexShader, 1, &vertexShaderSource, NULL); + glCompileShader(_vertexShader); + glAttachShader(_program, _vertexShader); + glShaderSource(_fragmentShader, 1, &fragmentShaderSource, NULL); + glCompileShader(_fragmentShader); + glAttachShader(_program, _fragmentShader); + glLinkProgram(_program); + _aPos = glGetAttribLocation(_program, "a_pos"); + + GLfloat triangle[] = { 0, 0.5, 0.5, -0.5, -0.5, -0.5 }; + glGenBuffers(1, &_buffer); + glBindBuffer(GL_ARRAY_BUFFER, _buffer); + glBufferData(GL_ARRAY_BUFFER, 6 * sizeof(GLfloat), triangle, GL_STATIC_DRAW); +} + +- (void)drawInMapView:(MGLMapView *)mapView withContext:(MGLStyleLayerDrawingContext)context { + glUseProgram(_program); + glBindBuffer(GL_ARRAY_BUFFER, _buffer); + glEnableVertexAttribArray(_aPos); + glVertexAttribPointer(_aPos, 2, GL_FLOAT, GL_FALSE, 0, NULL); + glDisable(GL_STENCIL_TEST); + glDisable(GL_DEPTH_TEST); + glDrawArrays(GL_TRIANGLE_STRIP, 0, 3); +} + +- (void)willMoveFromMapView:(MGLMapView *)mapView { + if (!_program) { + return; + } + + glDeleteBuffers(1, &_buffer); + glDetachShader(_program, _vertexShader); + glDetachShader(_program, _fragmentShader); + glDeleteShader(_vertexShader); + glDeleteShader(_fragmentShader); + glDeleteProgram(_program); +} + +@end -- cgit v1.2.1 From 86a2e93294b472898cfd005a4c34818551de0728 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Soto Date: Fri, 4 May 2018 12:49:58 -0400 Subject: [ios, macos] Fix overlay bounds that span the antimeridian. (#11783) * [ios, macos] Fix overlay bounds that span the antimeridian. * [ios, macos] Update changelogs. * [ios, macos] Make MGLLocationCoordinate2DIsValid private. * [ios, macos] Update changelogs. --- platform/darwin/src/MGLGeometry_Private.h | 11 ++++++++++ platform/darwin/src/MGLMultiPoint.mm | 2 +- platform/darwin/src/MGLOverlay.h | 5 +++++ platform/darwin/src/MGLPointCollection.mm | 2 +- platform/darwin/test/MGLGeometryTests.mm | 36 +++++++++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 2 deletions(-) (limited to 'platform/darwin') diff --git a/platform/darwin/src/MGLGeometry_Private.h b/platform/darwin/src/MGLGeometry_Private.h index 0bff9b09f5..d0d9446a5f 100644 --- a/platform/darwin/src/MGLGeometry_Private.h +++ b/platform/darwin/src/MGLGeometry_Private.h @@ -71,6 +71,17 @@ NS_INLINE MGLCoordinateQuad MGLCoordinateQuadFromLatLngArray(std::array= -90.0 && + coordinate.longitude <= 360.0 && + coordinate.longitude >= -360.0); +} + #if TARGET_OS_IPHONE NS_INLINE mbgl::EdgeInsets MGLEdgeInsetsFromNSEdgeInsets(UIEdgeInsets insets) { return { insets.top, insets.left, insets.bottom, insets.right }; diff --git a/platform/darwin/src/MGLMultiPoint.mm b/platform/darwin/src/MGLMultiPoint.mm index 240dad9614..75638fec97 100644 --- a/platform/darwin/src/MGLMultiPoint.mm +++ b/platform/darwin/src/MGLMultiPoint.mm @@ -163,7 +163,7 @@ if (!_bounds) { mbgl::LatLngBounds bounds = mbgl::LatLngBounds::empty(); for (auto coordinate : _coordinates) { - if (!CLLocationCoordinate2DIsValid(coordinate)) { + if (!MGLLocationCoordinate2DIsValid(coordinate)) { bounds = mbgl::LatLngBounds::empty(); break; } diff --git a/platform/darwin/src/MGLOverlay.h b/platform/darwin/src/MGLOverlay.h index 462a0c1031..7706b741e2 100644 --- a/platform/darwin/src/MGLOverlay.h +++ b/platform/darwin/src/MGLOverlay.h @@ -30,6 +30,11 @@ NS_ASSUME_NONNULL_BEGIN This property contains the smallest rectangle that completely encompasses the overlay. Implementers of this protocol must set this area when implementing their overlay class, and after setting it, you must not change it. + + If this overlay spans the antimeridian, its bounds may extend west of −180 degrees + longitude or east of 180 degrees longitude. For example, an overlay covering the + Pacific Ocean from Tokyo to San Francisco might have a bounds extending + from (35.68476, −220.24257) to (37.78428, −122.41310). */ @property (nonatomic, readonly) MGLCoordinateBounds overlayBounds; diff --git a/platform/darwin/src/MGLPointCollection.mm b/platform/darwin/src/MGLPointCollection.mm index 8f20d91a42..efb9497a1f 100644 --- a/platform/darwin/src/MGLPointCollection.mm +++ b/platform/darwin/src/MGLPointCollection.mm @@ -54,7 +54,7 @@ NS_ASSUME_NONNULL_BEGIN if (!_bounds) { mbgl::LatLngBounds bounds = mbgl::LatLngBounds::empty(); for (auto coordinate : _coordinates) { - if (!CLLocationCoordinate2DIsValid(coordinate)) { + if (!MGLLocationCoordinate2DIsValid(coordinate)) { bounds = mbgl::LatLngBounds::empty(); break; } diff --git a/platform/darwin/test/MGLGeometryTests.mm b/platform/darwin/test/MGLGeometryTests.mm index a0ddecf77e..1489fefea9 100644 --- a/platform/darwin/test/MGLGeometryTests.mm +++ b/platform/darwin/test/MGLGeometryTests.mm @@ -172,4 +172,40 @@ XCTAssertEqual(point.y, roundTrippedPoint.y); XCTAssertEqual(point.zoomLevel, roundTrippedPoint.zoomLevel); } + +- (void)testMGLLocationCoordinate2DIsValid { + { + CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(37.936, -71.516); + XCTAssertTrue(MGLLocationCoordinate2DIsValid(coordinate)); + } + { + CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(46.816368, 5.844469); + XCTAssertTrue(MGLLocationCoordinate2DIsValid(coordinate)); + } + { + CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(-21.512680, 23.334703); + XCTAssertTrue(MGLLocationCoordinate2DIsValid(coordinate)); + } + { + CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(-44.947936, -73.081313); + XCTAssertTrue(MGLLocationCoordinate2DIsValid(coordinate)); + } + { + CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(19.333630, 203.555405); + XCTAssertTrue(MGLLocationCoordinate2DIsValid(coordinate)); + } + { + CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(23.254696, -240.795323); + XCTAssertTrue(MGLLocationCoordinate2DIsValid(coordinate)); + } + { + CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(91, 361); + XCTAssertFalse(MGLLocationCoordinate2DIsValid(coordinate)); + } + { + CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(-91, -361); + XCTAssertFalse(MGLLocationCoordinate2DIsValid(coordinate)); + } +} + @end -- cgit v1.2.1 From 1c847b321b401a473a45f839d7e53c27836c1393 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Soto Date: Fri, 4 May 2018 13:30:06 -0400 Subject: [ios, macos] Add support for subscripting in expressions. (#11770) * [ios, macos] Add support for subscripting in expressions. * [ios, macos] Update changelogs. * [ios, macos] Refactor LAST subscripting expression. --- platform/darwin/src/NSExpression+MGLAdditions.mm | 17 ++++++++++++++- platform/darwin/test/MGLExpressionTests.mm | 27 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) (limited to 'platform/darwin') diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index 633f433a8f..7881b79370 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -1097,7 +1097,22 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { NSArray *arguments = self.arguments.mgl_jsonExpressionObject; return [@[@"concat", self.operand.mgl_jsonExpressionObject] arrayByAddingObjectsFromArray:arguments]; } else if ([function isEqualToString:@"objectFrom:withIndex:"]) { - return @[@"at", self.arguments[1].mgl_jsonExpressionObject, self.arguments[0].mgl_jsonExpressionObject]; + id index = self.arguments[1].mgl_jsonExpressionObject; + + if ([self.arguments[1] expressionType] == NSConstantValueExpressionType + && [[self.arguments[1] constantValue] isKindOfClass:[NSString class]]) { + id value = self.arguments[1].constantValue; + + if ([value isEqualToString:@"FIRST"]) { + index = [NSExpression expressionForConstantValue:@0].mgl_jsonExpressionObject; + } else if ([value isEqualToString:@"LAST"]) { + index = [NSExpression expressionWithFormat:@"count(%@) - 1", self.arguments[0]].mgl_jsonExpressionObject; + } else if ([value isEqualToString:@"SIZE"]) { + return [NSExpression expressionWithFormat:@"count(%@)", self.arguments[0]].mgl_jsonExpressionObject; + } + } + + return @[@"at", index, self.arguments[0].mgl_jsonExpressionObject]; } else if ([function isEqualToString:@"boolValue"]) { return @[@"to-boolean", self.operand.mgl_jsonExpressionObject]; } else if ([function isEqualToString:@"mgl_number"] || diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm index 9c75dedaa3..186cae609d 100644 --- a/platform/darwin/test/MGLExpressionTests.mm +++ b/platform/darwin/test/MGLExpressionTests.mm @@ -837,6 +837,33 @@ using namespace std::string_literals; } - (void)testLookupExpressionObject { + { + NSExpression *array = [NSExpression expressionForAggregate:@[MGLConstantExpression(@9), + MGLConstantExpression(@8), + MGLConstantExpression(@7)]]; + NSExpression *expression = [NSExpression expressionForFunction:@"objectFrom:withIndex:" + arguments:@[array, MGLConstantExpression(@"FIRST")]]; + NSArray *jsonExpression = @[@"at", @0, @[ @"literal", @[@9, @8, @7]]]; + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + } + { + NSExpression *array = [NSExpression expressionForAggregate:@[MGLConstantExpression(@9), + MGLConstantExpression(@8), + MGLConstantExpression(@7)]]; + NSExpression *expression = [NSExpression expressionForFunction:@"objectFrom:withIndex:" + arguments:@[array, MGLConstantExpression(@"LAST")]]; + NSArray *jsonExpression = @[@"at", @[@"-", @[@"length", @[ @"literal", @[@9, @8, @7]]], @1], @[ @"literal", @[@9, @8, @7]]]; + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + } + { + NSExpression *array = [NSExpression expressionForAggregate:@[MGLConstantExpression(@9), + MGLConstantExpression(@8), + MGLConstantExpression(@7)]]; + NSExpression *expression = [NSExpression expressionForFunction:@"objectFrom:withIndex:" + arguments:@[array, MGLConstantExpression(@"SIZE")]]; + NSArray *jsonExpression = @[@"length", @[ @"literal", @[@9, @8, @7]]]; + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + } { NSExpression *array = [NSExpression expressionForAggregate:@[MGLConstantExpression(@9), MGLConstantExpression(@8), -- cgit v1.2.1 From a365dd11da0f4c41ad793ea1e3db3cef8e3cbce8 Mon Sep 17 00:00:00 2001 From: Fabian Guerra Soto Date: Fri, 4 May 2018 15:09:07 -0400 Subject: [ios, macos] Make NSPredicate+MGLAdditions public. (#11810) --- platform/darwin/src/MGLBackgroundStyleLayer.mm | 2 +- platform/darwin/src/MGLCircleStyleLayer.mm | 2 +- platform/darwin/src/MGLFillExtrusionStyleLayer.mm | 2 +- platform/darwin/src/MGLFillStyleLayer.mm | 2 +- platform/darwin/src/MGLHeatmapStyleLayer.mm | 2 +- platform/darwin/src/MGLHillshadeStyleLayer.mm | 2 +- platform/darwin/src/MGLLineStyleLayer.mm | 2 +- platform/darwin/src/MGLRasterStyleLayer.mm | 2 +- platform/darwin/src/MGLShapeSource.mm | 2 +- platform/darwin/src/MGLStyleLayer.mm.ejs | 2 +- platform/darwin/src/MGLSymbolStyleLayer.mm | 2 +- platform/darwin/src/MGLVectorTileSource.mm | 2 +- .../darwin/src/NSCompoundPredicate+MGLAdditions.mm | 2 +- platform/darwin/src/NSExpression+MGLAdditions.mm | 2 +- platform/darwin/src/NSPredicate+MGLAdditions.h | 51 ++++++++---- platform/darwin/src/NSPredicate+MGLAdditions.mm | 16 ++-- .../darwin/src/NSPredicate+MGLPrivateAdditions.h | 25 ++++++ platform/darwin/test/MGLPredicateTests.mm | 92 +++++++++++----------- 18 files changed, 131 insertions(+), 81 deletions(-) create mode 100644 platform/darwin/src/NSPredicate+MGLPrivateAdditions.h (limited to 'platform/darwin') diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.mm b/platform/darwin/src/MGLBackgroundStyleLayer.mm index 993645d3a8..acea3441fa 100644 --- a/platform/darwin/src/MGLBackgroundStyleLayer.mm +++ b/platform/darwin/src/MGLBackgroundStyleLayer.mm @@ -2,7 +2,7 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. #import "MGLSource.h" -#import "NSPredicate+MGLAdditions.h" +#import "NSPredicate+MGLPrivateAdditions.h" #import "NSDate+MGLAdditions.h" #import "MGLStyleLayer_Private.h" #import "MGLStyleValue_Private.h" diff --git a/platform/darwin/src/MGLCircleStyleLayer.mm b/platform/darwin/src/MGLCircleStyleLayer.mm index 0be3920987..b85b3d9d4f 100644 --- a/platform/darwin/src/MGLCircleStyleLayer.mm +++ b/platform/darwin/src/MGLCircleStyleLayer.mm @@ -2,7 +2,7 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. #import "MGLSource.h" -#import "NSPredicate+MGLAdditions.h" +#import "NSPredicate+MGLPrivateAdditions.h" #import "NSDate+MGLAdditions.h" #import "MGLStyleLayer_Private.h" #import "MGLStyleValue_Private.h" diff --git a/platform/darwin/src/MGLFillExtrusionStyleLayer.mm b/platform/darwin/src/MGLFillExtrusionStyleLayer.mm index 688ce4c1ac..ea29dff62d 100644 --- a/platform/darwin/src/MGLFillExtrusionStyleLayer.mm +++ b/platform/darwin/src/MGLFillExtrusionStyleLayer.mm @@ -2,7 +2,7 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. #import "MGLSource.h" -#import "NSPredicate+MGLAdditions.h" +#import "NSPredicate+MGLPrivateAdditions.h" #import "NSDate+MGLAdditions.h" #import "MGLStyleLayer_Private.h" #import "MGLStyleValue_Private.h" diff --git a/platform/darwin/src/MGLFillStyleLayer.mm b/platform/darwin/src/MGLFillStyleLayer.mm index c975e28d6b..5be0decd4a 100644 --- a/platform/darwin/src/MGLFillStyleLayer.mm +++ b/platform/darwin/src/MGLFillStyleLayer.mm @@ -2,7 +2,7 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. #import "MGLSource.h" -#import "NSPredicate+MGLAdditions.h" +#import "NSPredicate+MGLPrivateAdditions.h" #import "NSDate+MGLAdditions.h" #import "MGLStyleLayer_Private.h" #import "MGLStyleValue_Private.h" diff --git a/platform/darwin/src/MGLHeatmapStyleLayer.mm b/platform/darwin/src/MGLHeatmapStyleLayer.mm index a394dbda3b..b4bf4c9566 100644 --- a/platform/darwin/src/MGLHeatmapStyleLayer.mm +++ b/platform/darwin/src/MGLHeatmapStyleLayer.mm @@ -2,7 +2,7 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. #import "MGLSource.h" -#import "NSPredicate+MGLAdditions.h" +#import "NSPredicate+MGLPrivateAdditions.h" #import "NSDate+MGLAdditions.h" #import "MGLStyleLayer_Private.h" #import "MGLStyleValue_Private.h" diff --git a/platform/darwin/src/MGLHillshadeStyleLayer.mm b/platform/darwin/src/MGLHillshadeStyleLayer.mm index 2383c1ce26..70fab24e33 100644 --- a/platform/darwin/src/MGLHillshadeStyleLayer.mm +++ b/platform/darwin/src/MGLHillshadeStyleLayer.mm @@ -2,7 +2,7 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. #import "MGLSource.h" -#import "NSPredicate+MGLAdditions.h" +#import "NSPredicate+MGLPrivateAdditions.h" #import "NSDate+MGLAdditions.h" #import "MGLStyleLayer_Private.h" #import "MGLStyleValue_Private.h" diff --git a/platform/darwin/src/MGLLineStyleLayer.mm b/platform/darwin/src/MGLLineStyleLayer.mm index 619cc70afe..b359c424a2 100644 --- a/platform/darwin/src/MGLLineStyleLayer.mm +++ b/platform/darwin/src/MGLLineStyleLayer.mm @@ -2,7 +2,7 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. #import "MGLSource.h" -#import "NSPredicate+MGLAdditions.h" +#import "NSPredicate+MGLPrivateAdditions.h" #import "NSDate+MGLAdditions.h" #import "MGLStyleLayer_Private.h" #import "MGLStyleValue_Private.h" diff --git a/platform/darwin/src/MGLRasterStyleLayer.mm b/platform/darwin/src/MGLRasterStyleLayer.mm index 94a58409de..0e31512491 100644 --- a/platform/darwin/src/MGLRasterStyleLayer.mm +++ b/platform/darwin/src/MGLRasterStyleLayer.mm @@ -2,7 +2,7 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. #import "MGLSource.h" -#import "NSPredicate+MGLAdditions.h" +#import "NSPredicate+MGLPrivateAdditions.h" #import "NSDate+MGLAdditions.h" #import "MGLStyleLayer_Private.h" #import "MGLStyleValue_Private.h" diff --git a/platform/darwin/src/MGLShapeSource.mm b/platform/darwin/src/MGLShapeSource.mm index dcc3fd97f5..af26b7ea13 100644 --- a/platform/darwin/src/MGLShapeSource.mm +++ b/platform/darwin/src/MGLShapeSource.mm @@ -6,7 +6,7 @@ #import "MGLFeature_Private.h" #import "MGLShape_Private.h" -#import "NSPredicate+MGLAdditions.h" +#import "NSPredicate+MGLPrivateAdditions.h" #import "NSURL+MGLAdditions.h" #include diff --git a/platform/darwin/src/MGLStyleLayer.mm.ejs b/platform/darwin/src/MGLStyleLayer.mm.ejs index 42940083b5..ead246fb03 100644 --- a/platform/darwin/src/MGLStyleLayer.mm.ejs +++ b/platform/darwin/src/MGLStyleLayer.mm.ejs @@ -8,7 +8,7 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. #import "MGLSource.h" -#import "NSPredicate+MGLAdditions.h" +#import "NSPredicate+MGLPrivateAdditions.h" #import "NSDate+MGLAdditions.h" #import "MGLStyleLayer_Private.h" #import "MGLStyleValue_Private.h" diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index 0d9fac4808..4236e04238 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.mm @@ -2,7 +2,7 @@ // Edit platform/darwin/scripts/generate-style-code.js, then run `make darwin-style-code`. #import "MGLSource.h" -#import "NSPredicate+MGLAdditions.h" +#import "NSPredicate+MGLPrivateAdditions.h" #import "NSDate+MGLAdditions.h" #import "MGLStyleLayer_Private.h" #import "MGLStyleValue_Private.h" diff --git a/platform/darwin/src/MGLVectorTileSource.mm b/platform/darwin/src/MGLVectorTileSource.mm index c1f7267e4a..96629997d6 100644 --- a/platform/darwin/src/MGLVectorTileSource.mm +++ b/platform/darwin/src/MGLVectorTileSource.mm @@ -6,7 +6,7 @@ #import "MGLStyle_Private.h" #import "MGLMapView_Private.h" -#import "NSPredicate+MGLAdditions.h" +#import "NSPredicate+MGLPrivateAdditions.h" #import "NSURL+MGLAdditions.h" #include diff --git a/platform/darwin/src/NSCompoundPredicate+MGLAdditions.mm b/platform/darwin/src/NSCompoundPredicate+MGLAdditions.mm index 5a98b763ea..a8ae19b172 100644 --- a/platform/darwin/src/NSCompoundPredicate+MGLAdditions.mm +++ b/platform/darwin/src/NSCompoundPredicate+MGLAdditions.mm @@ -2,7 +2,7 @@ #import "MGLStyleValue_Private.h" -#import "NSPredicate+MGLAdditions.h" +#import "NSPredicate+MGLPrivateAdditions.h" #import "NSExpression+MGLPrivateAdditions.h" #include diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index 7881b79370..b2bcf72caf 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -913,7 +913,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { for (NSUInteger index = 0; index < argumentObjects.count; index++) { if (index % 2 == 0 && index != argumentObjects.count - 1) { - NSPredicate *predicate = [NSPredicate mgl_predicateWithJSONObject:argumentObjects[index]]; + NSPredicate *predicate = [NSPredicate predicateWithMGLJSONObject:argumentObjects[index]]; NSExpression *argument = [NSExpression expressionForConstantValue:predicate]; [arguments addObject:argument]; } else { diff --git a/platform/darwin/src/NSPredicate+MGLAdditions.h b/platform/darwin/src/NSPredicate+MGLAdditions.h index a73b1a61ba..6c4b878d37 100644 --- a/platform/darwin/src/NSPredicate+MGLAdditions.h +++ b/platform/darwin/src/NSPredicate+MGLAdditions.h @@ -1,23 +1,44 @@ #import -#import "NSExpression+MGLPrivateAdditions.h" +NS_ASSUME_NONNULL_BEGIN @interface NSPredicate (MGLAdditions) -- (mbgl::style::Filter)mgl_filter; - -+ (instancetype)mgl_predicateWithFilter:(mbgl::style::Filter)filter; - -@end - -@interface NSPredicate (MGLExpressionAdditions) - -+ (instancetype)mgl_predicateWithJSONObject:(id)object; - +#pragma mark Converting JSON Expressions + +/** + Returns a predicate equivalent to the given Foundation object deserialized + from JSON data. + + The Foundation object is interpreted according to the + [Mapbox Style Specification](https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions). + See the + “[Predicates and Expressions](../predicates-and-expressions.html)” + guide for a correspondence of operators and types between the style + specification and the `NSPredicate` representation used by this SDK. + + @param object A Foundation object deserialized from JSON data, for example + using `NSJSONSerialization`. + @return An initialized predicate equivalent to `object`, suitable for use + with the `MGLVectorStyleLayer.predicate` property. + */ ++ (instancetype)predicateWithMGLJSONObject:(id)object NS_SWIFT_NAME(init(mglJSONObject:)); + +/** + An equivalent Foundation object that can be serialized as JSON. + + The Foundation object conforms to the + [Mapbox Style Specification](https://www.mapbox.com/mapbox-gl-js/style-spec/#expressions). + See the + “[Predicates and Expressions](../predicates-and-expressions.html)” + guide for a correspondence of operators and types between the style + specification and the `NSPredicate` representation used by this SDK. + + You can use `NSJSONSerialization` to serialize the Foundation object as data to + write to a file. + */ @property (nonatomic, readonly) id mgl_jsonExpressionObject; -- (id)mgl_if:(id)firstValue, ...; - -- (id)mgl_match:(NSExpression *)firstCase, ...; - @end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/NSPredicate+MGLAdditions.mm b/platform/darwin/src/NSPredicate+MGLAdditions.mm index bbd324bb63..07154cb246 100644 --- a/platform/darwin/src/NSPredicate+MGLAdditions.mm +++ b/platform/darwin/src/NSPredicate+MGLAdditions.mm @@ -1,4 +1,4 @@ -#import "NSPredicate+MGLAdditions.h" +#import "NSPredicate+MGLPrivateAdditions.h" #import "MGLValueEvaluator.h" #import "MGLStyleValue_Private.h" @@ -200,11 +200,11 @@ public: NSPredicate *operator()(mbgl::style::ExpressionFilter filter) { id jsonObject = MGLJSONObjectFromMBGLExpression(*filter.expression); - return [NSPredicate mgl_predicateWithJSONObject:jsonObject]; + return [NSPredicate predicateWithMGLJSONObject:jsonObject]; } }; -@implementation NSPredicate (MGLAdditions) +@implementation NSPredicate (MGLPrivateAdditions) - (mbgl::style::Filter)mgl_filter { @@ -230,18 +230,18 @@ public: @end -@implementation NSPredicate (MGLExpressionAdditions) +@implementation NSPredicate (MGLAdditions) NSArray *MGLSubpredicatesWithJSONObjects(NSArray *objects) { NSMutableArray *subpredicates = [NSMutableArray arrayWithCapacity:objects.count]; for (id object in objects) { - NSPredicate *predicate = [NSPredicate mgl_predicateWithJSONObject:object]; + NSPredicate *predicate = [NSPredicate predicateWithMGLJSONObject:object]; [subpredicates addObject:predicate]; } return subpredicates; } -+ (instancetype)mgl_predicateWithJSONObject:(id)object { ++ (instancetype)predicateWithMGLJSONObject:(id)object { if ([object isEqual:@YES]) { return [NSPredicate predicateWithValue:YES]; } @@ -360,6 +360,10 @@ NSArray *MGLSubpredicatesWithJSONObjects(NSArray *objects) { return nil; } +@end + +@implementation NSPredicate (MGLExpressionAdditions) + - (id)mgl_if:(id)firstValue, ... { if ([self evaluateWithObject:nil]) { diff --git a/platform/darwin/src/NSPredicate+MGLPrivateAdditions.h b/platform/darwin/src/NSPredicate+MGLPrivateAdditions.h new file mode 100644 index 0000000000..1828009678 --- /dev/null +++ b/platform/darwin/src/NSPredicate+MGLPrivateAdditions.h @@ -0,0 +1,25 @@ +#import + +#import "NSPredicate+MGLAdditions.h" + +#include + +NS_ASSUME_NONNULL_BEGIN + +@interface NSPredicate (MGLPrivateAdditions) + +- (mbgl::style::Filter)mgl_filter; + ++ (instancetype)mgl_predicateWithFilter:(mbgl::style::Filter)filter; + +@end + +@interface NSPredicate (MGLExpressionAdditions) + +- (id)mgl_if:(id)firstValue, ...; + +- (id)mgl_match:(NSExpression *)firstCase, ...; + +@end + +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/test/MGLPredicateTests.mm b/platform/darwin/test/MGLPredicateTests.mm index ab4a7e2d88..b725c63140 100644 --- a/platform/darwin/test/MGLPredicateTests.mm +++ b/platform/darwin/test/MGLPredicateTests.mm @@ -1,7 +1,7 @@ #import #import -#import "NSPredicate+MGLAdditions.h" +#import "NSPredicate+MGLPrivateAdditions.h" #import "MGLValueEvaluator.h" namespace mbgl { @@ -242,48 +242,48 @@ namespace mbgl { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"x == YES"]; NSArray *jsonExpression = @[@"==", @[@"get", @"x"], @YES]; XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, jsonExpression); - XCTAssertEqualObjects([NSPredicate mgl_predicateWithJSONObject:jsonExpression], predicate); - [self testSymmetryWithPredicate:[NSPredicate mgl_predicateWithJSONObject:jsonExpression] + XCTAssertEqualObjects([NSPredicate predicateWithMGLJSONObject:jsonExpression], predicate); + [self testSymmetryWithPredicate:[NSPredicate predicateWithMGLJSONObject:jsonExpression] mustRoundTrip:NO]; } { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"CAST(x, 'NSNumber') < 5"]; NSArray *jsonExpression = @[@"<", @[@"to-number", @[@"get", @"x"]], @5]; XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, jsonExpression); - XCTAssertEqualObjects([NSPredicate mgl_predicateWithJSONObject:jsonExpression], predicate); - [self testSymmetryWithPredicate:[NSPredicate mgl_predicateWithJSONObject:jsonExpression] + XCTAssertEqualObjects([NSPredicate predicateWithMGLJSONObject:jsonExpression], predicate); + [self testSymmetryWithPredicate:[NSPredicate predicateWithMGLJSONObject:jsonExpression] mustRoundTrip:NO]; } { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"CAST(x, 'NSNumber') > 5"]; NSArray *jsonExpression = @[@">", @[@"to-number", @[@"get", @"x"]], @5]; XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, jsonExpression); - XCTAssertEqualObjects([NSPredicate mgl_predicateWithJSONObject:jsonExpression], predicate); - [self testSymmetryWithPredicate:[NSPredicate mgl_predicateWithJSONObject:jsonExpression] + XCTAssertEqualObjects([NSPredicate predicateWithMGLJSONObject:jsonExpression], predicate); + [self testSymmetryWithPredicate:[NSPredicate predicateWithMGLJSONObject:jsonExpression] mustRoundTrip:NO]; } { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"CAST(x, 'NSNumber') <= 5"]; NSArray *jsonExpression = @[@"<=", @[@"to-number", @[@"get", @"x"]], @5]; XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, jsonExpression); - XCTAssertEqualObjects([NSPredicate mgl_predicateWithJSONObject:jsonExpression], predicate); - [self testSymmetryWithPredicate:[NSPredicate mgl_predicateWithJSONObject:jsonExpression] + XCTAssertEqualObjects([NSPredicate predicateWithMGLJSONObject:jsonExpression], predicate); + [self testSymmetryWithPredicate:[NSPredicate predicateWithMGLJSONObject:jsonExpression] mustRoundTrip:NO]; } { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"CAST(x, 'NSNumber') >= 5"]; NSArray *jsonExpression = @[@">=", @[@"to-number", @[@"get", @"x"]], @5]; XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, jsonExpression); - XCTAssertEqualObjects([NSPredicate mgl_predicateWithJSONObject:jsonExpression], predicate); - [self testSymmetryWithPredicate:[NSPredicate mgl_predicateWithJSONObject:jsonExpression] + XCTAssertEqualObjects([NSPredicate predicateWithMGLJSONObject:jsonExpression], predicate); + [self testSymmetryWithPredicate:[NSPredicate predicateWithMGLJSONObject:jsonExpression] mustRoundTrip:NO]; } { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"CAST(x, 'NSString') > 'value'"]; NSArray *jsonExpression = @[@">", @[@"to-string", @[@"get", @"x"]], @"value"]; XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, jsonExpression); - XCTAssertEqualObjects([NSPredicate mgl_predicateWithJSONObject:jsonExpression], predicate); - [self testSymmetryWithPredicate:[NSPredicate mgl_predicateWithJSONObject:jsonExpression] + XCTAssertEqualObjects([NSPredicate predicateWithMGLJSONObject:jsonExpression], predicate); + [self testSymmetryWithPredicate:[NSPredicate predicateWithMGLJSONObject:jsonExpression] mustRoundTrip:NO]; } { @@ -360,48 +360,48 @@ namespace mbgl { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"CAST(a, 'NSString') < 'b'"]; NSArray *jsonExpression = @[@"<", @[@"to-string", @[@"get", @"a"]], @"b"]; XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, jsonExpression); - XCTAssertEqualObjects([NSPredicate mgl_predicateWithJSONObject:jsonExpression], predicate); - [self testSymmetryWithPredicate:[NSPredicate mgl_predicateWithJSONObject:jsonExpression] + XCTAssertEqualObjects([NSPredicate predicateWithMGLJSONObject:jsonExpression], predicate); + [self testSymmetryWithPredicate:[NSPredicate predicateWithMGLJSONObject:jsonExpression] mustRoundTrip:NO]; } { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"CAST(a, 'NSString') <= 'b'"]; NSArray *jsonExpression = @[@"<=", @[@"to-string", @[@"get", @"a"]], @"b"]; XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, jsonExpression); - XCTAssertEqualObjects([NSPredicate mgl_predicateWithJSONObject:jsonExpression], predicate); - [self testSymmetryWithPredicate:[NSPredicate mgl_predicateWithJSONObject:jsonExpression] + XCTAssertEqualObjects([NSPredicate predicateWithMGLJSONObject:jsonExpression], predicate); + [self testSymmetryWithPredicate:[NSPredicate predicateWithMGLJSONObject:jsonExpression] mustRoundTrip:NO]; } { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"CAST(a, 'NSString') > 'b'"]; NSArray *jsonExpression = @[@">", @[@"to-string", @[@"get", @"a"]], @"b"]; XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, jsonExpression); - XCTAssertEqualObjects([NSPredicate mgl_predicateWithJSONObject:jsonExpression], predicate); - [self testSymmetryWithPredicate:[NSPredicate mgl_predicateWithJSONObject:jsonExpression] + XCTAssertEqualObjects([NSPredicate predicateWithMGLJSONObject:jsonExpression], predicate); + [self testSymmetryWithPredicate:[NSPredicate predicateWithMGLJSONObject:jsonExpression] mustRoundTrip:NO]; } { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"CAST(a, 'NSString') >= 'b'"]; NSArray *jsonExpression = @[@">=", @[@"to-string", @[@"get", @"a"]], @"b"]; XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, jsonExpression); - XCTAssertEqualObjects([NSPredicate mgl_predicateWithJSONObject:jsonExpression], predicate); - [self testSymmetryWithPredicate:[NSPredicate mgl_predicateWithJSONObject:jsonExpression] + XCTAssertEqualObjects([NSPredicate predicateWithMGLJSONObject:jsonExpression], predicate); + [self testSymmetryWithPredicate:[NSPredicate predicateWithMGLJSONObject:jsonExpression] mustRoundTrip:NO]; } { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"CAST(a, 'NSString') BETWEEN {'b', 'z'}"]; NSArray *jsonExpression =@[@"all", @[@"<=", @"b", @[@"to-string", @[@"get", @"a"]]], @[@"<=", @[@"to-string", @[@"get", @"a"]], @"z"]]; XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, jsonExpression); - XCTAssertEqualObjects([NSPredicate mgl_predicateWithJSONObject:jsonExpression], predicate); - [self testSymmetryWithPredicate:[NSPredicate mgl_predicateWithJSONObject:jsonExpression] + XCTAssertEqualObjects([NSPredicate predicateWithMGLJSONObject:jsonExpression], predicate); + [self testSymmetryWithPredicate:[NSPredicate predicateWithMGLJSONObject:jsonExpression] mustRoundTrip:NO]; } { NSExpression *limits = [NSExpression expressionForAggregate:@[[NSExpression expressionForConstantValue:@10], [NSExpression expressionForConstantValue:@100]]]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"CAST(x, 'NSNumber') BETWEEN %@", limits]; NSArray *jsonExpression = @[@"all", @[@">=", @[@"to-number", @[@"get", @"x"]], @10], @[@"<=", @[@"to-number", @[@"get", @"x"]], @100]]; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithJSONObject:jsonExpression], predicate); - [self testSymmetryWithPredicate:[NSPredicate mgl_predicateWithJSONObject:jsonExpression] + XCTAssertEqualObjects([NSPredicate predicateWithMGLJSONObject:jsonExpression], predicate); + [self testSymmetryWithPredicate:[NSPredicate predicateWithMGLJSONObject:jsonExpression] mustRoundTrip:NO]; } { @@ -409,24 +409,24 @@ namespace mbgl { NSExpression *limits = [NSExpression expressionForAggregate:@[[NSExpression expressionForConstantValue:@10], [NSExpression expressionForConstantValue:@100]]]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"CAST(x, 'NSNumber') BETWEEN %@", limits]; XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, expected); - XCTAssertEqualObjects([NSPredicate mgl_predicateWithJSONObject:expected], predicate); - [self testSymmetryWithPredicate:[NSPredicate mgl_predicateWithJSONObject:expected] + XCTAssertEqualObjects([NSPredicate predicateWithMGLJSONObject:expected], predicate); + [self testSymmetryWithPredicate:[NSPredicate predicateWithMGLJSONObject:expected] mustRoundTrip:NO]; } { NSArray *expected = @[@"all", @[@"<=", @10, @[@"to-number", @[@"get", @"x"]]], @[@">=", @100, @[@"to-number", @[@"get", @"x"]]]]; NSExpression *limits = [NSExpression expressionForAggregate:@[[NSExpression expressionForConstantValue:@10], [NSExpression expressionForConstantValue:@100]]]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"CAST(x, 'NSNumber') BETWEEN %@", limits]; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithJSONObject:expected], predicate); - [self testSymmetryWithPredicate:[NSPredicate mgl_predicateWithJSONObject:expected] + XCTAssertEqualObjects([NSPredicate predicateWithMGLJSONObject:expected], predicate); + [self testSymmetryWithPredicate:[NSPredicate predicateWithMGLJSONObject:expected] mustRoundTrip:NO]; } { NSArray *expected = @[@"all", @[@">=", @[@"to-number", @[@"get", @"x"]], @10], @[@">=", @100, @[@"to-number", @[@"get", @"x"]]]]; NSExpression *limits = [NSExpression expressionForAggregate:@[[NSExpression expressionForConstantValue:@10], [NSExpression expressionForConstantValue:@100]]]; NSPredicate *predicate = [NSPredicate predicateWithFormat:@"CAST(x, 'NSNumber') BETWEEN %@", limits]; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithJSONObject:expected], predicate); - [self testSymmetryWithPredicate:[NSPredicate mgl_predicateWithJSONObject:expected] + XCTAssertEqualObjects([NSPredicate predicateWithMGLJSONObject:expected], predicate); + [self testSymmetryWithPredicate:[NSPredicate predicateWithMGLJSONObject:expected] mustRoundTrip:NO]; } { @@ -434,7 +434,7 @@ namespace mbgl { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"$featureIdentifier IN { 6, 5, 4, 3}"]; XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, expected); NSPredicate *predicateAfter = [NSPredicate predicateWithFormat:@"MGL_MATCH(CAST($featureIdentifier, 'NSNumber'), 3, YES, 4, YES, 5, YES, 6, YES, NO) == YES"]; - auto forwardFilter = [NSPredicate mgl_predicateWithJSONObject:expected].mgl_filter; + auto forwardFilter = [NSPredicate predicateWithMGLJSONObject:expected].mgl_filter; NSPredicate *forwardPredicateAfter = [NSPredicate mgl_predicateWithFilter:forwardFilter]; XCTAssertEqualObjects(predicateAfter, forwardPredicateAfter); } @@ -443,7 +443,7 @@ namespace mbgl { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT x IN { 6, 5, 4, 3}"]; XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, expected); NSPredicate *predicateAfter = [NSPredicate predicateWithFormat:@"NOT MGL_MATCH(CAST(x, 'NSNumber'), 3, YES, 4, YES, 5, YES, 6, YES, NO) == YES"]; - auto forwardFilter = [NSPredicate mgl_predicateWithJSONObject:expected].mgl_filter; + auto forwardFilter = [NSPredicate predicateWithMGLJSONObject:expected].mgl_filter; NSPredicate *forwardPredicateAfter = [NSPredicate mgl_predicateWithFilter:forwardFilter]; XCTAssertEqualObjects(predicateAfter, forwardPredicateAfter); } @@ -452,7 +452,7 @@ namespace mbgl { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"a IN { 'b', 'c' }"]; XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, expected); NSPredicate *predicateAfter = [NSPredicate predicateWithFormat:@"MGL_MATCH(CAST(a, 'NSString'), 'b', YES, 'c', YES, NO) == YES"]; - auto forwardFilter = [NSPredicate mgl_predicateWithJSONObject:expected].mgl_filter; + auto forwardFilter = [NSPredicate predicateWithMGLJSONObject:expected].mgl_filter; NSPredicate *forwardPredicateAfter = [NSPredicate mgl_predicateWithFilter:forwardFilter]; XCTAssertEqualObjects(predicateAfter, forwardPredicateAfter); } @@ -461,7 +461,7 @@ namespace mbgl { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%@ IN %@", [NSExpression expressionForVariable:@"geometryType"], @[@"LineString", @"Polygon"]]; XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, expected); NSPredicate *predicateAfter = [NSPredicate predicateWithFormat:@"MGL_MATCH($geometryType, 'LineString', YES, 'Polygon', YES, NO) == YES"]; - auto forwardFilter = [NSPredicate mgl_predicateWithJSONObject:expected].mgl_filter; + auto forwardFilter = [NSPredicate predicateWithMGLJSONObject:expected].mgl_filter; NSPredicate *forwardPredicateAfter = [NSPredicate mgl_predicateWithFilter:forwardFilter]; XCTAssertEqualObjects(predicateAfter, forwardPredicateAfter); } @@ -470,7 +470,7 @@ namespace mbgl { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"{ 6, 5, 4, 3} CONTAINS x"]; XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, expected); NSPredicate *predicateAfter = [NSPredicate predicateWithFormat:@"MGL_MATCH(CAST(x, 'NSNumber'), 3, YES, 4, YES, 5, YES, 6, YES, NO) == YES"]; - auto forwardFilter = [NSPredicate mgl_predicateWithJSONObject:expected].mgl_filter; + auto forwardFilter = [NSPredicate predicateWithMGLJSONObject:expected].mgl_filter; NSPredicate *forwardPredicateAfter = [NSPredicate mgl_predicateWithFilter:forwardFilter]; XCTAssertEqualObjects(predicateAfter, forwardPredicateAfter); } @@ -479,7 +479,7 @@ namespace mbgl { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%@ CONTAINS %@", @[@"LineString", @"Polygon"], [NSExpression expressionForVariable:@"geometryType"]]; XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, expected); NSPredicate *predicateAfter = [NSPredicate predicateWithFormat:@"MGL_MATCH($geometryType, 'LineString', YES, 'Polygon', YES, NO) == YES"]; - auto forwardFilter = [NSPredicate mgl_predicateWithJSONObject:expected].mgl_filter; + auto forwardFilter = [NSPredicate predicateWithMGLJSONObject:expected].mgl_filter; NSPredicate *forwardPredicateAfter = [NSPredicate mgl_predicateWithFilter:forwardFilter]; XCTAssertEqualObjects(predicateAfter, forwardPredicateAfter); } @@ -488,7 +488,7 @@ namespace mbgl { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"{ 6, 5, 4, 3} CONTAINS $featureIdentifier"]; XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, expected); NSPredicate *predicateAfter = [NSPredicate predicateWithFormat:@"MGL_MATCH(CAST($featureIdentifier, 'NSNumber'), 3, YES, 4, YES, 5, YES, 6, YES, NO) == YES"]; - auto forwardFilter = [NSPredicate mgl_predicateWithJSONObject:expected].mgl_filter; + auto forwardFilter = [NSPredicate predicateWithMGLJSONObject:expected].mgl_filter; NSPredicate *forwardPredicateAfter = [NSPredicate mgl_predicateWithFilter:forwardFilter]; XCTAssertEqualObjects(predicateAfter, forwardPredicateAfter); } @@ -499,32 +499,32 @@ namespace mbgl { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"a == 'b' AND c == 'd'"]; NSArray *jsonExpression = @[@"all", @[@"==", @[@"get", @"a"], @"b"], @[@"==", @[@"get", @"c"], @"d"]]; XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, jsonExpression); - XCTAssertEqualObjects([NSPredicate mgl_predicateWithJSONObject:jsonExpression], predicate); - [self testSymmetryWithPredicate:[NSPredicate mgl_predicateWithJSONObject:jsonExpression] + XCTAssertEqualObjects([NSPredicate predicateWithMGLJSONObject:jsonExpression], predicate); + [self testSymmetryWithPredicate:[NSPredicate predicateWithMGLJSONObject:jsonExpression] mustRoundTrip:NO]; } { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"a == 'b' OR c == 'd'"]; NSArray *jsonExpression = @[@"any", @[@"==", @[@"get", @"a"], @"b"], @[@"==", @[@"get", @"c"], @"d"]]; XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, jsonExpression); - XCTAssertEqualObjects([NSPredicate mgl_predicateWithJSONObject:jsonExpression], predicate); - [self testSymmetryWithPredicate:[NSPredicate mgl_predicateWithJSONObject:jsonExpression] + XCTAssertEqualObjects([NSPredicate predicateWithMGLJSONObject:jsonExpression], predicate); + [self testSymmetryWithPredicate:[NSPredicate predicateWithMGLJSONObject:jsonExpression] mustRoundTrip:NO]; } { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT(a == 'b' AND c == 'd')"]; NSArray *jsonExpression = @[@"!", @[@"all", @[@"==", @[@"get", @"a"], @"b"], @[@"==", @[@"get", @"c"], @"d"]]]; XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, jsonExpression); - XCTAssertEqualObjects([NSPredicate mgl_predicateWithJSONObject:jsonExpression], predicate); - [self testSymmetryWithPredicate:[NSPredicate mgl_predicateWithJSONObject:jsonExpression] + XCTAssertEqualObjects([NSPredicate predicateWithMGLJSONObject:jsonExpression], predicate); + [self testSymmetryWithPredicate:[NSPredicate predicateWithMGLJSONObject:jsonExpression] mustRoundTrip:NO]; } { NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT(a == 'b' OR c == 'd')"]; NSArray *jsonExpression = @[@"!", @[@"any", @[@"==", @[@"get", @"a"], @"b"], @[@"==", @[@"get", @"c"], @"d"]]]; XCTAssertEqualObjects(predicate.mgl_jsonExpressionObject, jsonExpression); - XCTAssertEqualObjects([NSPredicate mgl_predicateWithJSONObject:jsonExpression], predicate); - [self testSymmetryWithPredicate:[NSPredicate mgl_predicateWithJSONObject:jsonExpression] + XCTAssertEqualObjects([NSPredicate predicateWithMGLJSONObject:jsonExpression], predicate); + [self testSymmetryWithPredicate:[NSPredicate predicateWithMGLJSONObject:jsonExpression] mustRoundTrip:NO]; } { -- cgit v1.2.1 From a425995189c3f4c9d9040b4acff477bfc96b6afd Mon Sep 17 00:00:00 2001 From: Fabian Guerra Soto Date: Mon, 7 May 2018 12:01:29 -0400 Subject: [ios, macos] Add to-rgba expression operator. (#11725) * [ios, macos] Add expression support to to-rgba operator. * [ios, macos] Update style docs. * [ios, macos] Refactored to-rgba to to-color. * [ios, macos] Add support for to-rgba expression operator. * [ios, macos] Add multiple parameters support to to-color operand. * [ios, macos] Enable to-rgba operator for MGLColor or key path expressions. * [ios, macos] Update predicates and expressions guide to reflect cast changes. * [ios, macos] Update changelogs. * [ios, macos] Clarify color casting usage. --- .../darwin/docs/guides/For Style Authors.md.ejs | 4 +-- .../docs/guides/Predicates and Expressions.md | 2 ++ platform/darwin/src/NSExpression+MGLAdditions.mm | 36 ++++++++++++++++++++++ platform/darwin/test/MGLExpressionTests.mm | 32 +++++++++++++++++++ 4 files changed, 72 insertions(+), 2 deletions(-) (limited to 'platform/darwin') diff --git a/platform/darwin/docs/guides/For Style Authors.md.ejs b/platform/darwin/docs/guides/For Style Authors.md.ejs index b0ded7bc03..60177e57c2 100644 --- a/platform/darwin/docs/guides/For Style Authors.md.ejs +++ b/platform/darwin/docs/guides/For Style Authors.md.ejs @@ -335,7 +335,7 @@ In style specification | Method, function, or predicate type | Format string syn `number` | | `string` | | `to-boolean` | `boolValue` | -`to-color` | | +`to-color` | | `CAST(var, '<%- cocoaPrefix %>Color')` `to-number` | `mgl_numberWithFallbackValues:` | `CAST(zipCode, 'NSNumber')` `to-string` | `stringValue` | `CAST(ele, 'NSString')` `typeof` | | @@ -372,7 +372,7 @@ In style specification | Method, function, or predicate type | Format string syn `rgb` | `+[UIColor colorWithRed:green:blue:alpha:]` | `rgba` | `+[UIColor colorWithRed:green:blue:alpha:]` | <% } -%> -`to-rgba` | | +`to-rgba` | | `CAST(noindex(var), 'NSArray')` `-` | `from:subtract:` | `2 - 1` `*` | `multiply:by:` | `1 * 2` `/` | `divide:by:` | `1 / 2` diff --git a/platform/darwin/docs/guides/Predicates and Expressions.md b/platform/darwin/docs/guides/Predicates and Expressions.md index c3b3d39a52..18eccda569 100644 --- a/platform/darwin/docs/guides/Predicates and Expressions.md +++ b/platform/darwin/docs/guides/Predicates and Expressions.md @@ -70,6 +70,8 @@ path or variable into a matching type: * To cast a value to a number, use `CAST(key, 'NSNumber')`. * To cast a value to a string, use `CAST(key, 'NSString')`. +* To cast a value to a color, use `CAST(key, 'UIColor')` on iOS and `CAST(key, 'NSColor')` on macOS. +* To cast an `NSColor` or `UIColor` object to an array, use `CAST(noindex(color), 'NSArray')`. For details about the predicate format string syntax, consult the “Predicate Format String Syntax” chapter of the diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index b2bcf72caf..6dde705d3c 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -802,6 +802,22 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { } else if ([op isEqualToString:@"to-string"] || [op isEqualToString:@"string"]) { NSExpression *operand = [NSExpression expressionWithMGLJSONObject:argumentObjects.firstObject]; return [NSExpression expressionWithFormat:@"CAST(%@, 'NSString')", operand]; + } else if ([op isEqualToString:@"to-color"]) { + NSExpression *operand = [NSExpression expressionWithMGLJSONObject:argumentObjects.firstObject]; + + if (argumentObjects.count == 1) { +#if TARGET_OS_IPHONE + return [NSExpression expressionWithFormat:@"CAST(%@, 'UIColor')", operand]; +#else + return [NSExpression expressionWithFormat:@"CAST(%@, 'NSColor')", operand]; +#endif + } + NSArray *subexpressions = MGLSubexpressionsWithJSONObjects(array); + return [NSExpression expressionForFunction:@"MGL_FUNCTION" arguments:subexpressions]; + + } else if ([op isEqualToString:@"to-rgba"]) { + NSExpression *operand = [NSExpression expressionWithMGLJSONObject:argumentObjects.firstObject]; + return [NSExpression expressionWithFormat:@"CAST(noindex(%@), 'NSArray')", operand]; } else if ([op isEqualToString:@"get"]) { if (argumentObjects.count == 2) { NSExpression *operand = [NSExpression expressionWithMGLJSONObject:argumentObjects.lastObject]; @@ -1165,6 +1181,26 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { } else if ([type isEqualToString:@"NSNumber"]) { return @[@"to-number", object]; } +#if TARGET_OS_IPHONE + else if ([type isEqualToString:@"UIColor"] || [type isEqualToString:@"MGLColor"]) { + return @[@"to-color", object]; + } +#else + else if ([type isEqualToString:@"NSColor"] || [type isEqualToString:@"MGLColor"]) { + return @[@"to-color", object]; + } +#endif + else if ([type isEqualToString:@"NSArray"]) { + NSExpression *operand = self.arguments.firstObject; + if ([operand expressionType] == NSFunctionExpressionType ) { + operand = self.arguments.firstObject.arguments.firstObject; + } + if (([operand expressionType] != NSConstantValueExpressionType) || + ([operand expressionType] == NSConstantValueExpressionType && + [[operand constantValue] isKindOfClass:[MGLColor class]])) { + return @[@"to-rgba", object]; + } + } [NSException raise:NSInvalidArgumentException format:@"Casting expression to %@ not yet implemented.", type]; } else if ([function isEqualToString:@"MGL_FUNCTION"]) { diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm index 186cae609d..4ed1f61eb1 100644 --- a/platform/darwin/test/MGLExpressionTests.mm +++ b/platform/darwin/test/MGLExpressionTests.mm @@ -668,6 +668,38 @@ using namespace std::string_literals; XCTAssertEqualObjects([compatibilityExpression expressionValueWithObject:@{@"number": @1.5} context:nil], @"1.5"); XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); } + { +#if TARGET_OS_IPHONE + NSExpression *expression = [NSExpression expressionWithFormat:@"CAST(x, 'UIColor')"]; +#else + NSExpression *expression = [NSExpression expressionWithFormat:@"CAST(x, 'NSColor')"]; +#endif + + NSArray *jsonExpression = @[@"to-color", @[@"get", @"x"]]; + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); + } + { + NSExpression *expression = [NSExpression expressionWithFormat:@"MGL_FUNCTION('to-color', x, y, z)"]; + NSArray *jsonExpression = @[@"to-color", @[@"get", @"x"], @[@"get", @"y"], @[@"get", @"z"]]; + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + } + { + NSExpression *expression = [NSExpression expressionWithFormat:@"CAST(noindex(x), 'NSArray')"]; + NSArray *jsonExpression = @[@"to-rgba", @[@"get", @"x"]]; + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); + } + { + NSExpression *expression = [NSExpression expressionWithFormat:@"CAST(noindex(%@), 'NSArray')", MGLConstantExpression(MGLColor.blueColor)]; + NSArray *jsonExpression = @[@"to-rgba", @[@"rgb", @0, @0, @255]]; + XCTAssertEqualObjects(expression.mgl_jsonExpressionObject, jsonExpression); + XCTAssertEqualObjects([NSExpression expressionWithMGLJSONObject:jsonExpression], expression); + } + { + NSExpression *expression = [NSExpression expressionWithFormat:@"CAST(noindex('x'), 'NSArray')"]; + XCTAssertThrowsSpecificNamed(expression.mgl_jsonExpressionObject, NSException, NSInvalidArgumentException); + } } - (void)testInterpolationExpressionObject { -- cgit v1.2.1 From a4e2c1af1fd83b22ef4ee57ab19a15616224f8b8 Mon Sep 17 00:00:00 2001 From: Lucas Wojciechowski Date: Thu, 10 May 2018 12:37:14 -0700 Subject: [core] Convert "legacy" filters directly into expressions (#11610) Ports the specialized filter-* expressions from GL JS, adding them to src/mbgl/style/expression/compound_expression.cpp --- platform/darwin/src/MGLCircleStyleLayer.mm | 2 +- platform/darwin/src/MGLFillExtrusionStyleLayer.mm | 2 +- platform/darwin/src/MGLFillStyleLayer.mm | 2 +- platform/darwin/src/MGLHeatmapStyleLayer.mm | 2 +- platform/darwin/src/MGLLineStyleLayer.mm | 2 +- platform/darwin/src/MGLStyleLayer.mm.ejs | 2 +- platform/darwin/src/MGLSymbolStyleLayer.mm | 2 +- platform/darwin/src/NSPredicate+MGLAdditions.mm | 207 +-------------------- platform/darwin/test/MGLPredicateTests.mm | 214 ---------------------- 9 files changed, 13 insertions(+), 422 deletions(-) (limited to 'platform/darwin') diff --git a/platform/darwin/src/MGLCircleStyleLayer.mm b/platform/darwin/src/MGLCircleStyleLayer.mm index b85b3d9d4f..b03ab8a7a6 100644 --- a/platform/darwin/src/MGLCircleStyleLayer.mm +++ b/platform/darwin/src/MGLCircleStyleLayer.mm @@ -75,7 +75,7 @@ namespace mbgl { { MGLAssertStyleLayerIsValid(); - self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::NullFilter()); + self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::Filter()); } - (NSPredicate *)predicate diff --git a/platform/darwin/src/MGLFillExtrusionStyleLayer.mm b/platform/darwin/src/MGLFillExtrusionStyleLayer.mm index ea29dff62d..4f3bfee18e 100644 --- a/platform/darwin/src/MGLFillExtrusionStyleLayer.mm +++ b/platform/darwin/src/MGLFillExtrusionStyleLayer.mm @@ -65,7 +65,7 @@ namespace mbgl { { MGLAssertStyleLayerIsValid(); - self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::NullFilter()); + self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::Filter()); } - (NSPredicate *)predicate diff --git a/platform/darwin/src/MGLFillStyleLayer.mm b/platform/darwin/src/MGLFillStyleLayer.mm index 5be0decd4a..12e3643ce6 100644 --- a/platform/darwin/src/MGLFillStyleLayer.mm +++ b/platform/darwin/src/MGLFillStyleLayer.mm @@ -65,7 +65,7 @@ namespace mbgl { { MGLAssertStyleLayerIsValid(); - self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::NullFilter()); + self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::Filter()); } - (NSPredicate *)predicate diff --git a/platform/darwin/src/MGLHeatmapStyleLayer.mm b/platform/darwin/src/MGLHeatmapStyleLayer.mm index b4bf4c9566..925b3ac750 100644 --- a/platform/darwin/src/MGLHeatmapStyleLayer.mm +++ b/platform/darwin/src/MGLHeatmapStyleLayer.mm @@ -56,7 +56,7 @@ { MGLAssertStyleLayerIsValid(); - self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::NullFilter()); + self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::Filter()); } - (NSPredicate *)predicate diff --git a/platform/darwin/src/MGLLineStyleLayer.mm b/platform/darwin/src/MGLLineStyleLayer.mm index b359c424a2..84412073cd 100644 --- a/platform/darwin/src/MGLLineStyleLayer.mm +++ b/platform/darwin/src/MGLLineStyleLayer.mm @@ -77,7 +77,7 @@ namespace mbgl { { MGLAssertStyleLayerIsValid(); - self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::NullFilter()); + self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::Filter()); } - (NSPredicate *)predicate diff --git a/platform/darwin/src/MGLStyleLayer.mm.ejs b/platform/darwin/src/MGLStyleLayer.mm.ejs index ead246fb03..e7589c1f62 100644 --- a/platform/darwin/src/MGLStyleLayer.mm.ejs +++ b/platform/darwin/src/MGLStyleLayer.mm.ejs @@ -103,7 +103,7 @@ namespace mbgl { { MGLAssertStyleLayerIsValid(); - self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::NullFilter()); + self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::Filter()); } - (NSPredicate *)predicate diff --git a/platform/darwin/src/MGLSymbolStyleLayer.mm b/platform/darwin/src/MGLSymbolStyleLayer.mm index 4236e04238..7ec7816c3b 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.mm +++ b/platform/darwin/src/MGLSymbolStyleLayer.mm @@ -142,7 +142,7 @@ namespace mbgl { { MGLAssertStyleLayerIsValid(); - self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::NullFilter()); + self.rawLayer->setFilter(predicate ? predicate.mgl_filter : mbgl::style::Filter()); } - (NSPredicate *)predicate diff --git a/platform/darwin/src/NSPredicate+MGLAdditions.mm b/platform/darwin/src/NSPredicate+MGLAdditions.mm index 07154cb246..4b9a4177cb 100644 --- a/platform/darwin/src/NSPredicate+MGLAdditions.mm +++ b/platform/darwin/src/NSPredicate+MGLAdditions.mm @@ -5,205 +5,6 @@ #include -class FilterEvaluator { -public: - - NSArray *getPredicates(std::vector filters) { - NSMutableArray *predicates = [NSMutableArray arrayWithCapacity:filters.size()]; - for (auto filter : filters) { - [predicates addObject:mbgl::style::Filter::visit(filter, FilterEvaluator())]; - } - return predicates; - } - - template - NSExpression *getValues(std::vector values) { - NSMutableArray *array = [NSMutableArray arrayWithCapacity:values.size()]; - for (auto value : values) { - id constantValue = MBGLType::visit(value, ValueEvaluator()); - [array addObject:[NSExpression expressionForConstantValue:constantValue]]; - } - return [NSExpression expressionForAggregate:array]; - } - - NSString *getFeatureTypeString(mbgl::FeatureType type) { - switch (type) { - case mbgl::FeatureType::Point: - return @"Point"; - - case mbgl::FeatureType::LineString: - return @"LineString"; - - case mbgl::FeatureType::Polygon: - return @"Polygon"; - - default: - NSCAssert(NO, @"Unrecognized feature type %hhu", type); - return nil; - } - } - - NSExpression *getFeatureTypeStrings(std::vector values) { - NSMutableArray *array = [NSMutableArray arrayWithCapacity:values.size()]; - for (auto value : values) { - id typeString = getFeatureTypeString(value); - [array addObject:[NSExpression expressionForConstantValue:typeString]]; - } - return [NSExpression expressionForAggregate:array]; - } - - NSPredicate *operator()(mbgl::style::NullFilter filter) { - return nil; - } - - NSPredicate *operator()(mbgl::style::EqualsFilter filter) { - return [NSPredicate predicateWithFormat:@"%K == %@", @(filter.key.c_str()), mbgl::Value::visit(filter.value, ValueEvaluator())]; - } - - NSPredicate *operator()(mbgl::style::NotEqualsFilter filter) { - return [NSPredicate predicateWithFormat:@"%K != %@", @(filter.key.c_str()), mbgl::Value::visit(filter.value, ValueEvaluator())]; - } - - NSPredicate *operator()(mbgl::style::GreaterThanFilter filter) { - return [NSPredicate predicateWithFormat:@"%K > %@", @(filter.key.c_str()), mbgl::Value::visit(filter.value, ValueEvaluator())]; - } - - NSPredicate *operator()(mbgl::style::GreaterThanEqualsFilter filter) { - return [NSPredicate predicateWithFormat:@"%K >= %@", @(filter.key.c_str()), mbgl::Value::visit(filter.value, ValueEvaluator())]; - } - - NSPredicate *operator()(mbgl::style::LessThanFilter filter) { - return [NSPredicate predicateWithFormat:@"%K < %@", @(filter.key.c_str()), mbgl::Value::visit(filter.value, ValueEvaluator())]; - } - - NSPredicate *operator()(mbgl::style::LessThanEqualsFilter filter) { - return [NSPredicate predicateWithFormat:@"%K <= %@", @(filter.key.c_str()), mbgl::Value::visit(filter.value, ValueEvaluator())]; - } - - NSPredicate *operator()(mbgl::style::InFilter filter) { - return [NSPredicate predicateWithFormat:@"%K IN %@", @(filter.key.c_str()), getValues(filter.values)]; - } - - NSPredicate *operator()(mbgl::style::NotInFilter filter) { - return [NSPredicate predicateWithFormat:@"NOT %K IN %@", @(filter.key.c_str()), getValues(filter.values)]; - } - - NSPredicate *operator()(mbgl::style::TypeEqualsFilter filter) { - return [NSPredicate predicateWithFormat:@"%K == %@", @"$type", getFeatureTypeString(filter.value)]; - } - - NSPredicate *operator()(mbgl::style::TypeNotEqualsFilter filter) { - return [NSPredicate predicateWithFormat:@"%K != %@", @"$type", getFeatureTypeString(filter.value)]; - } - - NSPredicate *operator()(mbgl::style::TypeInFilter filter) { - return [NSPredicate predicateWithFormat:@"%K IN %@", @"$type", getFeatureTypeStrings(filter.values)]; - } - - NSPredicate *operator()(mbgl::style::TypeNotInFilter filter) { - return [NSPredicate predicateWithFormat:@"NOT %K IN %@", @"$type", getFeatureTypeStrings(filter.values)]; - } - - NSPredicate *operator()(mbgl::style::IdentifierEqualsFilter filter) { - return [NSPredicate predicateWithFormat:@"%K == %@", @"$id", mbgl::FeatureIdentifier::visit(filter.value, ValueEvaluator())]; - } - - NSPredicate *operator()(mbgl::style::IdentifierNotEqualsFilter filter) { - return [NSPredicate predicateWithFormat:@"%K != %@", @"$id", mbgl::FeatureIdentifier::visit(filter.value, ValueEvaluator())]; - } - - NSPredicate *operator()(mbgl::style::IdentifierInFilter filter) { - return [NSPredicate predicateWithFormat:@"%K IN %@", @"$id", getValues(filter.values)]; - } - - NSPredicate *operator()(mbgl::style::IdentifierNotInFilter filter) { - return [NSPredicate predicateWithFormat:@"NOT %K IN %@", @"$id", getValues(filter.values)]; - } - - NSPredicate *operator()(mbgl::style::AnyFilter filter) { - NSArray *subpredicates = getPredicates(filter.filters); - if (subpredicates.count) { - return [NSCompoundPredicate orPredicateWithSubpredicates:subpredicates]; - } - return [NSPredicate predicateWithValue:NO]; - } - - NSPredicate *operator()(mbgl::style::AllFilter filter) { - // Convert [all, [>=, key, lower], [<=, key, upper]] to key BETWEEN {lower, upper} - if (filter.filters.size() == 2) { - auto leftFilter = filter.filters[0]; - auto rightFilter = filter.filters[1]; - - std::string lowerKey; - std::string upperKey; - mbgl::Value lowerBound; - mbgl::Value upperBound; - if (leftFilter.is()) { - lowerKey = leftFilter.get().key; - lowerBound = leftFilter.get().value; - } else if (rightFilter.is()) { - lowerKey = rightFilter.get().key; - lowerBound = rightFilter.get().value; - } - - if (leftFilter.is()) { - upperKey = leftFilter.get().key; - upperBound = leftFilter.get().value; - } else if (rightFilter.is()) { - upperKey = rightFilter.get().key; - upperBound = rightFilter.get().value; - } - - if (!lowerBound.is() && !upperBound.is() - && lowerKey == upperKey) { - return [NSPredicate predicateWithFormat:@"%K BETWEEN {%@, %@}", - @(lowerKey.c_str()), - mbgl::Value::visit(lowerBound, ValueEvaluator()), - mbgl::Value::visit(upperBound, ValueEvaluator())]; - } - } - - NSArray *subpredicates = getPredicates(filter.filters); - if (subpredicates.count) { - return [NSCompoundPredicate andPredicateWithSubpredicates:subpredicates]; - } - return [NSPredicate predicateWithValue:YES]; - } - - NSPredicate *operator()(mbgl::style::NoneFilter filter) { - NSArray *subpredicates = getPredicates(filter.filters); - if (subpredicates.count > 1) { - NSCompoundPredicate *predicate = [NSCompoundPredicate orPredicateWithSubpredicates:subpredicates]; - return [NSCompoundPredicate notPredicateWithSubpredicate:predicate]; - } else if (subpredicates.count) { - return [NSCompoundPredicate notPredicateWithSubpredicate:subpredicates.firstObject]; - } else { - return [NSPredicate predicateWithValue:YES]; - } - } - - NSPredicate *operator()(mbgl::style::HasFilter filter) { - return [NSPredicate predicateWithFormat:@"%K != nil", @(filter.key.c_str())]; - } - - NSPredicate *operator()(mbgl::style::NotHasFilter filter) { - return [NSPredicate predicateWithFormat:@"%K == nil", @(filter.key.c_str())]; - } - - NSPredicate *operator()(mbgl::style::HasIdentifierFilter filter) { - return [NSPredicate predicateWithFormat:@"%K != nil", @"$id"]; - } - - NSPredicate *operator()(mbgl::style::NotHasIdentifierFilter filter) { - return [NSPredicate predicateWithFormat:@"%K == nil", @"$id"]; - } - - NSPredicate *operator()(mbgl::style::ExpressionFilter filter) { - id jsonObject = MGLJSONObjectFromMBGLExpression(*filter.expression); - return [NSPredicate predicateWithMGLJSONObject:jsonObject]; - } -}; - @implementation NSPredicate (MGLPrivateAdditions) - (mbgl::style::Filter)mgl_filter @@ -224,8 +25,12 @@ public: + (instancetype)mgl_predicateWithFilter:(mbgl::style::Filter)filter { - FilterEvaluator evaluator; - return mbgl::style::Filter::visit(filter, evaluator); + if (filter.expression) { + id jsonObject = MGLJSONObjectFromMBGLExpression(**filter.expression); + return [NSPredicate predicateWithMGLJSONObject:jsonObject]; + } else { + return nil; + } } @end diff --git a/platform/darwin/test/MGLPredicateTests.mm b/platform/darwin/test/MGLPredicateTests.mm index b725c63140..4e7b3e7e4b 100644 --- a/platform/darwin/test/MGLPredicateTests.mm +++ b/platform/darwin/test/MGLPredicateTests.mm @@ -4,226 +4,12 @@ #import "NSPredicate+MGLPrivateAdditions.h" #import "MGLValueEvaluator.h" -namespace mbgl { - namespace style { - bool operator!=(const Filter &a, const Filter &b) { - return !(a == b); - } - } -} - -#define MGLAssertEqualFilters(actual, expected, ...) \ - XCTAssertTrue(actual.is<__typeof__(expected)>()); \ - if (actual.is<__typeof__(expected)>()) { \ - XCTAssertEqual(actual.get<__typeof__(expected)>(), expected, __VA_ARGS__); \ - } - @interface MGLPredicateTests : XCTestCase @end @implementation MGLPredicateTests -- (void)testPredication { - XCTAssertNil([NSPredicate mgl_predicateWithFilter:mbgl::style::NullFilter()]); - - { - mbgl::style::EqualsFilter filter = { .key = "a", .value = std::string("b") }; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], [NSPredicate predicateWithFormat:@"a = 'b'"]); - } - - { - mbgl::style::TypeEqualsFilter filter = { .value = mbgl::FeatureType::Point }; - NSPredicate *expected = [NSPredicate predicateWithFormat:@"%K = 'Point'", @"$type"]; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], expected); - } - - { - mbgl::style::TypeEqualsFilter filter = { .value = mbgl::FeatureType::LineString }; - NSPredicate *expected = [NSPredicate predicateWithFormat:@"%K = 'LineString'", @"$type"]; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], expected); - } - - { - mbgl::style::TypeEqualsFilter filter = { .value = mbgl::FeatureType::Polygon }; - NSPredicate *expected = [NSPredicate predicateWithFormat:@"%K = 'Polygon'", @"$type"]; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], expected); - } - - { - mbgl::style::IdentifierEqualsFilter filter = { .value = UINT64_C(67086180) }; - NSPredicate *expected = [NSPredicate predicateWithFormat:@"%K = 67086180", @"$id"]; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], expected); - } - - { - mbgl::style::NotHasIdentifierFilter filter; - NSPredicate *expected = [NSPredicate predicateWithFormat:@"%K = nil", @"$id"]; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], expected); - } - - { - mbgl::style::TypeEqualsFilter filter = { .value = mbgl::FeatureType::Unknown }; - XCTAssertThrowsSpecificNamed([NSPredicate mgl_predicateWithFilter:filter], NSException, NSInternalInconsistencyException); - } - - { - mbgl::style::NotHasFilter filter = { .key = "a" }; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], [NSPredicate predicateWithFormat:@"a = nil"]); - } - - { - mbgl::style::NotEqualsFilter filter = { .key = "a", .value = std::string("b") }; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], [NSPredicate predicateWithFormat:@"a != 'b'"]); - } - - { - mbgl::style::TypeNotEqualsFilter filter = { .value = mbgl::FeatureType::Point }; - NSPredicate *expected = [NSPredicate predicateWithFormat:@"%K != 'Point'", @"$type"]; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], expected); - } - - { - mbgl::style::IdentifierNotEqualsFilter filter = { .value = UINT64_C(67086180) }; - NSPredicate *expected = [NSPredicate predicateWithFormat:@"%K != 67086180", @"$id"]; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], expected); - } - - { - mbgl::style::HasIdentifierFilter filter; - NSPredicate *expected = [NSPredicate predicateWithFormat:@"%K != nil", @"$id"]; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], expected); - } - - { - mbgl::style::HasFilter filter = { .key = "a" }; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], [NSPredicate predicateWithFormat:@"a != nil"]); - } - - { - mbgl::style::LessThanFilter filter = { .key = "a", .value = std::string("b") }; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], [NSPredicate predicateWithFormat:@"a < 'b'"]); - } - - { - mbgl::style::LessThanEqualsFilter filter = { .key = "a", .value = std::string("b") }; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], [NSPredicate predicateWithFormat:@"a <= 'b'"]); - } - - { - mbgl::style::GreaterThanFilter filter = { .key = "a", .value = std::string("b") }; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], [NSPredicate predicateWithFormat:@"a > 'b'"]); - } - - { - mbgl::style::GreaterThanEqualsFilter filter = { .key = "a", .value = std::string("b") }; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], [NSPredicate predicateWithFormat:@"a >= 'b'"]); - } - - { - mbgl::style::AllFilter filter = { - .filters = { - mbgl::style::GreaterThanEqualsFilter { .key = "a", .value = std::string("b") }, - mbgl::style::LessThanEqualsFilter { .key = "a", .value = std::string("z") }, - }, - }; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], [NSPredicate predicateWithFormat:@"a BETWEEN {'b', 'z'}"]); - } - - { - mbgl::style::AllFilter filter = { - .filters = { - mbgl::style::LessThanEqualsFilter { .key = "a", .value = std::string("z") }, - mbgl::style::GreaterThanEqualsFilter { .key = "a", .value = std::string("b") }, - }, - }; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], [NSPredicate predicateWithFormat:@"a BETWEEN {'b', 'z'}"]); - } - - { - mbgl::style::InFilter filter = { .key = "a", .values = { std::string("b"), std::string("c") } }; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter].predicateFormat, [NSPredicate predicateWithFormat:@"a IN {'b', 'c'}"].predicateFormat); - } - - { - mbgl::style::TypeInFilter filter = { .values = { mbgl::FeatureType::LineString, mbgl::FeatureType::Polygon } }; - NSPredicate *expected = [NSPredicate predicateWithFormat:@"%K IN {'LineString', 'Polygon'}", @"$type"]; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter].predicateFormat, expected.predicateFormat); - } - - { - mbgl::style::IdentifierInFilter filter = { .values = { UINT64_C(67086180), UINT64_C(3709678893), UINT64_C(3352016856), UINT64_C(4189833989) } }; - NSPredicate *expected = [NSPredicate predicateWithFormat:@"%K IN {67086180, 3709678893, 3352016856, 4189833989}", @"$id"]; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], expected); - } - - { - mbgl::style::NotInFilter filter = { .key = "a", .values = { std::string("b"), std::string("c") } }; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter].predicateFormat, [NSPredicate predicateWithFormat:@"NOT a IN {'b', 'c'}"].predicateFormat); - } - - { - mbgl::style::TypeNotInFilter filter = { .values = { mbgl::FeatureType::LineString, mbgl::FeatureType::Polygon } }; - NSPredicate *expected = [NSPredicate predicateWithFormat:@"NOT %K IN {'LineString', 'Polygon'}", @"$type"]; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter].predicateFormat, expected.predicateFormat); - } - - { - mbgl::style::IdentifierNotInFilter filter = { .values = { UINT64_C(67086180), UINT64_C(3709678893), UINT64_C(3352016856), UINT64_C(4189833989) } }; - NSPredicate *expected = [NSPredicate predicateWithFormat:@"NOT %K IN {67086180, 3709678893, 3352016856, 4189833989}", @"$id"]; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], expected); - } - - { - mbgl::style::AllFilter filter; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], [NSPredicate predicateWithValue:YES]); - } - - { - mbgl::style::AllFilter filter = { - .filters = { - mbgl::style::EqualsFilter { .key = "a", .value = std::string("b") }, - mbgl::style::EqualsFilter { .key = "c", .value = std::string("d") }, - }, - }; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], [NSPredicate predicateWithFormat:@"a == 'b' AND c == 'd'"]); - } - - { - mbgl::style::AnyFilter filter; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], [NSPredicate predicateWithValue:NO]); - } - - { - mbgl::style::AnyFilter filter = { - .filters = { - mbgl::style::EqualsFilter { .key = "a", .value = std::string("b") }, - mbgl::style::EqualsFilter { .key = "c", .value = std::string("d") }, - }, - }; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], [NSPredicate predicateWithFormat:@"a == 'b' OR c == 'd'"]); - } - - { - mbgl::style::NoneFilter filter; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], [NSPredicate predicateWithValue:YES]); - } - - { - mbgl::style::NoneFilter filter = { - .filters = { - mbgl::style::EqualsFilter { .key = "a", .value = std::string("b") }, - mbgl::style::EqualsFilter { .key = "c", .value = std::string("d") }, - }, - }; - XCTAssertEqualObjects([NSPredicate mgl_predicateWithFilter:filter], [NSPredicate predicateWithFormat:@"NOT(a == 'b' OR c == 'd')"]); - } -} - - (void)testUnsupportedFilterPredicates { - XCTAssertThrowsSpecificNamed([NSPredicate predicateWithFormat:@"1 == 2"].mgl_filter, NSException, NSInvalidArgumentException); - XCTAssertThrowsSpecificNamed([NSPredicate predicateWithFormat:@"1 == 1"].mgl_filter, NSException, NSInvalidArgumentException); - XCTAssertThrowsSpecificNamed([NSPredicate predicateWithValue:YES].mgl_filter, NSException, NSInvalidArgumentException); - XCTAssertThrowsSpecificNamed([NSPredicate predicateWithValue:NO].mgl_filter, NSException, NSInvalidArgumentException); XCTAssertThrowsSpecificNamed([NSPredicate predicateWithFormat:@"a BEGINSWITH 'L'"].mgl_filter, NSException, NSInvalidArgumentException); XCTAssertThrowsSpecificNamed([NSPredicate predicateWithFormat:@"a ENDSWITH 'itude'"].mgl_filter, NSException, NSInvalidArgumentException); XCTAssertThrowsSpecificNamed([NSPredicate predicateWithFormat:@"a LIKE 'glob?trotter'"].mgl_filter, NSException, NSInvalidArgumentException); -- cgit v1.2.1 From baf5fd7d01c3618e415389c9dca05886e00ff307 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Mon, 14 May 2018 13:38:32 -0700 Subject: [ios, macos] Fixed English priority during label localization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Respect English in the Preferred Languages setting even if other Mapbox Streets source–supported languages are listed too. --- platform/darwin/src/MGLVectorTileSource.mm | 23 +++-------------------- platform/darwin/src/MGLVectorTileSource_Private.h | 2 -- platform/darwin/test/MGLStyleTests.mm | 4 ++++ 3 files changed, 7 insertions(+), 22 deletions(-) (limited to 'platform/darwin') diff --git a/platform/darwin/src/MGLVectorTileSource.mm b/platform/darwin/src/MGLVectorTileSource.mm index 96629997d6..6b9d857ad2 100644 --- a/platform/darwin/src/MGLVectorTileSource.mm +++ b/platform/darwin/src/MGLVectorTileSource.mm @@ -112,7 +112,8 @@ static NSArray * const MGLMapboxStreetsAlternativeLanguages = @[ return [[NSLocale localeWithLocaleIdentifier:language].languageCode isEqualToString:@"en"]; }]].count; - NSArray *preferredLanguages = [NSBundle preferredLocalizationsFromArray:MGLMapboxStreetsAlternativeLanguages + NSArray *availableLanguages = acceptsEnglish ? MGLMapboxStreetsLanguages : MGLMapboxStreetsAlternativeLanguages; + NSArray *preferredLanguages = [NSBundle preferredLocalizationsFromArray:availableLanguages forPreferences:preferencesArray]; NSString *mostSpecificLanguage; for (NSString *language in preferredLanguages) { @@ -120,10 +121,7 @@ static NSArray * const MGLMapboxStreetsAlternativeLanguages = @[ mostSpecificLanguage = language; } } - if ([mostSpecificLanguage isEqualToString:@"mul"]) { - return acceptsEnglish ? @"en" : nil; - } - return mostSpecificLanguage; + return [mostSpecificLanguage isEqualToString:@"mul"] ? nil : mostSpecificLanguage; } - (BOOL)isMapboxStreets { @@ -135,19 +133,4 @@ static NSArray * const MGLMapboxStreetsAlternativeLanguages = @[ return [identifiers containsObject:@"mapbox.mapbox-streets-v7"] || [identifiers containsObject:@"mapbox.mapbox-streets-v6"]; } -- (NS_DICTIONARY_OF(NSString *, NSString *) *)localizedKeysByKeyForPreferredLanguage:(nullable NSString *)preferredLanguage { - if (!self.mapboxStreets) { - return @{}; - } - - // Replace {name} and {name_*} with the matching localized name tag. - NSString *localizedKey = preferredLanguage ? [NSString stringWithFormat:@"name_%@", preferredLanguage] : @"name"; - NSMutableDictionary *localizedKeysByKey = [NSMutableDictionary dictionaryWithObject:localizedKey forKey:@"name"]; - for (NSString *languageCode in [MGLVectorTileSource mapboxStreetsLanguages]) { - NSString *key = [NSString stringWithFormat:@"name_%@", languageCode]; - localizedKeysByKey[key] = localizedKey; - } - return localizedKeysByKey; -} - @end diff --git a/platform/darwin/src/MGLVectorTileSource_Private.h b/platform/darwin/src/MGLVectorTileSource_Private.h index 77521869f1..109f66a432 100644 --- a/platform/darwin/src/MGLVectorTileSource_Private.h +++ b/platform/darwin/src/MGLVectorTileSource_Private.h @@ -11,8 +11,6 @@ NS_ASSUME_NONNULL_BEGIN + (nullable NSString *)preferredMapboxStreetsLanguage; + (nullable NSString *)preferredMapboxStreetsLanguageForPreferences:(NSArray *)preferencesArray; -- (NS_DICTIONARY_OF(NSString *, NSString *) *)localizedKeysByKeyForPreferredLanguage:(nullable NSString *)preferredLanguage; - @end NS_ASSUME_NONNULL_END diff --git a/platform/darwin/test/MGLStyleTests.mm b/platform/darwin/test/MGLStyleTests.mm index 6048f39ea3..32243c1bec 100644 --- a/platform/darwin/test/MGLStyleTests.mm +++ b/platform/darwin/test/MGLStyleTests.mm @@ -447,6 +447,10 @@ NSArray *preferences = @[@"zh-Hant"]; XCTAssertNil([MGLVectorTileSource preferredMapboxStreetsLanguageForPreferences:preferences]); } + { + NSArray *preferences = @[@"en", @"fr", @"el"]; + XCTAssertEqualObjects([MGLVectorTileSource preferredMapboxStreetsLanguageForPreferences:preferences], @"en"); + } { NSArray *preferences = @[@"tlh"]; XCTAssertNil([MGLVectorTileSource preferredMapboxStreetsLanguageForPreferences:preferences]); -- cgit v1.2.1 From 0d5a33df677018bc66a40e6fc1f0bf9752d98f52 Mon Sep 17 00:00:00 2001 From: Jordan Kiley Date: Tue, 15 May 2018 10:48:21 -0700 Subject: [ios, macos] Moved numbers away from start of lines in documentation (#11881) --- platform/darwin/scripts/generate-style-code.js | 2 +- platform/darwin/src/MGLBackgroundStyleLayer.h | 2 +- platform/darwin/src/MGLCircleStyleLayer.h | 10 +++---- platform/darwin/src/MGLFillExtrusionStyleLayer.h | 6 ++--- platform/darwin/src/MGLFillStyleLayer.h | 2 +- platform/darwin/src/MGLHeatmapStyleLayer.h | 8 +++--- platform/darwin/src/MGLHillshadeStyleLayer.h | 4 +-- platform/darwin/src/MGLLight.h | 2 +- platform/darwin/src/MGLLineStyleLayer.h | 14 +++++----- platform/darwin/src/MGLRasterStyleLayer.h | 14 +++++----- platform/darwin/src/MGLSymbolStyleLayer.h | 34 ++++++++++++------------ 11 files changed, 49 insertions(+), 49 deletions(-) (limited to 'platform/darwin') diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index c7b54b326a..e4e4d3dcc1 100755 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -403,7 +403,7 @@ global.describeValue = function (value, property, layerType) { case 'boolean': return value ? '`YES`' : '`NO`'; case 'number': - return 'the float ' + formatNumber(value); + return 'the float ' + '`' + formatNumber(value) + '`'; case 'string': if (value === '') { return 'the empty string'; diff --git a/platform/darwin/src/MGLBackgroundStyleLayer.h b/platform/darwin/src/MGLBackgroundStyleLayer.h index d5c3ed5403..31755c8bad 100644 --- a/platform/darwin/src/MGLBackgroundStyleLayer.h +++ b/platform/darwin/src/MGLBackgroundStyleLayer.h @@ -96,7 +96,7 @@ which it is added. The opacity at which the background will be drawn. The default value of this property is an expression that evaluates to the float - 1. Set this property to `nil` to reset it to the default value. + `1`. Set this property to `nil` to reset it to the default value. You can set this property to an expression containing any of the following: diff --git a/platform/darwin/src/MGLCircleStyleLayer.h b/platform/darwin/src/MGLCircleStyleLayer.h index 06b4de32f0..69b6e41c9c 100644 --- a/platform/darwin/src/MGLCircleStyleLayer.h +++ b/platform/darwin/src/MGLCircleStyleLayer.h @@ -117,7 +117,7 @@ MGL_EXPORT full opacity. The default value of this property is an expression that evaluates to the float - 0. Set this property to `nil` to reset it to the default value. + `0`. Set this property to `nil` to reset it to the default value. You can set this property to an expression containing any of the following: @@ -186,7 +186,7 @@ MGL_EXPORT The opacity at which the circle will be drawn. The default value of this property is an expression that evaluates to the float - 1. Set this property to `nil` to reset it to the default value. + `1`. Set this property to `nil` to reset it to the default value. You can set this property to an expression containing any of the following: @@ -235,7 +235,7 @@ MGL_EXPORT This property is measured in points. The default value of this property is an expression that evaluates to the float - 5. Set this property to `nil` to reset it to the default value. + `5`. Set this property to `nil` to reset it to the default value. You can set this property to an expression containing any of the following: @@ -334,7 +334,7 @@ MGL_EXPORT The opacity of the circle's stroke. The default value of this property is an expression that evaluates to the float - 1. Set this property to `nil` to reset it to the default value. + `1`. Set this property to `nil` to reset it to the default value. You can set this property to an expression containing any of the following: @@ -361,7 +361,7 @@ MGL_EXPORT This property is measured in points. The default value of this property is an expression that evaluates to the float - 0. Set this property to `nil` to reset it to the default value. + `0`. Set this property to `nil` to reset it to the default value. You can set this property to an expression containing any of the following: diff --git a/platform/darwin/src/MGLFillExtrusionStyleLayer.h b/platform/darwin/src/MGLFillExtrusionStyleLayer.h index 7c3a0773e4..bca2a99f1e 100644 --- a/platform/darwin/src/MGLFillExtrusionStyleLayer.h +++ b/platform/darwin/src/MGLFillExtrusionStyleLayer.h @@ -78,7 +78,7 @@ MGL_EXPORT This property is measured in meters. The default value of this property is an expression that evaluates to the float - 0. Set this property to `nil` to reset it to the default value. + `0`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `fillExtrusionHeight` is non-`nil`. Otherwise, it is ignored. @@ -164,7 +164,7 @@ MGL_EXPORT This property is measured in meters. The default value of this property is an expression that evaluates to the float - 0. Set this property to `nil` to reset it to the default value. + `0`. Set this property to `nil` to reset it to the default value. You can set this property to an expression containing any of the following: @@ -189,7 +189,7 @@ MGL_EXPORT per-layer, not per-feature, basis, and data-driven styling is not available. The default value of this property is an expression that evaluates to the float - 1. Set this property to `nil` to reset it to the default value. + `1`. Set this property to `nil` to reset it to the default value. You can set this property to an expression containing any of the following: diff --git a/platform/darwin/src/MGLFillStyleLayer.h b/platform/darwin/src/MGLFillStyleLayer.h index a159a924e6..ea19cf13cc 100644 --- a/platform/darwin/src/MGLFillStyleLayer.h +++ b/platform/darwin/src/MGLFillStyleLayer.h @@ -151,7 +151,7 @@ MGL_EXPORT value will also affect the 1pt stroke around the fill, if the stroke is used. The default value of this property is an expression that evaluates to the float - 1. Set this property to `nil` to reset it to the default value. + `1`. Set this property to `nil` to reset it to the default value. You can set this property to an expression containing any of the following: diff --git a/platform/darwin/src/MGLHeatmapStyleLayer.h b/platform/darwin/src/MGLHeatmapStyleLayer.h index ad7ba5de01..167c5bafbe 100644 --- a/platform/darwin/src/MGLHeatmapStyleLayer.h +++ b/platform/darwin/src/MGLHeatmapStyleLayer.h @@ -116,7 +116,7 @@ MGL_EXPORT Primarily used for adjusting the heatmap based on zoom level. The default value of this property is an expression that evaluates to the float - 1. Set this property to `nil` to reset it to the default value. + `1`. Set this property to `nil` to reset it to the default value. You can set this property to an expression containing any of the following: @@ -142,7 +142,7 @@ MGL_EXPORT The global opacity at which the heatmap layer will be drawn. The default value of this property is an expression that evaluates to the float - 1. Set this property to `nil` to reset it to the default value. + `1`. Set this property to `nil` to reset it to the default value. You can set this property to an expression containing any of the following: @@ -171,7 +171,7 @@ MGL_EXPORT This property is measured in points. The default value of this property is an expression that evaluates to the float - 30. Set this property to `nil` to reset it to the default value. + `30`. Set this property to `nil` to reset it to the default value. You can set this property to an expression containing any of the following: @@ -197,7 +197,7 @@ MGL_EXPORT Especially useful when combined with clustering. The default value of this property is an expression that evaluates to the float - 1. Set this property to `nil` to reset it to the default value. + `1`. Set this property to `nil` to reset it to the default value. You can set this property to an expression containing any of the following: diff --git a/platform/darwin/src/MGLHillshadeStyleLayer.h b/platform/darwin/src/MGLHillshadeStyleLayer.h index 224680160a..45b0e66751 100644 --- a/platform/darwin/src/MGLHillshadeStyleLayer.h +++ b/platform/darwin/src/MGLHillshadeStyleLayer.h @@ -130,7 +130,7 @@ MGL_EXPORT Intensity of the hillshade The default value of this property is an expression that evaluates to the float - 0.5. Set this property to `nil` to reset it to the default value. + `0.5`. Set this property to `nil` to reset it to the default value. You can set this property to an expression containing any of the following: @@ -232,7 +232,7 @@ MGL_EXPORT `hillshadeIlluminationAnchor` is set to `MGLHillshadeIlluminationAnchorMap`. The default value of this property is an expression that evaluates to the float - 335. Set this property to `nil` to reset it to the default value. + `335`. Set this property to `nil` to reset it to the default value. You can set this property to an expression containing any of the following: diff --git a/platform/darwin/src/MGLLight.h b/platform/darwin/src/MGLLight.h index cf4aa50112..13c925d9bd 100644 --- a/platform/darwin/src/MGLLight.h +++ b/platform/darwin/src/MGLLight.h @@ -188,7 +188,7 @@ MGL_EXPORT more extreme contrast. The default value of this property is an expression that evaluates to the float - 0.5. + `0.5`. You can set this property to an expression containing any of the following: diff --git a/platform/darwin/src/MGLLineStyleLayer.h b/platform/darwin/src/MGLLineStyleLayer.h index a7510142fc..9620ec438e 100644 --- a/platform/darwin/src/MGLLineStyleLayer.h +++ b/platform/darwin/src/MGLLineStyleLayer.h @@ -180,7 +180,7 @@ MGL_EXPORT Used to automatically convert miter joins to bevel joins for sharp angles. The default value of this property is an expression that evaluates to the float - 2. Set this property to `nil` to reset it to the default value. + `2`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `lineJoin` is set to an expression that evaluates to `miter`. Otherwise, it is ignored. @@ -202,7 +202,7 @@ MGL_EXPORT Used to automatically convert round joins to miter joins for shallow angles. The default value of this property is an expression that evaluates to the float - 1.05. Set this property to `nil` to reset it to the default value. + `1.05`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `lineJoin` is set to an expression that evaluates to `round`. Otherwise, it is ignored. @@ -228,7 +228,7 @@ MGL_EXPORT This property is measured in points. The default value of this property is an expression that evaluates to the float - 0. Set this property to `nil` to reset it to the default value. + `0`. Set this property to `nil` to reset it to the default value. You can set this property to an expression containing any of the following: @@ -343,7 +343,7 @@ MGL_EXPORT This property is measured in points. The default value of this property is an expression that evaluates to the float - 0. Set this property to `nil` to reset it to the default value. + `0`. Set this property to `nil` to reset it to the default value. You can set this property to an expression containing any of the following: @@ -372,7 +372,7 @@ MGL_EXPORT This property is measured in points. The default value of this property is an expression that evaluates to the float - 0. Set this property to `nil` to reset it to the default value. + `0`. Set this property to `nil` to reset it to the default value. You can set this property to an expression containing any of the following: @@ -396,7 +396,7 @@ MGL_EXPORT The opacity at which the line will be drawn. The default value of this property is an expression that evaluates to the float - 1. Set this property to `nil` to reset it to the default value. + `1`. Set this property to `nil` to reset it to the default value. You can set this property to an expression containing any of the following: @@ -542,7 +542,7 @@ MGL_EXPORT This property is measured in points. The default value of this property is an expression that evaluates to the float - 1. Set this property to `nil` to reset it to the default value. + `1`. Set this property to `nil` to reset it to the default value. You can set this property to an expression containing any of the following: diff --git a/platform/darwin/src/MGLRasterStyleLayer.h b/platform/darwin/src/MGLRasterStyleLayer.h index bca9649e5d..ff055d24f6 100644 --- a/platform/darwin/src/MGLRasterStyleLayer.h +++ b/platform/darwin/src/MGLRasterStyleLayer.h @@ -64,7 +64,7 @@ MGL_EXPORT brightness. The default value of this property is an expression that evaluates to the float - 1. Set this property to `nil` to reset it to the default value. + `1`. Set this property to `nil` to reset it to the default value. This attribute corresponds to the raster-brightness-max @@ -97,7 +97,7 @@ MGL_EXPORT brightness. The default value of this property is an expression that evaluates to the float - 0. Set this property to `nil` to reset it to the default value. + `0`. Set this property to `nil` to reset it to the default value. This attribute corresponds to the raster-brightness-min @@ -129,7 +129,7 @@ MGL_EXPORT Increase or reduce the contrast of the image. The default value of this property is an expression that evaluates to the float - 0. Set this property to `nil` to reset it to the default value. + `0`. Set this property to `nil` to reset it to the default value. You can set this property to an expression containing any of the following: @@ -157,7 +157,7 @@ MGL_EXPORT This property is measured in milliseconds. The default value of this property is an expression that evaluates to the float - 300. Set this property to `nil` to reset it to the default value. + `300`. Set this property to `nil` to reset it to the default value. You can set this property to an expression containing any of the following: @@ -178,7 +178,7 @@ MGL_EXPORT This property is measured in degrees. The default value of this property is an expression that evaluates to the float - 0. Set this property to `nil` to reset it to the default value. + `0`. Set this property to `nil` to reset it to the default value. This attribute corresponds to the raster-hue-rotate @@ -210,7 +210,7 @@ MGL_EXPORT The opacity at which the image will be drawn. The default value of this property is an expression that evaluates to the float - 1. Set this property to `nil` to reset it to the default value. + `1`. Set this property to `nil` to reset it to the default value. You can set this property to an expression containing any of the following: @@ -236,7 +236,7 @@ MGL_EXPORT Increase or reduce the saturation of the image. The default value of this property is an expression that evaluates to the float - 0. Set this property to `nil` to reset it to the default value. + `0`. Set this property to `nil` to reset it to the default value. You can set this property to an expression containing any of the following: diff --git a/platform/darwin/src/MGLSymbolStyleLayer.h b/platform/darwin/src/MGLSymbolStyleLayer.h index e27f039b75..2c899fe76f 100644 --- a/platform/darwin/src/MGLSymbolStyleLayer.h +++ b/platform/darwin/src/MGLSymbolStyleLayer.h @@ -564,7 +564,7 @@ MGL_EXPORT This property is measured in points. The default value of this property is an expression that evaluates to the float - 2. Set this property to `nil` to reset it to the default value. + `2`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`. Otherwise, it is ignored. @@ -615,7 +615,7 @@ MGL_EXPORT This property is measured in degrees. The default value of this property is an expression that evaluates to the float - 0. Set this property to `nil` to reset it to the default value. + `0`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`. Otherwise, it is ignored. @@ -678,7 +678,7 @@ MGL_EXPORT This property is measured in factor of the original icon sizes. The default value of this property is an expression that evaluates to the float - 1. Set this property to `nil` to reset it to the default value. + `1`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`. Otherwise, it is ignored. @@ -858,7 +858,7 @@ MGL_EXPORT This property is measured in degrees. The default value of this property is an expression that evaluates to the float - 45. Set this property to `nil` to reset it to the default value. + `45`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`, and `symbolPlacement` is set to an expression that evaluates to `line`. Otherwise, @@ -890,7 +890,7 @@ MGL_EXPORT This property is measured in ems. The default value of this property is an expression that evaluates to the float - 10. Set this property to `nil` to reset it to the default value. + `10`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. @@ -973,7 +973,7 @@ MGL_EXPORT This property is measured in points. The default value of this property is an expression that evaluates to the float - 250. Set this property to `nil` to reset it to the default value. + `250`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `symbolPlacement` is set to an expression that evaluates to `line`. Otherwise, it is ignored. @@ -1129,7 +1129,7 @@ MGL_EXPORT This property is measured in points. The default value of this property is an expression that evaluates to the float - 16. Set this property to `nil` to reset it to the default value. + `16`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. @@ -1219,7 +1219,7 @@ MGL_EXPORT This property is measured in ems. The default value of this property is an expression that evaluates to the float - 0. Set this property to `nil` to reset it to the default value. + `0`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. @@ -1241,7 +1241,7 @@ MGL_EXPORT This property is measured in ems. The default value of this property is an expression that evaluates to the float - 1.2. Set this property to `nil` to reset it to the default value. + `1.2`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. @@ -1338,7 +1338,7 @@ MGL_EXPORT This property is measured in points. The default value of this property is an expression that evaluates to the float - 2. Set this property to `nil` to reset it to the default value. + `2`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. @@ -1389,7 +1389,7 @@ MGL_EXPORT This property is measured in degrees. The default value of this property is an expression that evaluates to the float - 0. Set this property to `nil` to reset it to the default value. + `0`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. @@ -1529,7 +1529,7 @@ MGL_EXPORT This property is measured in points. The default value of this property is an expression that evaluates to the float - 0. Set this property to `nil` to reset it to the default value. + `0`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`. Otherwise, it is ignored. @@ -1611,7 +1611,7 @@ MGL_EXPORT This property is measured in points. The default value of this property is an expression that evaluates to the float - 0. Set this property to `nil` to reset it to the default value. + `0`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`. Otherwise, it is ignored. @@ -1638,7 +1638,7 @@ MGL_EXPORT The opacity at which the icon will be drawn. The default value of this property is an expression that evaluates to the float - 1. Set this property to `nil` to reset it to the default value. + `1`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `iconImageName` is non-`nil`. Otherwise, it is ignored. @@ -1819,7 +1819,7 @@ MGL_EXPORT This property is measured in points. The default value of this property is an expression that evaluates to the float - 0. Set this property to `nil` to reset it to the default value. + `0`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. @@ -1900,7 +1900,7 @@ MGL_EXPORT This property is measured in points. The default value of this property is an expression that evaluates to the float - 0. Set this property to `nil` to reset it to the default value. + `0`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. @@ -1927,7 +1927,7 @@ MGL_EXPORT The opacity at which the text will be drawn. The default value of this property is an expression that evaluates to the float - 1. Set this property to `nil` to reset it to the default value. + `1`. Set this property to `nil` to reset it to the default value. This property is only applied to the style if `text` is non-`nil`. Otherwise, it is ignored. -- cgit v1.2.1