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

Added getSourceIds to the controller #197

Merged
merged 13 commits into from
Feb 27, 2023
Merged
19 changes: 19 additions & 0 deletions android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,25 @@ public void onFailure(@NonNull Exception exception) {
result.success(reply);
break;
}
case "style#getSourceIds":
{
if (style == null) {
result.error(
"STYLE IS NULL",
"The style is null. Has onStyleLoaded() already been invoked?",
null);
}
Map<String, Object> reply = new HashMap<>();

List<String> sourceIds = new ArrayList<>();
for (Source source : style.getSources()) {
sourceIds.add(source.getId());
}

reply.put("sources", sourceIds);
result.success(reply);
break;
}
default:
result.notImplemented();
}
Expand Down
11 changes: 11 additions & 0 deletions ios/Classes/MapboxMapController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,17 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
var reply = [String: NSObject]()
reply["layers"] = layerIds as NSObject
result(reply)

case "style#getSrouceIds":
mariusvn marked this conversation as resolved.
Show resolved Hide resolved
var sourceIds = [String]()

guard let style = mapView.style else { return }

style.sources.forEach { source in sourceIds.append(source.identifier) }

var reply = [String: NSObject]()
reply["sources"] = sourceIds as NSObject
result(reply)

case "style#getFilter":
guard let arguments = methodCall.arguments as? [String: Any] else { return }
Expand Down
6 changes: 6 additions & 0 deletions lib/src/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,12 @@ class MaplibreMapController extends ChangeNotifier {
return _mapboxGlPlatform.getLayerIds();
}

Future<List<String>> getSourceIds() async {
mariusvn marked this conversation as resolved.
Show resolved Hide resolved
return (await _mapboxGlPlatform.getSourceIds())
.whereType<String>()
.toList();
}

@override
void dispose() {
super.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ abstract class MapLibreGlPlatform {

Future<List> getLayerIds();

Future<List> getSourceIds();

Future<void> setFilter(String layerId, dynamic filter);

Future<dynamic> getFilter(String layerId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -753,4 +753,15 @@ class MethodChannelMaplibreGl extends MapLibreGlPlatform {
return new Future.error(e);
}
}

@override
Future<List> getSourceIds() async {
try {
final Map<dynamic, dynamic> reply =
await _channel.invokeMethod('style#getSourceIds');
return reply['sources'].map((it) => it.toString()).toList();
} on PlatformException catch (e) {
return new Future.error(e);
}
}
}
5 changes: 5 additions & 0 deletions maplibre_gl_web/lib/src/mapbox_web_gl_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1045,4 +1045,9 @@ class MaplibreMapController extends MapLibreGlPlatform
Future<List> getLayerIds() async {
throw UnimplementedError();
}

@override
Future<List> getSourceIds() async {
throw UnimplementedError();
}
}