Do not take snapshot if map is stopped. (#390)

This commit is contained in:
Kevin Li
2020-05-26 15:53:09 +08:00
committed by GitHub
parent 66a6c0cea7
commit f73822d336
2 changed files with 11 additions and 2 deletions

View File

@@ -81,6 +81,7 @@ public final class MapboxMap {
private Style style; private Style style;
private boolean debugActive; private boolean debugActive;
private boolean started;
MapboxMap(NativeMap map, Transform transform, UiSettings ui, Projection projection, MapboxMap(NativeMap map, Transform transform, UiSettings ui, Projection projection,
OnGesturesManagerInteractionListener listener, CameraChangeDispatcher cameraChangeDispatcher, OnGesturesManagerInteractionListener listener, CameraChangeDispatcher cameraChangeDispatcher,
@@ -143,6 +144,7 @@ public final class MapboxMap {
* Called when the hosting Activity/Fragment onStart() method is called. * Called when the hosting Activity/Fragment onStart() method is called.
*/ */
void onStart() { void onStart() {
started = true;
locationComponent.onStart(); locationComponent.onStart();
} }
@@ -150,6 +152,7 @@ public final class MapboxMap {
* Called when the hosting Activity/Fragment onStop() method is called. * Called when the hosting Activity/Fragment onStop() method is called.
*/ */
void onStop() { void onStop() {
started = false;
locationComponent.onStop(); locationComponent.onStop();
} }
@@ -2003,6 +2006,9 @@ public final class MapboxMap {
* @param callback Callback method invoked when the snapshot is taken. * @param callback Callback method invoked when the snapshot is taken.
*/ */
public void snapshot(@NonNull SnapshotReadyCallback callback) { public void snapshot(@NonNull SnapshotReadyCallback callback) {
if (!started) {
return;
}
nativeMapView.addSnapshotCallback(callback); nativeMapView.addSnapshotCallback(callback);
} }

View File

@@ -6,7 +6,6 @@ import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.TextView import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView
import com.mapbox.mapboxsdk.maps.MapView import com.mapbox.mapboxsdk.maps.MapView
import com.mapbox.mapboxsdk.maps.Style import com.mapbox.mapboxsdk.maps.Style
import com.mapbox.mapboxsdk.testapp.R import com.mapbox.mapboxsdk.testapp.R
@@ -141,7 +140,11 @@ open class GLSurfaceRecyclerViewActivity : AppCompatActivity() {
} }
fun bind(mapItem: MapItem) { fun bind(mapItem: MapItem) {
mapView.getMapAsync { mapboxMap -> mapboxMap.setStyle(mapItem.style) } mapView.getMapAsync { mapboxMap ->
mapboxMap.setStyle(mapItem.style) {
mapboxMap.snapshot { }
}
}
} }
} }