diff options
author | jmkiley <jordan.kiley@mapbox.com> | 2019-09-26 16:38:17 -0700 |
---|---|---|
committer | jmkiley <jordan.kiley@mapbox.com> | 2019-09-26 16:38:17 -0700 |
commit | 24ee9039df90d31879b5069536e4e2de39db674a (patch) | |
tree | 178405c31146a146ab581c9b8bc3dc71f1fe7423 | |
parent | 38ee2963dd174bb11d0a3f875bc24c709c40a522 (diff) | |
download | qtlocation-mapboxgl-24ee9039df90d31879b5069536e4e2de39db674a.tar.gz |
[ios] Additional cleanup
-rw-r--r-- | platform/darwin/src/MGLShapeSource.h | 4 | ||||
-rw-r--r-- | platform/darwin/src/MGLShapeSource.mm | 26 | ||||
-rw-r--r-- | platform/ios/app/MBXViewController.m | 49 |
3 files changed, 29 insertions, 50 deletions
diff --git a/platform/darwin/src/MGLShapeSource.h b/platform/darwin/src/MGLShapeSource.h index 384d4d49f0..8eb581dae1 100644 --- a/platform/darwin/src/MGLShapeSource.h +++ b/platform/darwin/src/MGLShapeSource.h @@ -46,10 +46,10 @@ FOUNDATION_EXTERN MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionClus The dictionary key is an `NSString` that will be an attribute key for the clusters. The dictionary value is an `NSArray` consisting of a reduce operator and a map expression. - The reduce operator is any expression function that accepts at least two operands. It can be a string containing a single operator, such as `sum:`, or a valid expression with two expression arguments: `featureAccumulated` and + The reduce operator is any `NSExpression` function that accepts at least two operands. It can be a string containing a single function, such as `sum:`, or a valid expression with two expression arguments: `featureAccumulated` and another valid expression. - The map expression produces the value of a single point. + The map expression is an `NSExpression` that produces the value of a single point within the cluster. This option corresponds to the <a href="https://www.mapbox.com/mapbox-gl-style-spec/#sources-geojson-clusterProperties"><code>clusterProperties</code></a> diff --git a/platform/darwin/src/MGLShapeSource.mm b/platform/darwin/src/MGLShapeSource.mm index 66dc4697eb..b806987267 100644 --- a/platform/darwin/src/MGLShapeSource.mm +++ b/platform/darwin/src/MGLShapeSource.mm @@ -96,45 +96,45 @@ mbgl::style::GeoJSONOptions MGLGeoJSONOptionsFromDictionary(NSDictionary<MGLShap NSString *key; while (key = [stringEnumerator nextObject]) { - NSArray *expArray = value[key]; - if (![expArray isKindOfClass:[NSArray class]]) { + NSArray *expressionsArray = value[key]; + if (![expressionsArray isKindOfClass:[NSArray class]]) { [NSException raise:NSInvalidArgumentException format:@"MGLShapeSourceOptionClusterProperties dictinary member value must be an array containing two objects."]; } // check that array has only 2 values - if ([expArray count] != 2) { + if ([expressionsArray count] != 2) { [NSException raise:NSInvalidArgumentException format:@"MGLShapeSourceOptionClusterProperties member value requires array of two objects."]; } // reduceExpression could be either a string of operator, or a valid NSExpression - NSString *reduceOperator = expArray[0]; - NSExpression *reduceExpre; + NSString *reduceOperator = expressionsArray[0]; + NSExpression *reduceExpression; if ([reduceOperator isKindOfClass:[NSString class]]) { // If reduceOperator is a string, prepare a full NSExpression before parsing - NSString *reduceExpression = [NSString stringWithFormat:@"%@({ $featureAccumulated, %@})", reduceOperator, key]; - reduceExpre = [NSExpression expressionWithFormat:reduceExpression]; + NSString *reduceString = [NSString stringWithFormat:@"%@({ $featureAccumulated, %@})", reduceOperator, key]; + reduceExpression = [NSExpression expressionWithFormat:reduceString]; } else { - reduceExpre = expArray[0]; + reduceExpression = expressionsArray[0]; } - if (![reduceExpre isKindOfClass:[NSExpression class]]) { + if (![reduceExpression isKindOfClass:[NSExpression class]]) { [NSException raise:NSInvalidArgumentException format:@"MGLShapeSourceOptionClusterProperties member value shall contain a valid reduceExpression."]; } - auto reduce = MGLClusterPropertyFromNSExpression(reduceExpre); + auto reduce = MGLClusterPropertyFromNSExpression(reduceExpression); if (!reduce) { [NSException raise:NSInvalidArgumentException format:@"Failed to convert MGLShapeSourceOptionClusterProperties reduce expression."]; } // mapExpression shall be a valid NSExpression - NSExpression *mapExpre = expArray[1]; - if (![mapExpre isKindOfClass:[NSExpression class]]) { + NSExpression *mapExpression = expressionsArray[1]; + if (![mapExpression isKindOfClass:[NSExpression class]]) { [NSException raise:NSInvalidArgumentException format:@"MGLShapeSourceOptionClusterProperties member value shall contain a valid mapExpression.."]; } - auto map = MGLClusterPropertyFromNSExpression(mapExpre); + auto map = MGLClusterPropertyFromNSExpression(mapExpression); if (!map) { [NSException raise:NSInvalidArgumentException format:@"Failed to convert MGLShapeSourceOptionClusterProperties map expression."]; diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index c319b43682..82a68e074a 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -1296,7 +1296,6 @@ CLLocationCoordinate2D randomWorldCoordinate() { NSData *data = [geoJSON dataUsingEncoding:NSUTF8StringEncoding]; MGLShape *shape = [MGLShape shapeWithData:data encoding:NSUTF8StringEncoding error:NULL]; - MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"mutable-data-source-id" shape:shape options:nil]; [self.mapView.style addSource:source]; @@ -1315,42 +1314,22 @@ CLLocationCoordinate2D randomWorldCoordinate() { { [self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(48.668731, -122.857151) zoomLevel:11 animated:NO]; - NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"earthquakes" ofType:@"geojson"]; + NSString *filePath = [[NSBundle bundleForClass:self.class] pathForResource:@"polyline" ofType:@"geojson"]; NSURL *geoJSONURL = [NSURL fileURLWithPath:filePath]; -// MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"mutable-data-source-url-id" URL:geoJSONURL options:nil]; - - // Input property with format {"property_name": [[reduce_operator, accumulated, expression], [map_expression]]} -// NSExpression *reduceExpression1 = [NSExpression expressionForFunction:@"sum:" arguments:@[[NSExpression expressionForVariable:@"featureAccumulated"], [NSExpression expressionForKeyPath:@"sumVal"]]]; - NSExpression *reduceExpression1 = [NSExpression expressionWithFormat:@"sum({ $featureAccumulated, sumVal })"]; - NSExpression *mapExpression1 = [NSExpression expressionForKeyPath:@"mag"]; - NSArray *expressArray1 = @[reduceExpression1, mapExpression1]; - - // Input propety with format {"property_name": [[literal(reduce_operator)], [map_expression]]} - NSString *reduceExpression2 = @"max"; - NSExpression *mapExpression2 = [NSExpression expressionForKeyPath:@"mag"]; - NSArray *expressArray2 = @[reduceExpression2, mapExpression2]; - - NSDictionary *clusterProperty = @{@"sumVal" : expressArray1, - @"maxVal" : expressArray2 - }; - - MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"mutable-data-source-id" - URL:geoJSONURL - options:@{ - MGLShapeSourceOptionClustered: @(YES), - MGLShapeSourceOptionClusterRadius: @(15), - MGLShapeSourceOptionClusterProperties: clusterProperty - }]; - + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"mutable-data-source-url-id" URL:geoJSONURL options:nil]; [self.mapView.style addSource:source]; - - // Create image cluster style layer - MGLSymbolStyleLayer *clusterLayer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"clusteredPortsNumbers" source:source]; - clusterLayer.textColor = [NSExpression expressionForConstantValue:[UIColor redColor]]; - clusterLayer.textFontSize = [NSExpression expressionForConstantValue:@(30)]; - clusterLayer.text = [NSExpression expressionWithFormat:@"CAST(maxVal, 'NSString')"]; - - [self.mapView.style addLayer:clusterLayer]; + + MGLLineStyleLayer *layer = [[MGLLineStyleLayer alloc] initWithIdentifier:@"mutable-data-layer-url-id" source:source]; + [self.mapView.style addLayer:layer]; + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(41.563986787078704, -75.04843935793578) zoomLevel:8 animated:NO]; + + NSString *threeStatesFilePath = [[NSBundle bundleForClass:self.class] pathForResource:@"threestates" ofType:@"geojson"]; + NSURL *updatedGeoJSONURL = [NSURL fileURLWithPath:threeStatesFilePath]; + + source.URL = updatedGeoJSONURL; + }); } - (void)updateShapeSourceFeatures |