Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - add convenience method for destroyed state on MapView, ca…
Browse files Browse the repository at this point in the history
…n be used to determine if an asynchrous result should be set on map.
  • Loading branch information
tobrun committed Jul 12, 2018
1 parent b79b971 commit e16c964
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,19 @@ public void onDestroy() {
}
}

/**
* Returns if the map has been destroyed.
* <p>
* This method can be used to determine if the result of an asynchronous operation should be set.
* </p>
*
* @return true, if the map has been destroyed
*/
@UiThread
public boolean isDestroyed() {
return destroyed;
}

@Override
public boolean onTouchEvent(MotionEvent event) {
if (!isMapInitialized() || !isZoomButtonControllerInitialized() || !isGestureDetectorInitialized()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private void onLatLngListLoaded(List<LatLng> latLngs, int amount) {
}

private void showMarkers(int amount) {
if (mapboxMap == null || locations == null) {
if (mapboxMap == null || locations == null || mapView.isDestroyed()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.mapbox.geojson.Feature;
import com.mapbox.geojson.FeatureCollection;
import com.mapbox.mapboxsdk.maps.MapView;
Expand All @@ -26,14 +25,13 @@
import com.mapbox.mapboxsdk.style.sources.Source;
import com.mapbox.mapboxsdk.testapp.R;
import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils;
import timber.log.Timber;

import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.List;

import timber.log.Timber;

import static com.mapbox.mapboxsdk.style.expressions.Expression.concat;
import static com.mapbox.mapboxsdk.style.expressions.Expression.division;
import static com.mapbox.mapboxsdk.style.expressions.Expression.downcase;
Expand Down Expand Up @@ -240,6 +238,10 @@ protected void onPostExecute(FeatureCollection featureCollection) {
}

public void onDataLoaded(@NonNull FeatureCollection featureCollection) {
if (mapView.isDestroyed()) {
return;
}

// create expressions
Expression iconImageExpression = string(get(literal(FEATURE_ID)));
Expression iconSizeExpression = division(number(get(literal(FEATURE_RANK))), literal(2.0f));
Expand Down

0 comments on commit e16c964

Please sign in to comment.