summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzmiao <zmiao.jamie@gmail.com>2019-09-18 15:25:52 +0300
committerjmkiley <jordan.kiley@mapbox.com>2019-09-25 14:28:56 -0700
commitfbe7ce8ada734bfa71a2a4a3481ed8e28b1aa21d (patch)
tree7407d1f3dab22026920132bbfee7c21c3c17ac5d
parent8a06ca4646ee7912807e851938f5c943c59acbb6 (diff)
downloadqtlocation-mapboxgl-fbe7ce8ada734bfa71a2a4a3481ed8e28b1aa21d.tar.gz
Add type checker
-rw-r--r--platform/darwin/src/MGLShapeSource.h2
-rw-r--r--platform/darwin/src/MGLShapeSource.mm34
2 files changed, 25 insertions, 11 deletions
diff --git a/platform/darwin/src/MGLShapeSource.h b/platform/darwin/src/MGLShapeSource.h
index 08891ee90c..03dea116b0 100644
--- a/platform/darwin/src/MGLShapeSource.h
+++ b/platform/darwin/src/MGLShapeSource.h
@@ -42,7 +42,7 @@ FOUNDATION_EXTERN MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionClus
FOUNDATION_EXTERN MGL_EXPORT const MGLShapeSourceOption MGLShapeSourceOptionClusterRadius;
/**
- An `NSDictionary` objcet containing custom properties on the generated clusters if clustering is enabled,
+ An `NSDictionary` object containing custom properties on the generated clusters if clustering is enabled,
aggregating values from clustered points. Has the form {"property_name": [recude_operator, [map_expression]]} or
{"property_name": [[reduce_operator, accumulated, expression], [map_expression]]}
diff --git a/platform/darwin/src/MGLShapeSource.mm b/platform/darwin/src/MGLShapeSource.mm
index 8ec92880cb..66dc4697eb 100644
--- a/platform/darwin/src/MGLShapeSource.mm
+++ b/platform/darwin/src/MGLShapeSource.mm
@@ -96,36 +96,50 @@ mbgl::style::GeoJSONOptions MGLGeoJSONOptionsFromDictionary(NSDictionary<MGLShap
NSString *key;
while (key = [stringEnumerator nextObject]) {
- // check that array has only 2 values
NSArray *expArray = value[key];
- if ([expArray count] != 2) {
+ if (![expArray isKindOfClass:[NSArray class]]) {
[NSException raise:NSInvalidArgumentException
- format:@"MGLShapeSourceOptionClusterProperties requires two NSExpression objects."];
+ format:@"MGLShapeSourceOptionClusterProperties dictinary member value must be an array containing two objects."];
}
-
- NSExpression *mapExpre = expArray[1];
- auto map = MGLClusterPropertyFromNSExpression(mapExpre);
- if (!map) {
+ // check that array has only 2 values
+ if ([expArray count] != 2) {
[NSException raise:NSInvalidArgumentException
- format:@"Failed to convert MGLShapeSourceOptionClusterProperties map expression."];
+ 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;
- // If reduceOperator is only a string instead of expression, create the integrated full expression before parsing
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];
} else {
reduceExpre = expArray[0];
}
+ if (![reduceExpre isKindOfClass:[NSExpression class]]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"MGLShapeSourceOptionClusterProperties member value shall contain a valid reduceExpression."];
+ }
auto reduce = MGLClusterPropertyFromNSExpression(reduceExpre);
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]]) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"MGLShapeSourceOptionClusterProperties member value shall contain a valid mapExpression.."];
+ }
+ auto map = MGLClusterPropertyFromNSExpression(mapExpre);
+ if (!map) {
+ [NSException raise:NSInvalidArgumentException
+ format:@"Failed to convert MGLShapeSourceOptionClusterProperties map expression."];
+ }
+
std::string keyString = std::string([key UTF8String]);
geoJSONOptions.clusterProperties.emplace(keyString, std::make_pair(std::move(map), std::move(reduce)));