Skip to content
Merged
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
6 changes: 6 additions & 0 deletions ios/Classes/MapboxMapController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,12 @@ class MapboxMapController: NSObject, FlutterPlatformView, MGLMapViewDelegate, Ma
}
}

func mapViewDidBecomeIdle(_ mapView: MGLMapView) {
if let channel = channel {
channel.invokeMethod("map#onIdle", arguments: []);
}
}

func mapView(_ mapView: MGLMapView, regionWillChangeAnimated animated: Bool) {
if let channel = channel {
channel.invokeMethod("camera#onMoveStarted", arguments: []);
Expand Down
18 changes: 15 additions & 3 deletions lib/src/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ typedef void OnStyleLoadedCallback();
typedef void OnCameraTrackingDismissedCallback();
typedef void OnCameraTrackingChangedCallback(MyLocationTrackingMode mode);

typedef void OnMapIdleCallback();

/// Controller for a single MapboxMap instance running on the host platform.
///
/// Change listeners are notified upon changes to any of
Expand All @@ -32,7 +34,8 @@ class MapboxMapController extends ChangeNotifier {
{this.onStyleLoadedCallback,
this.onMapClick,
this.onCameraTrackingDismissed,
this.onCameraTrackingChanged})
this.onCameraTrackingChanged,
this.onMapIdle})
: assert(_id != null),
assert(channel != null),
_channel = channel {
Expand All @@ -45,7 +48,8 @@ class MapboxMapController extends ChangeNotifier {
{OnStyleLoadedCallback onStyleLoadedCallback,
OnMapClickCallback onMapClick,
OnCameraTrackingDismissedCallback onCameraTrackingDismissed,
OnCameraTrackingChangedCallback onCameraTrackingChanged}) async {
OnCameraTrackingChangedCallback onCameraTrackingChanged,
OnMapIdleCallback onMapIdle}) async {
assert(id != null);
final MethodChannel channel =
MethodChannel('plugins.flutter.io/mapbox_maps_$id');
Expand All @@ -54,7 +58,8 @@ class MapboxMapController extends ChangeNotifier {
onStyleLoadedCallback: onStyleLoadedCallback,
onMapClick: onMapClick,
onCameraTrackingDismissed: onCameraTrackingDismissed,
onCameraTrackingChanged: onCameraTrackingChanged);
onCameraTrackingChanged: onCameraTrackingChanged,
onMapIdle: onMapIdle);
}

final MethodChannel _channel;
Expand All @@ -66,6 +71,8 @@ class MapboxMapController extends ChangeNotifier {
final OnCameraTrackingDismissedCallback onCameraTrackingDismissed;
final OnCameraTrackingChangedCallback onCameraTrackingChanged;

final OnMapIdleCallback onMapIdle;

/// Callbacks to receive tap events for symbols placed on this map.
final ArgumentCallbacks<Symbol> onSymbolTapped = ArgumentCallbacks<Symbol>();

Expand Down Expand Up @@ -175,6 +182,11 @@ class MapboxMapController extends ChangeNotifier {
onCameraTrackingDismissed();
}
break;
case 'map#onIdle':
if (onMapIdle != null) {
onMapIdle();
}
break;
default:
throw MissingPluginException();
}
Expand Down
12 changes: 11 additions & 1 deletion lib/src/mapbox_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class MapboxMap extends StatefulWidget {
this.onMapClick,
this.onCameraTrackingDismissed,
this.onCameraTrackingChanged,
this.onMapIdle,
}) : assert(initialCameraPosition != null);

final MapCreatedCallback onMapCreated;
Expand Down Expand Up @@ -130,6 +131,14 @@ class MapboxMap extends StatefulWidget {
final OnCameraTrackingDismissedCallback onCameraTrackingDismissed;
final OnCameraTrackingChangedCallback onCameraTrackingChanged;

/// Called when map view is entering an idle state, and no more drawing will
/// be necessary until new data is loaded or there is some interaction with
/// the map.
/// * No camera transitions are in progress
/// * All currently requested tiles have loaded
/// * All fade/transition animations have completed
final OnMapIdleCallback onMapIdle;

@override
State createState() => _MapboxMapState();
}
Expand Down Expand Up @@ -198,7 +207,8 @@ class _MapboxMapState extends State<MapboxMap> {
onStyleLoadedCallback: widget.onStyleLoadedCallback,
onMapClick: widget.onMapClick,
onCameraTrackingDismissed: widget.onCameraTrackingDismissed,
onCameraTrackingChanged: widget.onCameraTrackingChanged);
onCameraTrackingChanged: widget.onCameraTrackingChanged,
onMapIdle: widget.onMapIdle);
_controller.complete(controller);
if (widget.onMapCreated != null) {
widget.onMapCreated(controller);
Expand Down