Skip to content

Commit f280ac3

Browse files
Fix
1 parent 5f55076 commit f280ac3

8 files changed

Lines changed: 35 additions & 16 deletions

File tree

android/rctmgl/src/main/java/com/mapbox/rctmgl/components/styles/sources/RCTMGLShapeSource.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,28 @@ public void querySourceFeatures(String callbackID,
172172
mManager.handleEvent(event);
173173
}
174174

175-
public void getClusterExpansionZoom(String callbackID, String clusterId) {
175+
public void getClusterExpansionZoom(String callbackID, int clusterId) {
176176
if (mSource == null) {
177177
WritableMap payload = new WritableNativeMap();
178178
payload.putString("error", "source is not yet loaded");
179179
AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
180180
mManager.handleEvent(event);
181181
return;
182182
}
183-
List<Feature> features = mSource.querySourceFeatures(Expression.eq(Expression.get("id"), clusterId));
184-
int zoom = mSource.getClusterExpansionZoom(features.get(0));
183+
List<Feature> features = mSource.querySourceFeatures(Expression.eq(Expression.id(), clusterId));
184+
int zoom = -1;
185+
if (features.size() > 0) {
186+
zoom = mSource.getClusterExpansionZoom(features.get(0));
187+
}
188+
189+
if (zoom == -1) {
190+
WritableMap payload = new WritableNativeMap();
191+
payload.putString("error", "Could not get zoom for cluster id " + clusterId);
192+
AndroidCallbackEvent event = new AndroidCallbackEvent(this, callbackID, payload);
193+
mManager.handleEvent(event);
194+
return;
195+
}
196+
185197
WritableMap payload = new WritableNativeMap();
186198
payload.putInt("data", zoom);
187199

android/rctmgl/src/main/java/com/mapbox/rctmgl/components/styles/sources/RCTMGLShapeSourceManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public void receiveCommand(RCTMGLShapeSource source, int commandID, @Nullable Re
169169
);
170170
break;
171171
case METHOD_GET_CLUSTER_EXPANSION_ZOOM:
172-
source.getClusterExpansionZoom(args.getString(0), args.getString(1));
172+
source.getClusterExpansionZoom(args.getString(0), args.getInt(1));
173173
break;
174174
}
175175
}

docs/ShapeSource.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ shapeSource.features()
3838

3939
#### getClusterExpansionZoom(clusterId)
4040

41-
Returns the zoom needed to expand the cluster. If the request fails -1 will be<br/>returned.
41+
Returns the zoom needed to expand the cluster.
4242

4343
##### arguments
4444
| Name | Type | Required | Description |
4545
| ---- | :--: | :------: | :----------: |
46-
| `clusterId` | `string` | `Yes` | The id of the cluster to expand. |
46+
| `clusterId` | `number` | `Yes` | The id of the cluster to expand. |
4747

4848

4949

docs/docs.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3575,7 +3575,7 @@
35753575
},
35763576
{
35773577
"name": "getClusterExpansionZoom",
3578-
"docblock": "Returns the zoom needed to expand the cluster. If the request fails -1 will be\nreturned.\n\n@example\nconst zoom = await shapeSource.getClusterExpansionZoom(clusterId);\n\n@param {string} clusterId - The id of the cluster to expand.\n@return {number}",
3578+
"docblock": "Returns the zoom needed to expand the cluster.\n\n@example\nconst zoom = await shapeSource.getClusterExpansionZoom(clusterId);\n\n@param {number} clusterId - The id of the cluster to expand.\n@return {number}",
35793579
"modifiers": [
35803580
"async"
35813581
],
@@ -3584,7 +3584,7 @@
35843584
"name": "clusterId",
35853585
"description": "The id of the cluster to expand.",
35863586
"type": {
3587-
"name": "string"
3587+
"name": "number"
35883588
},
35893589
"optional": false
35903590
}
@@ -3595,7 +3595,7 @@
35953595
"name": "number"
35963596
}
35973597
},
3598-
"description": "Returns the zoom needed to expand the cluster. If the request fails -1 will be\nreturned.",
3598+
"description": "Returns the zoom needed to expand the cluster.",
35993599
"examples": [
36003600
"\nconst zoom = await shapeSource.getClusterExpansionZoom(clusterId);\n\n"
36013601
]

ios/RCTMGL/RCTMGLShapeSource.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131

3232
- (nonnull NSArray<id <MGLFeature>> *)featuresMatchingPredicate:(nullable NSPredicate *)predicate;
3333

34-
- (double)getClusterExpansionZoom:(NSString *)clusterId;
34+
- (double)getClusterExpansionZoom:(nonnull NSNumber *)clusterId;
3535

3636
@end

ios/RCTMGL/RCTMGLShapeSource.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,14 @@ - (nullable MGLSource*)makeSource
104104
return [shapeSource featuresMatchingPredicate:predicate];
105105
}
106106

107-
- (double)getClusterExpansionZoom:(NSString *)clusterId
107+
- (double)getClusterExpansionZoom:(nonnull NSNumber *)clusterId
108108
{
109109
MGLShapeSource *shapeSource = (MGLShapeSource *)self.source;
110-
NSArray<id<MGLFeature>> *features = [shapeSource featuresMatchingPredicate: [NSPredicate predicateWithFormat:@"id = %@", clusterId]];
110+
NSArray<id<MGLFeature>> *features = [shapeSource featuresMatchingPredicate: [NSPredicate predicateWithFormat:@"id == %i", clusterId.intValue]];
111+
112+
if (features.count == 0) {
113+
return -1;
114+
}
111115
return [shapeSource zoomLevelForExpandingCluster:(MGLPointFeatureCluster *)features[0]];
112116
}
113117

ios/RCTMGL/RCTMGLShapeSourceManager.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ - (UIView*)view
6767
}
6868

6969
RCT_EXPORT_METHOD(getClusterExpansionZoom:(nonnull NSNumber*)reactTag
70-
clusterId:(NSString *)clusterId
70+
clusterId:(nonnull NSNumber*)clusterId
7171
resolver:(RCTPromiseResolveBlock)resolve
7272
rejecter:(RCTPromiseRejectBlock)reject)
7373
{
@@ -80,6 +80,10 @@ - (UIView*)view
8080
}
8181

8282
double zoom = [shapeSource getClusterExpansionZoom:clusterId];
83+
if (zoom == -1) {
84+
reject(@"zoom_error", [NSString stringWithFormat:@"Could not get zoom for cluster id %@", clusterId], nil);
85+
return;
86+
}
8387
resolve(@{@"data":@(zoom)});
8488
}];
8589
}

javascript/components/ShapeSource.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,12 @@ class ShapeSource extends NativeBridgeComponent(AbstractSource) {
148148
}
149149

150150
/**
151-
* Returns the zoom needed to expand the cluster. If the request fails -1 will be
152-
* returned.
151+
* Returns the zoom needed to expand the cluster.
153152
*
154153
* @example
155154
* const zoom = await shapeSource.getClusterExpansionZoom(clusterId);
156155
*
157-
* @param {string} clusterId - The id of the cluster to expand.
156+
* @param {number} clusterId - The id of the cluster to expand.
158157
* @return {number}
159158
*/
160159
async getClusterExpansionZoom(clusterId) {

0 commit comments

Comments
 (0)