diff options
author | jmkiley <jordan.kiley@mapbox.com> | 2019-10-04 13:56:14 -0700 |
---|---|---|
committer | jmkiley <jordan.kiley@mapbox.com> | 2019-10-04 13:56:14 -0700 |
commit | 482471594ba2aa04424df47113ede9931b1cbd4e (patch) | |
tree | b7af79535ab78fae424025c38e99537334f9c52c | |
parent | f75a3f88a9bd6d4956066c4e0c77e23df7633728 (diff) | |
download | qtlocation-mapboxgl-482471594ba2aa04424df47113ede9931b1cbd4e.tar.gz |
[ios] added debug code, switch string to expression
-rw-r--r-- | platform/darwin/src/MGLShapeSource.h | 16 | ||||
-rw-r--r-- | platform/darwin/src/MGLShapeSource.mm | 16 | ||||
-rw-r--r-- | platform/ios/app/MBXViewController.m | 17 |
3 files changed, 36 insertions, 13 deletions
diff --git a/platform/darwin/src/MGLShapeSource.h b/platform/darwin/src/MGLShapeSource.h index 967fb94544..94e443b549 100644 --- a/platform/darwin/src/MGLShapeSource.h +++ b/platform/darwin/src/MGLShapeSource.h @@ -42,14 +42,20 @@ FOUNDATION_EXTERN MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionClus FOUNDATION_EXTERN MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionClusterRadius; /** - An `NSDictionary` object where the key is an `NSString`. The dictionary key will be the attribute feature attribute key. The resulting attribute value is aggregated from the clustered points. The dictionary value is an `NSArray` consisting of a reduce operator and a map expression. + An `NSDictionary` object where the key is an `NSString`. The dictionary key will + be the attribute feature attribute key. The resulting attribute value is + aggregated from the clustered points. The dictionary value is an `NSArray` + consisting of two objects. - The reduce operator is any `NSExpression` function that accepts at least two operands. You can use one of the following: + The first object determines how the attributes are accumulated from the cluster + points. You can use one of the following: - * An `NSString` containing a single function, such as `sum` or `max`. - * An `NSExpression` that takes two expression arguments: `featureAccumulated` and another valid expression. + * An `[NSExpression expressionForConstantValue:]` containing a single function string, such as `sum:` or `max:`, which takes at least two operands. + * An `NSExpression` that takes two expression arguments: `featureAccumulated` and + another valid expression. - The map expression is an `NSExpression` that produces the value of a single point within the cluster. + The second object in the array 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 00641c4a93..8bf0a3d3e5 100644 --- a/platform/darwin/src/MGLShapeSource.mm +++ b/platform/darwin/src/MGLShapeSource.mm @@ -108,20 +108,20 @@ mbgl::style::GeoJSONOptions MGLGeoJSONOptionsFromDictionary(NSDictionary<MGLShap } // reduceExpression could be either a string of operator, or a valid NSExpression - NSString *reduceOperator = expressionsArray[0]; + if (![expressionsArray.firstObject isKindOfClass:[NSExpression class]]) { + [NSException raise:NSInvalidArgumentException + format:@"MGLShapeSourceOptionClusterProperties array value requires two expression objects."]; + } + NSExpression *reduceOperator = expressionsArray[0]; NSExpression *reduceExpression; - if ([reduceOperator isKindOfClass:[NSString class]]) { + if (reduceOperator.expressionType == NSConstantValueExpressionType) { // If reduceOperator is a string, prepare a full NSExpression before parsing - NSString *reduceString = [NSString stringWithFormat:@"%@({ $featureAccumulated, %@})", reduceOperator, key]; + NSString *reduceString = [NSString stringWithFormat:@"%@({ $featureAccumulated, %@})", reduceOperator.constantValue, key]; reduceExpression = [NSExpression expressionWithFormat:reduceString]; } else { reduceExpression = expressionsArray[0]; } - if (![reduceExpression isKindOfClass:[NSExpression class]]) { - [NSException raise:NSInvalidArgumentException - format:@"MGLShapeSourceOptionClusterProperties member value shall contain a valid reduceExpression."]; - } auto reduce = MGLClusterPropertyFromNSExpression(reduceExpression); if (!reduce) { [NSException raise:NSInvalidArgumentException @@ -132,7 +132,7 @@ mbgl::style::GeoJSONOptions MGLGeoJSONOptionsFromDictionary(NSDictionary<MGLShap NSExpression *mapExpression = expressionsArray[1]; if (![mapExpression isKindOfClass:[NSExpression class]]) { [NSException raise:NSInvalidArgumentException - format:@"MGLShapeSourceOptionClusterProperties member value shall contain a valid mapExpression."]; + format:@"MGLShapeSourceOptionClusterProperties member value must contain a valid NSExpression."]; } auto map = MGLClusterPropertyFromNSExpression(mapExpression); if (!map) { diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m index 82a68e074a..cead3b4339 100644 --- a/platform/ios/app/MBXViewController.m +++ b/platform/ios/app/MBXViewController.m @@ -2202,6 +2202,23 @@ CLLocationCoordinate2D randomWorldCoordinate() { // that a device with an English-language locale is already effectively // using locale-based country labels. _localizingLabels = [[self bestLanguageForUser] isEqualToString:@"en"]; + + NSURL *url = [NSURL URLWithString:@"https://www.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson"]; + + NSExpression *reduceExpression1 = [NSExpression expressionWithFormat:@"sum:"]; + + NSExpression *mapExpression1 = [NSExpression expressionForKeyPath:@"mag"]; + NSArray *expressArray1 = @[reduceExpression1, mapExpression1]; + + MGLShapeSource *source = [[MGLShapeSource alloc] initWithIdentifier:@"earthquakes" URL:url options:@{ + MGLShapeSourceOptionClustered: @(YES), + MGLShapeSourceOptionClusterRadius: @(15), + MGLShapeSourceOptionClusterProperties: @{@"sumVal" : expressArray1 }}]; + [mapView.style addSource:source]; + MGLSymbolStyleLayer *clusterLayer = [[MGLSymbolStyleLayer alloc] initWithIdentifier:@"clusteredPortsNumbers" source:source]; + clusterLayer.text = [NSExpression expressionWithFormat:@"CAST(sumVal, 'NSString')"]; + [self.mapView.style addLayer:clusterLayer]; + } - (BOOL)mapView:(MGLMapView *)mapView shouldChangeFromCamera:(MGLMapCamera *)oldCamera toCamera:(MGLMapCamera *)newCamera { |