Skip to content

Commit 47f0f0d

Browse files
committed
feat: basic cluster support
1 parent c366c50 commit 47f0f0d

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/mapbox.android.ts

+6
Original file line numberDiff line numberDiff line change
@@ -2429,6 +2429,12 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
24292429
if (options.maxzoom) {
24302430
geojsonOptions.withMaxZoom(options.maxzoom);
24312431
}
2432+
if (options.cluster) {
2433+
geojsonOptions
2434+
.withCluster(true)
2435+
.withClusterMaxZoom(options.cluster.maxZoom || 13)
2436+
.withClusterRadius(options.cluster.radius || 40);
2437+
}
24322438

24332439
const geoJsonSource = new com.mapbox.mapboxsdk.style.sources.GeoJsonSource(id, geojsonOptions);
24342440
if (options.data) {

src/mapbox.common.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,10 @@ export interface GeoJSONSource extends Source {
332332
data?: any;
333333
minzoom?: number;
334334
maxzoom?: number;
335+
cluster?: {
336+
radius;
337+
maxZoom;
338+
};
335339
}
336340

337341
// ------------------------------------------------------------
@@ -650,7 +654,7 @@ export interface MapboxApi {
650654

651655
setOnFlingListener(listener: () => void, nativeMap?: any): Promise<any>;
652656

653-
setOnCameraMoveListener(listener: (reason, animated?:boolean) => void, nativeMap?: any): Promise<any>;
657+
setOnCameraMoveListener(listener: (reason, animated?: boolean) => void, nativeMap?: any): Promise<any>;
654658

655659
setOnCameraMoveCancelListener(listener: () => void, nativeMap?: any): Promise<any>;
656660

@@ -769,7 +773,7 @@ export interface MapboxViewApi {
769773

770774
setOnFlingListener(listener: () => void): Promise<any>;
771775

772-
setOnCameraMoveListener(listener: (reason, animated?:boolean) => void): Promise<any>;
776+
setOnCameraMoveListener(listener: (reason, animated?: boolean) => void): Promise<any>;
773777

774778
setOnCameraMoveCancelListener(listener: () => void): Promise<any>;
775779

@@ -904,7 +908,7 @@ export abstract class MapboxViewCommonBase extends ContentView implements Mapbox
904908
setOnFlingListener(listener: () => void, nativeMap?: any): Promise<any> {
905909
return this.mapbox.setOnFlingListener(listener, this.getNativeMapView());
906910
}
907-
setOnCameraMoveListener(listener: (reason, animated?:boolean) => void, nativeMap?: any): Promise<any> {
911+
setOnCameraMoveListener(listener: (reason, animated?: boolean) => void, nativeMap?: any): Promise<any> {
908912
return this.mapbox.setOnCameraMoveListener(listener, this.getNativeMapView());
909913
}
910914
setOnCameraMoveCancelListener(listener: () => void, nativeMap?: any): Promise<any> {

src/mapbox.ios.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -2225,6 +2225,12 @@ export class Mapbox extends MapboxCommon implements MapboxApi {
22252225
sourceOptions[MGLShapeSourceOptionMaximumZoomLevel] = options.maxzoom;
22262226
}
22272227

2228+
if (options.cluster) {
2229+
sourceOptions[MGLShapeSourceOptionClustered] = true;
2230+
sourceOptions[MGLShapeSourceOptionClusterRadius] = options.cluster.radius || 40;
2231+
sourceOptions[MGLShapeSourceOptionMaximumZoomLevelForClustering] = options.cluster.maxZoom || 13;
2232+
}
2233+
22282234
source = MGLShapeSource.alloc().initWithIdentifierShapeOptions(id, geoJsonShape, sourceOptions);
22292235

22302236
break;
@@ -2659,7 +2665,7 @@ class MGLMapViewDelegateImpl extends NSObject implements MGLMapViewDelegate {
26592665

26602666
private userLocationClickListener: (annotation: MGLAnnotation) => void;
26612667
private userLocationChangedListener: (location: UserLocation) => void;
2662-
private cameraChangedListener: (reason,animated?:boolean) => void;
2668+
private cameraChangedListener: (reason, animated?: boolean) => void;
26632669
private cameraIdledListener: () => void;
26642670
private userLocationRenderMode: any;
26652671
private userLocationAnnotationView: CustomUserLocationAnnotationView;

0 commit comments

Comments
 (0)