[android] - remove style loaded listener
This commit is contained in:
@@ -168,7 +168,7 @@ public class MapView extends FrameLayout implements NativeMapView.ViewCallback {
|
||||
|
||||
// MapboxMap
|
||||
mapboxMap = new MapboxMap(nativeMapView, transform, uiSettings, proj, registerTouchListener,
|
||||
annotationManager, cameraChangeDispatcher, mapChangeReceiver);
|
||||
annotationManager, cameraChangeDispatcher);
|
||||
|
||||
// user input
|
||||
mapGestureDetector = new MapGestureDetector(context, transform, proj, uiSettings,
|
||||
|
||||
@@ -61,7 +61,6 @@ public final class MapboxMap {
|
||||
private final Transform transform;
|
||||
private final AnnotationManager annotationManager;
|
||||
private final CameraChangeDispatcher cameraChangeDispatcher;
|
||||
private final MapChangeReceiver mapChangeReceiver;
|
||||
|
||||
private final OnGesturesManagerInteractionListener onGesturesManagerInteractionListener;
|
||||
|
||||
@@ -73,7 +72,7 @@ public final class MapboxMap {
|
||||
|
||||
MapboxMap(NativeMapView map, Transform transform, UiSettings ui, Projection projection,
|
||||
OnGesturesManagerInteractionListener listener, AnnotationManager annotations,
|
||||
CameraChangeDispatcher cameraChangeDispatcher, MapChangeReceiver mapChangeReceiver) {
|
||||
CameraChangeDispatcher cameraChangeDispatcher) {
|
||||
this.nativeMapView = map;
|
||||
this.style = new Style(nativeMapView);
|
||||
this.uiSettings = ui;
|
||||
@@ -82,7 +81,6 @@ public final class MapboxMap {
|
||||
this.transform = transform;
|
||||
this.onGesturesManagerInteractionListener = listener;
|
||||
this.cameraChangeDispatcher = cameraChangeDispatcher;
|
||||
this.mapChangeReceiver = mapChangeReceiver;
|
||||
}
|
||||
|
||||
void initialise(@NonNull Context context, @NonNull MapboxMapOptions options) {
|
||||
@@ -702,7 +700,7 @@ public final class MapboxMap {
|
||||
* <p>
|
||||
* This method is asynchronous and will return before the style finishes loading.
|
||||
* If you wish to wait for the map to finish loading, listen to the {@link MapView.OnDidFinishLoadingStyleListener}
|
||||
* callback or use the {@link #setStyleUrl(String, OnStyleLoadedListener)} method instead.
|
||||
* callback.
|
||||
* </p>
|
||||
* If the style fails to load or an invalid style URL is set, the map view will become blank.
|
||||
* An error message will be logged in the Android logcat and {@link MapView.OnDidFailLoadingMapListener} callback
|
||||
@@ -712,47 +710,6 @@ public final class MapboxMap {
|
||||
* @see Style
|
||||
*/
|
||||
public void setStyleUrl(@NonNull String url) {
|
||||
setStyleUrl(url, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Loads a new map style asynchronous from the specified URL.
|
||||
* </p>
|
||||
* {@code url} can take the following forms:
|
||||
* <ul>
|
||||
* <li>{@code Style.*}: load one of the bundled styles in {@link Style}.</li>
|
||||
* <li>{@code mapbox://styles/<user>/<style>}:
|
||||
* loads the style from a <a href="https://www.mapbox.com/account/">Mapbox account.</a>
|
||||
* {@code user} is your username. {@code style} is the ID of your custom
|
||||
* style created in <a href="https://www.mapbox.com/studio">Mapbox Studio</a>.</li>
|
||||
* <li>{@code http://...} or {@code https://...}:
|
||||
* loads the style over the Internet from any web server.</li>
|
||||
* <li>{@code asset://...}:
|
||||
* loads the style from the APK {@code assets/} directory.
|
||||
* This is used to load a style bundled with your app.</li>
|
||||
* <li>{@code null}: loads the default {@link Style#MAPBOX_STREETS} style.</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* If the style fails to load or an invalid style URL is set, the map view will become blank.
|
||||
* An error message will be logged in the Android logcat and {@link MapView.OnDidFailLoadingMapListener} callback
|
||||
* will be triggered.
|
||||
* <p>
|
||||
*
|
||||
* @param url The URL of the map style
|
||||
* @param callback The callback that is invoked when the style has loaded.
|
||||
* @see Style
|
||||
*/
|
||||
public void setStyleUrl(@NonNull final String url, @Nullable final OnStyleLoadedListener callback) {
|
||||
if (callback != null) {
|
||||
mapChangeReceiver.addOnDidFinishLoadingStyleListener(new MapView.OnDidFinishLoadingStyleListener() {
|
||||
@Override
|
||||
public void onDidFinishLoadingStyle() {
|
||||
callback.onStyleLoaded(url);
|
||||
mapChangeReceiver.removeOnDidFinishLoadingStyleListener(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
nativeMapView.setStyleUrl(url);
|
||||
}
|
||||
|
||||
@@ -763,7 +720,7 @@ public final class MapboxMap {
|
||||
* <p>
|
||||
* This method is asynchronous and will return before the style finishes loading.
|
||||
* If you wish to wait for the map to finish loading, listen to the {@link MapView.OnDidFinishLoadingStyleListener}
|
||||
* callback or use the {@link #setStyle(String, OnStyleLoadedListener)} method instead.
|
||||
* callback.
|
||||
* </p>
|
||||
* If the style fails to load or an invalid style URL is set, the map view will become blank.
|
||||
* An error message will be logged in the Android logcat and {@link MapView.OnDidFailLoadingMapListener} callback
|
||||
@@ -776,22 +733,6 @@ public final class MapboxMap {
|
||||
setStyleUrl(style);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Loads a new map style from the specified bundled style.
|
||||
* </p>
|
||||
* If the style fails to load or an invalid style URL is set, the map view will become blank.
|
||||
* An error message will be logged in the Android logcat and {@link MapView.OnDidFailLoadingMapListener} callback
|
||||
* will be triggered.
|
||||
*
|
||||
* @param style The bundled style.
|
||||
* @param callback The callback to be invoked when the style has finished loading
|
||||
* @see Style
|
||||
*/
|
||||
public void setStyle(@NonNull @Style.StyleUrl String style, @Nullable OnStyleLoadedListener callback) {
|
||||
setStyleUrl(style, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a new map style from MapboxMapOptions if available.
|
||||
*
|
||||
@@ -800,7 +741,7 @@ public final class MapboxMap {
|
||||
private void setStyleUrl(@NonNull MapboxMapOptions options) {
|
||||
String style = options.getStyleUrl();
|
||||
if (!TextUtils.isEmpty(style)) {
|
||||
setStyleUrl(style, null);
|
||||
setStyleUrl(style);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2178,18 +2119,6 @@ public final class MapboxMap {
|
||||
void onSnapshotReady(@NonNull Bitmap snapshot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface definition for a callback to be invoked when the style has finished loading.
|
||||
*/
|
||||
public interface OnStyleLoadedListener {
|
||||
/**
|
||||
* Invoked when the style has finished loading
|
||||
*
|
||||
* @param style the style that has been loaded
|
||||
*/
|
||||
void onStyleLoaded(@NonNull String style);
|
||||
}
|
||||
|
||||
//
|
||||
// Used for instrumentation testing
|
||||
//
|
||||
|
||||
@@ -15,7 +15,7 @@ import com.mapbox.mapboxsdk.style.layers.Property
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
|
||||
|
||||
fun MapboxMap.querySourceFeatures(sourceId: String): List<Feature> {
|
||||
return this.getSourceAs<GeoJsonSource>(sourceId)?.querySourceFeatures(null) ?: emptyList()
|
||||
return this.style.getSourceAs<GeoJsonSource>(sourceId)?.querySourceFeatures(null) ?: emptyList()
|
||||
}
|
||||
|
||||
fun MapboxMap.queryRenderedFeatures(location: Location, layerId: String): List<Feature> {
|
||||
@@ -25,7 +25,7 @@ fun MapboxMap.queryRenderedFeatures(location: Location, layerId: String): List<F
|
||||
}
|
||||
|
||||
fun MapboxMap.isLayerVisible(layerId: String): Boolean {
|
||||
return this.getLayer(layerId)?.visibility?.value?.equals(Property.VISIBLE)!!
|
||||
return this.style.getLayer(layerId)?.visibility?.value?.equals(Property.VISIBLE)!!
|
||||
}
|
||||
|
||||
fun MapboxMap.waitForSource(uiController: UiController, sourceId: String) {
|
||||
|
||||
@@ -25,7 +25,7 @@ public class MaxMinZoomActivity extends AppCompatActivity implements OnMapReadyC
|
||||
@Override
|
||||
public boolean onMapClick(@NonNull LatLng point) {
|
||||
if (mapboxMap != null) {
|
||||
mapboxMap.setStyle(Style.OUTDOORS, style -> Timber.d("Style Loaded %s", style));
|
||||
mapboxMap.setStyle(Style.OUTDOORS);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -39,6 +39,10 @@ public class MaxMinZoomActivity extends AppCompatActivity implements OnMapReadyC
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(this);
|
||||
|
||||
mapView.addOnDidFinishLoadingStyleListener(() -> {
|
||||
Timber.d("Style Loaded");
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -93,6 +93,7 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa
|
||||
mapView.setStyleUrl(STYLES[currentStyleIndex]);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(this);
|
||||
mapView.addOnDidFinishLoadingStyleListener(() -> Timber.d("Style loaded"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -160,7 +161,7 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa
|
||||
if (currentStyleIndex == STYLES.length) {
|
||||
currentStyleIndex = 0;
|
||||
}
|
||||
mapboxMap.setStyleUrl(STYLES[currentStyleIndex], style -> Timber.d("Style loaded %s", style));
|
||||
mapboxMap.setStyleUrl(STYLES[currentStyleIndex]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -79,6 +79,14 @@ public class CircleLayerActivity extends AppCompatActivity implements View.OnCli
|
||||
initFloatingActionButtons();
|
||||
isLoadingStyle = false;
|
||||
});
|
||||
|
||||
mapView.addOnDidFinishLoadingStyleListener(new MapView.OnDidFinishLoadingStyleListener() {
|
||||
@Override
|
||||
public void onDidFinishLoadingStyle() {
|
||||
addBusStop();
|
||||
isLoadingStyle = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void addBusStopSource() {
|
||||
@@ -211,10 +219,7 @@ public class CircleLayerActivity extends AppCompatActivity implements View.OnCli
|
||||
}
|
||||
|
||||
private void loadNewStyle() {
|
||||
mapboxMap.setStyleUrl(getNextStyle(), style -> {
|
||||
addBusStop();
|
||||
isLoadingStyle = false;
|
||||
});
|
||||
mapboxMap.setStyleUrl(getNextStyle());
|
||||
}
|
||||
|
||||
private void addBusStop() {
|
||||
|
||||
@@ -152,6 +152,8 @@ public class TextureViewDebugModeActivity extends AppCompatActivity implements O
|
||||
}
|
||||
|
||||
private void setupStyleChangeView() {
|
||||
mapView.addOnDidFinishLoadingStyleListener(() -> Timber.d("Style loaded"));
|
||||
|
||||
FloatingActionButton fabStyles = findViewById(R.id.fabStyles);
|
||||
fabStyles.setOnClickListener(view -> {
|
||||
if (mapboxMap != null) {
|
||||
@@ -159,7 +161,7 @@ public class TextureViewDebugModeActivity extends AppCompatActivity implements O
|
||||
if (currentStyleIndex == STYLES.length) {
|
||||
currentStyleIndex = 0;
|
||||
}
|
||||
mapboxMap.setStyleUrl(STYLES[currentStyleIndex], style -> Timber.d("Style loaded %s", style));
|
||||
mapboxMap.setStyleUrl(STYLES[currentStyleIndex]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user