From 264f9947b878fa86ef05fcce6437f5be9ab11987 Mon Sep 17 00:00:00 2001 From: Levente Morva Date: Thu, 21 Apr 2022 13:30:45 +0200 Subject: [PATCH] implement cluster query features on GeoJsonSource --- .../style/sources/geojson_source_interop.dart | 9 +++++ lib/src/style/sources/geojson_source.dart | 40 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/lib/src/interop/style/sources/geojson_source_interop.dart b/lib/src/interop/style/sources/geojson_source_interop.dart index 5340e82..65ee326 100644 --- a/lib/src/interop/style/sources/geojson_source_interop.dart +++ b/lib/src/interop/style/sources/geojson_source_interop.dart @@ -17,4 +17,13 @@ class GeoJsonSourceJsImpl { external GeoJsonSourceJsImpl setData( FeatureCollectionJsImpl featureCollection); + + external GeoJsonSourceJsImpl getClusterChildren( + int clusterId, Function(dynamic, [List?]) callback); + + external GeoJsonSourceJsImpl getClusterLeaves(int clusterId, int limit, + int offset, Function(dynamic, [List?]) callback); + + external GeoJsonSourceJsImpl getClusterExpansionZoom( + int clusterId, Function(dynamic, [int?]) callback); } diff --git a/lib/src/style/sources/geojson_source.dart b/lib/src/style/sources/geojson_source.dart index 8725b3b..fea1ebc 100644 --- a/lib/src/style/sources/geojson_source.dart +++ b/lib/src/style/sources/geojson_source.dart @@ -1,5 +1,6 @@ library mapboxgl.style.sources.geojson_source; +import 'package:js/js.dart'; import 'package:mapbox_gl_dart/mapbox_gl_dart.dart'; import 'package:mapbox_gl_dart/src/interop/interop.dart'; @@ -20,6 +21,45 @@ class GeoJsonSource extends Source { GeoJsonSource setData(FeatureCollection featureCollection) => GeoJsonSource.fromJsObject(jsObject.setData(featureCollection.jsObject)); + GeoJsonSource getClusterChildren( + int clusterId, Function(dynamic, List?) callback) => + GeoJsonSource.fromJsObject( + jsObject.getClusterChildren( + clusterId, + allowInterop((error, [children]) { + callback( + error, + children?.map((child) => Feature.fromJsObject(child)).toList(), + ); + }), + ), + ); + + GeoJsonSource getClusterLeaves(int clusterId, int limit, int offset, + Function(dynamic, List?) callback) => + GeoJsonSource.fromJsObject( + jsObject.getClusterLeaves( + clusterId, + limit, + offset, + allowInterop((error, [leaves]) { + callback( + error, + leaves?.map((leaf) => Feature.fromJsObject(leaf)).toList(), + ); + }), + ), + ); + + GeoJsonSource getClusterExpansionZoom( + int clusterId, Function(dynamic, int?) callback) => + GeoJsonSource.fromJsObject( + jsObject.getClusterExpansionZoom( + clusterId, + allowInterop((error, [level]) => callback(error, level)), + ), + ); + /// Creates a new GeoJsonSource from a [jsObject]. GeoJsonSource.fromJsObject(GeoJsonSourceJsImpl jsObject) : super.fromJsObject(jsObject);