summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Rex <julian.rex@mapbox.com>2019-01-11 16:10:54 -0500
committerJulian Rex <julian.rex@mapbox.com>2019-01-12 14:36:51 -0500
commit8c4066d6a74ac6b89463c2629fa7397fe99ef818 (patch)
treeb29fe18c0e3051e6e6d345956ba9716435d400dd
parent8ebce7fda579cff81d8cdacf472f5573512baf0c (diff)
downloadqtlocation-mapboxgl-8c4066d6a74ac6b89463c2629fa7397fe99ef818.tar.gz
WIP updates
-rw-r--r--platform/darwin/src/MGLCluster.h12
-rw-r--r--platform/darwin/src/MGLCluster.mm42
-rw-r--r--platform/darwin/src/MGLCluster_Private.h2
-rw-r--r--platform/darwin/src/MGLShapeSource.h6
-rw-r--r--platform/darwin/src/MGLShapeSource.mm82
-rw-r--r--platform/darwin/src/MGLShapeSource_Private.h2
-rw-r--r--platform/darwin/test/MGLCodingTests.mm2
-rw-r--r--platform/darwin/test/MGLDocumentationExampleTests.swift3
-rw-r--r--platform/darwin/test/MGLFeatureTests.mm2
9 files changed, 99 insertions, 54 deletions
diff --git a/platform/darwin/src/MGLCluster.h b/platform/darwin/src/MGLCluster.h
index a3524737fc..2a3b5270da 100644
--- a/platform/darwin/src/MGLCluster.h
+++ b/platform/darwin/src/MGLCluster.h
@@ -36,7 +36,7 @@ FOUNDATION_EXTERN MGL_EXPORT const NSUInteger MGLClusterIdentifierInvalid;
```
*/
MGL_EXPORT
-@protocol MGLCluster <NSObject>
+@protocol MGLCluster <MGLFeature>
/** The identifier for the cluster. */
@property (nonatomic, readonly) NSUInteger clusterIdentifier;
@@ -44,11 +44,11 @@ MGL_EXPORT
/** The number of points within this cluster */
@property (nonatomic, readonly) NSUInteger clusterPointCount;
-/**
- An `NSString` abbreviation for the number of points within this cluster. For
- example "1.2k".
- */
-@property (nonatomic, readonly) NSString *clusterPointCountAbbreviation;
+///**
+// An `NSString` abbreviation for the number of points within this cluster. For
+// example "1.2k".
+// */
+//@property (nonatomic, readonly) NSString *clusterPointCountAbbreviation;
@end
NS_ASSUME_NONNULL_END
diff --git a/platform/darwin/src/MGLCluster.mm b/platform/darwin/src/MGLCluster.mm
index 7d5e72aba6..2cc296fa91 100644
--- a/platform/darwin/src/MGLCluster.mm
+++ b/platform/darwin/src/MGLCluster.mm
@@ -7,7 +7,7 @@
NSString * const MGLClusterBoolKey = @"cluster";
NSString * const MGLClusterIdentifierKey = @"cluster_id";
NSString * const MGLClusterCountKey = @"point_count";
-NSString * const MGLClusterCountAbbreviationKey = @"point_count_abbreviated";
+//NSString * const MGLClusterCountAbbreviationKey = @"point_count_abbreviated";
const NSUInteger MGLClusterIdentifierInvalid = NSUIntegerMax;
@@ -58,22 +58,22 @@ static NSUInteger MGLClusterPointCountIMP(id self, SEL _cmd) {
return [count unsignedIntegerValue];
}
-/**
- Static free function used as implementation for custom subclasses (that conform
- to both `MGLFeature` and `MGLCluster`).
- */
-static NSString *MGLClusterPointCountAbbreviationIMP(id self, SEL _cmd) {
- id<MGLFeature> feature = MGL_OBJC_DYNAMIC_CAST_AS_PROTOCOL(self, MGLFeature);
-
- NSString *abbreviation = MGL_OBJC_DYNAMIC_CAST([feature attributeForKey:MGLClusterCountAbbreviationKey], NSString);
- MGLAssert(abbreviation, @"Clusters should have a point_count_abbreviated");
-
- if (!abbreviation) {
- return @"0";
- }
-
- return abbreviation;
-}
+///**
+// Static free function used as implementation for custom subclasses (that conform
+// to both `MGLFeature` and `MGLCluster`).
+// */
+//static NSString *MGLClusterPointCountAbbreviationIMP(id self, SEL _cmd) {
+// id<MGLFeature> feature = MGL_OBJC_DYNAMIC_CAST_AS_PROTOCOL(self, MGLFeature);
+//
+// NSString *abbreviation = MGL_OBJC_DYNAMIC_CAST([feature attributeForKey:MGLClusterCountAbbreviationKey], NSString);
+// MGLAssert(abbreviation, @"Clusters should have a point_count_abbreviated");
+//
+// if (!abbreviation) {
+// return @"0";
+// }
+//
+// return abbreviation;
+//}
static IMP MGLFeatureClusterIMPFromSelector(SEL selector) {
if (selector == @selector(clusterIdentifier)) {
@@ -82,9 +82,9 @@ static IMP MGLFeatureClusterIMPFromSelector(SEL selector) {
else if (selector == @selector(clusterPointCount)) {
return (IMP)MGLClusterPointCountIMP;
}
- else if (selector == @selector(clusterPointCountAbbreviation)) {
- return (IMP)MGLClusterPointCountAbbreviationIMP;
- }
+// else if (selector == @selector(clusterPointCountAbbreviation)) {
+// return (IMP)MGLClusterPointCountAbbreviationIMP;
+// }
MGLCAssert(0, @"Unrecognized selector: %@", NSStringFromSelector(selector));
return NULL;
}
@@ -149,7 +149,7 @@ id<MGLFeature, MGLCluster> MGLConvertFeatureToClusterSubclass(id<MGLFeature> fea
MGLCAssert([cluster respondsToSelector:@selector(clusterIdentifier)], @"Feature subclass %@ - missing selector `clusterIdentifier`", subclassName);
MGLCAssert([cluster respondsToSelector:@selector(clusterPointCount)], @"Feature subclass %@ - missing selector `clusterPointCount`", subclassName);
- MGLCAssert([cluster respondsToSelector:@selector(clusterPointCountAbbreviation)], @"Feature subclass %@ - missing selector `clusterPointCountAbbreviation`", subclassName);
+// MGLCAssert([cluster respondsToSelector:@selector(clusterPointCountAbbreviation)], @"Feature subclass %@ - missing selector `clusterPointCountAbbreviation`", subclassName);
return cluster;
}
diff --git a/platform/darwin/src/MGLCluster_Private.h b/platform/darwin/src/MGLCluster_Private.h
index e3019c3dcd..5117c68918 100644
--- a/platform/darwin/src/MGLCluster_Private.h
+++ b/platform/darwin/src/MGLCluster_Private.h
@@ -7,7 +7,7 @@
FOUNDATION_EXPORT NSString * const MGLClusterBoolKey;
FOUNDATION_EXPORT NSString * const MGLClusterIdentifierKey;
FOUNDATION_EXPORT NSString * const MGLClusterCountKey;
-FOUNDATION_EXPORT NSString * const MGLClusterCountAbbreviationKey;
+//FOUNDATION_EXPORT NSString * const MGLClusterCountAbbreviationKey;
FOUNDATION_EXPORT BOOL MGLFeatureHasClusterAttribute(id<MGLFeature> feature);
diff --git a/platform/darwin/src/MGLShapeSource.h b/platform/darwin/src/MGLShapeSource.h
index 0263c39c58..1c37252a3d 100644
--- a/platform/darwin/src/MGLShapeSource.h
+++ b/platform/darwin/src/MGLShapeSource.h
@@ -337,7 +337,7 @@ MGL_EXPORT
@return An array of objects that conform to the `MGLFeature` protocol.
*/
-- (NSArray<id <MGLFeature>> *)leavesOfCluster:(id<MGLCluster>)cluster offset:(NSUInteger)offset limit:(NSUInteger)limit;
+- (NSArray<id <MGLFeature>> *)leavesOfCluster:(MGLShape<MGLCluster> *)cluster offset:(NSUInteger)offset limit:(NSUInteger)limit;
/**
Returns an array of map features that are the immediate children of the specified
@@ -353,7 +353,7 @@ MGL_EXPORT
zoom level doesn't the zoom level for expanding that cluster. See
`-[MGLShapeSource zoomLevelForExpandingCluster:]`.
*/
-- (NSArray<id <MGLFeature>> *)childrenOfCluster:(id<MGLCluster>)cluster;
+- (NSArray<id<MGLFeature>> *)childrenOfCluster:(MGLShape<MGLCluster> *)cluster;
/**
Returns the zoom level at which the given cluster expands.
@@ -364,7 +364,7 @@ MGL_EXPORT
@return Zoom level. This should be >= 0; any negative return value should be
considered an error.
*/
-- (double)zoomLevelForExpandingCluster:(id<MGLCluster>)cluster;
+- (double)zoomLevelForExpandingCluster:(MGLShape<MGLCluster> *)cluster;
@end
diff --git a/platform/darwin/src/MGLShapeSource.mm b/platform/darwin/src/MGLShapeSource.mm
index 35d6cf8421..7720f94328 100644
--- a/platform/darwin/src/MGLShapeSource.mm
+++ b/platform/darwin/src/MGLShapeSource.mm
@@ -189,34 +189,86 @@ mbgl::style::GeoJSONOptions MGLGeoJSONOptionsFromDictionary(NSDictionary<MGLShap
#pragma mark - MGLCluster management
-- (NSArray<id <MGLFeature>> *)leavesOfCluster:(id<MGLCluster>)cluster offset:(NSUInteger)offset limit:(NSUInteger)limit {
- if(!self.rawSource) {
+- (mbgl::optional<mbgl::FeatureExtensionValue>)featureExtensionValueOfCluster:(MGLShape<MGLCluster> *)cluster extension:(std::string)extension options:(const std::map<std::string, mbgl::Value>)options {
+ mbgl::optional<mbgl::FeatureExtensionValue> extensionValue;
+
+ // Check parameters
+ if (!self.rawSource || !self.mapView || !cluster) {
+ return extensionValue;
+ }
+
+ auto geoJSON = [cluster geoJSONObject];
+
+ if (!geoJSON.is<mbgl::Feature>()) {
+ MGLAssert(0, @"cluster geoJSON object is not a feature.");
+ return extensionValue;
+ }
+
+ auto clusterFeature = geoJSON.get<mbgl::Feature>();
+
+ extensionValue = self.mapView.renderer->queryFeatureExtensions(self.rawSource->getID(),
+ clusterFeature,
+ "supercluster",
+ extension,
+ options);
+
+ return extensionValue;
+}
+
+
+- (NSArray<id <MGLFeature>> *)leavesOfCluster:(MGLShape<MGLCluster> *)cluster offset:(NSUInteger)offset limit:(NSUInteger)limit {
+ const std::map<std::string, mbgl::Value> options = {
+ { "limit", static_cast<uint64_t>(limit) },
+ { "offset", static_cast<uint64_t>(offset) }
+ };
+
+ auto featureExtension = [self featureExtensionValueOfCluster:cluster extension:"leaves" options:options];
+
+ if (!featureExtension) {
return @[];
}
- MGLAssert(offset < UINT32_MAX, @"`offset` should be < `UINT32_MAX`");
- MGLAssert(limit < UINT32_MAX, @"`limit` should be < `UINT32_MAX`");
+ if (!featureExtension->is<mbgl::FeatureCollection>()) {
+ return @[];
+ }
- std::vector<mbgl::Feature> leaves = self.rawSource->getLeaves((uint32_t)cluster.clusterIdentifier, (uint32_t)limit, (uint32_t)offset);
+ std::vector<mbgl::Feature> leaves = featureExtension->get<mbgl::FeatureCollection>();
return MGLFeaturesFromMBGLFeatures(leaves);
}
-- (NSArray<id <MGLFeature>> *)childrenOfCluster:(id<MGLCluster>)cluster {
- if(!self.rawSource) {
+- (NSArray<id <MGLFeature>> *)childrenOfCluster:(MGLShape<MGLCluster> *)cluster {
+ auto featureExtension = [self featureExtensionValueOfCluster:cluster extension:"children" options:{}];
+
+ if (!featureExtension) {
return @[];
}
-
- std::vector<mbgl::Feature> children = self.rawSource->getChildren((uint32_t)cluster.clusterIdentifier);
- return MGLFeaturesFromMBGLFeatures(children);
+
+ if (!featureExtension->is<mbgl::FeatureCollection>()) {
+ return @[];
+ }
+
+ std::vector<mbgl::Feature> leaves = featureExtension->get<mbgl::FeatureCollection>();
+ return MGLFeaturesFromMBGLFeatures(leaves);
}
-- (double)zoomLevelForExpandingCluster:(id<MGLCluster>)cluster {
- if(!self.rawSource) {
+- (double)zoomLevelForExpandingCluster:(MGLShape<MGLCluster> *)cluster {
+ auto featureExtension = [self featureExtensionValueOfCluster:cluster extension:"expansion-zoom" options:{}];
+
+ if (!featureExtension) {
return -1.0;
}
-
- uint8_t zoom = self.rawSource->getClusterExpansionZoom((uint32_t)cluster.clusterIdentifier);
- return static_cast<double>(zoom);
+
+ if (!featureExtension->is<mbgl::Value>()) {
+ return -1.0;
+ }
+
+ auto value = featureExtension->get<mbgl::Value>();
+ if (value.is<uint64_t>()) {
+ auto zoom = value.get<uint64_t>();
+ return static_cast<double>(zoom);
+ }
+
+ return -1.0;
}
- (void)debugRecursiveLogForFeature:(id <MGLFeature>)feature indent:(NSUInteger)indent {
diff --git a/platform/darwin/src/MGLShapeSource_Private.h b/platform/darwin/src/MGLShapeSource_Private.h
index 4ed044c256..271aa2a9ee 100644
--- a/platform/darwin/src/MGLShapeSource_Private.h
+++ b/platform/darwin/src/MGLShapeSource_Private.h
@@ -25,7 +25,7 @@ mbgl::style::GeoJSONOptions MGLGeoJSONOptionsFromDictionary(NSDictionary<MGLShap
@param indent Used during recursion. Specify 0.
*/
-- (void)debugRecursiveLogForFeature:(id <MGLFeature>)feature indent:(NSUInteger)indent;
+- (void)debugRecursiveLogForFeature:(MGLShape<MGLFeature> *)feature indent:(NSUInteger)indent;
@end
NS_ASSUME_NONNULL_END
diff --git a/platform/darwin/test/MGLCodingTests.mm b/platform/darwin/test/MGLCodingTests.mm
index e8fd0ddf27..2060992457 100644
--- a/platform/darwin/test/MGLCodingTests.mm
+++ b/platform/darwin/test/MGLCodingTests.mm
@@ -53,7 +53,6 @@
@"cluster" : @(YES),
@"cluster_id" : @(456),
@"point_count" : @(2),
- @"point_count_abbreviated" : @"2"
};
XCTAssert([pointFeature isMemberOfClass:[MGLPointFeature class]], @"");
@@ -73,7 +72,6 @@
XCTAssert(cluster);
XCTAssert(cluster.clusterIdentifier == 456);
XCTAssert(cluster.clusterPointCount == 2);
- XCTAssertEqualObjects(cluster.clusterPointCountAbbreviation, @"2");
// Archiving shouldn't affect
[NSKeyedArchiver archiveRootObject:unarchivedPointFeature toFile:filePath];
diff --git a/platform/darwin/test/MGLDocumentationExampleTests.swift b/platform/darwin/test/MGLDocumentationExampleTests.swift
index e7420b2aa4..10308619d2 100644
--- a/platform/darwin/test/MGLDocumentationExampleTests.swift
+++ b/platform/darwin/test/MGLDocumentationExampleTests.swift
@@ -415,7 +415,6 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate {
"cluster" : true,
"cluster_id" : 123,
"point_count" : 4567,
- "point_count_abbreviated" : "4.5k"
]
]
@@ -434,8 +433,6 @@ class MGLDocumentationExampleTests: XCTestCase, MGLMapViewDelegate {
throw ExampleError.featureIsNotACluster
}
- print("Approximate number of points in cluster: \(cluster.clusterPointCountAbbreviation)")
-
//#-end-example-code
XCTAssert(cluster.clusterIdentifier == 123)
diff --git a/platform/darwin/test/MGLFeatureTests.mm b/platform/darwin/test/MGLFeatureTests.mm
index 0d6f4af29d..87f288f3ce 100644
--- a/platform/darwin/test/MGLFeatureTests.mm
+++ b/platform/darwin/test/MGLFeatureTests.mm
@@ -93,7 +93,6 @@
pointFeature.properties["cluster"] = true;
pointFeature.properties["cluster_id"] = 1ULL;
pointFeature.properties["point_count"] = 5ULL;
- pointFeature.properties["point_count_abbreviated"] = std::string("5");;
id<MGLFeature> feature = MGLFeatureFromMBGLFeature(pointFeature);
@@ -103,7 +102,6 @@
XCTAssert(cluster);
XCTAssert(cluster.clusterIdentifier == 1);
XCTAssert(cluster.clusterPointCount == 5);
- XCTAssertEqualObjects(cluster.clusterPointCountAbbreviation, @"5");
}
- (void)testPropertyConversion {