Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement cluster query features on GeoJsonSource #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/src/interop/style/sources/geojson_source_interop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,13 @@ class GeoJsonSourceJsImpl {

external GeoJsonSourceJsImpl setData(
FeatureCollectionJsImpl featureCollection);

external GeoJsonSourceJsImpl getClusterChildren(
int clusterId, Function(dynamic, [List<dynamic>?]) callback);

external GeoJsonSourceJsImpl getClusterLeaves(int clusterId, int limit,
int offset, Function(dynamic, [List<dynamic>?]) callback);

external GeoJsonSourceJsImpl getClusterExpansionZoom(
int clusterId, Function(dynamic, [int?]) callback);
}
40 changes: 40 additions & 0 deletions lib/src/style/sources/geojson_source.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -20,6 +21,45 @@ class GeoJsonSource extends Source<GeoJsonSourceJsImpl> {
GeoJsonSource setData(FeatureCollection featureCollection) =>
GeoJsonSource.fromJsObject(jsObject.setData(featureCollection.jsObject));

GeoJsonSource getClusterChildren(
int clusterId, Function(dynamic, List<Feature>?) 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<Feature>?) 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);
Expand Down