From 6373b91e0da9798070a45f3a32cf00718d85fc4f Mon Sep 17 00:00:00 2001 From: Nathan Hamblen Date: Sat, 30 Oct 2021 11:01:18 -0400 Subject: [PATCH] Enable `onMapIdle` callback for android This is the android piece of PR #214. The listener `MapView.OnDidBecomeIdleListener` is less well documented than its iOS counterpart. We just have this to go on: > Interface definition for a callback to be invoked when the map has > entered the idle state. https://docs.mapbox.com/android/maps/api/9.6.1/com/mapbox/mapboxsdk/maps/MapView.OnDidBecomeIdleListener.html Fr the iOS framework method we have more detailed information: > Tells the delegate that the 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 https://docs.mapbox.com/archive/ios/maps/api/5.6.1/Protocols/MGLMapViewDelegate.html#/c:objc(pl)MGLMapViewDelegate(im)mapViewDidBecomeIdle: After testing with these changes, it does seem to be the case that it is only invoked after the tiles are loaded. So I think this is the correct analogue for the iOS listener. --- .../java/com/mapbox/mapboxgl/MapboxMapController.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java b/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java index 9a97c48ff..9d9921ca1 100644 --- a/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java +++ b/android/src/main/java/com/mapbox/mapboxgl/MapboxMapController.java @@ -94,6 +94,7 @@ final class MapboxMapController MapboxMap.OnCameraIdleListener, MapboxMap.OnCameraMoveListener, MapboxMap.OnCameraMoveStartedListener, + MapView.OnDidBecomeIdleListener, OnAnnotationClickListener, MapboxMap.OnMapClickListener, MapboxMap.OnMapLongClickListener, @@ -270,6 +271,8 @@ public void onMapReady(MapboxMap mapboxMap) { } }); + mapView.addOnDidBecomeIdleListener(this); + setStyleString(styleStringInitial); // updateMyLocationEnabled(); } @@ -1027,6 +1030,11 @@ public void onCameraTrackingDismissed() { methodChannel.invokeMethod("map#onCameraTrackingDismissed", new HashMap<>()); } + @Override + public void onDidBecomeIdle() { + methodChannel.invokeMethod("map#onIdle", new HashMap<>()); + } + @Override public boolean onAnnotationClick(Annotation annotation) { if (annotation instanceof Symbol) {