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

Commit

Permalink
[android] - optimise loaded style for location component, expose isFu…
Browse files Browse the repository at this point in the history
…llyLoaded
  • Loading branch information
tobrun committed Dec 7, 2018
1 parent 767bb43 commit 9f254c5
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import android.view.MotionEvent;

import com.mapbox.android.gestures.AndroidGesturesManager;
import com.mapbox.android.gestures.MoveGestureDetector;
import com.mapbox.android.gestures.RotateGestureDetector;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,8 @@ public void onStartLoadingMap() {
*/
public void onFinishLoadingStyle() {
if (isComponentInitialized) {
locationLayerController.initializeComponents(options);
style = mapboxMap.getStyle();
locationLayerController.initializeComponents(style, options);
locationCameraController.initializeOptions(options);
onLocationLayerStart();
}
Expand Down Expand Up @@ -913,7 +914,10 @@ private void initialize(@NonNull final Context context, @NonNull Style style,
if (isComponentInitialized) {
return;
}
isComponentInitialized = true;

if (!style.isFullyLoaded()) {
throw new IllegalStateException("Style hasn't fully loaded yet, can't initialize LocationComponent.");
}

this.style = style;
this.options = options;
Expand Down Expand Up @@ -946,6 +950,8 @@ private void initialize(@NonNull final Context context, @NonNull Style style,
setRenderMode(RenderMode.NORMAL);
setCameraMode(CameraMode.NONE);

isComponentInitialized = true;

onLocationLayerStart();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ final class LocationLayerController implements MapboxAnimator.OnLayerAnimationsV
private int renderMode;

private final MapboxMap mapboxMap;
private final Style style;
private Style style;
private final LayerSourceProvider layerSourceProvider;
private final LayerBitmapProvider bitmapProvider;
private LocationComponentOptions options;
Expand All @@ -81,11 +81,12 @@ final class LocationLayerController implements MapboxAnimator.OnLayerAnimationsV
this.layerSourceProvider = layerSourceProvider;
this.bitmapProvider = bitmapProvider;
this.locationFeature = featureProvider.generateLocationFeature(locationFeature, options);
initializeComponents(options);
initializeComponents(style, options);
setRenderMode(RenderMode.NORMAL);
}

void initializeComponents(LocationComponentOptions options) {
void initializeComponents(Style style, LocationComponentOptions options) {
this.style = style;
addLocationSource();
addLayers(options.layerBelow());
applyStyle(options);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void initialise(@NonNull Context context, @NonNull MapboxMapOptions options) {
* Get the Style of the map asynchronously.
*/
public void getStyle(@NonNull Style.OnStyleLoaded onStyleLoaded) {
if (style != null && style.isStyleLoaded()) {
if (style != null && style.isFullyLoaded()) {
onStyleLoaded.onStyleLoaded(style);
} else {
styleLoadedCallbacks.add(onStyleLoaded);
Expand All @@ -118,7 +118,7 @@ public void getStyle(@NonNull Style.OnStyleLoaded onStyleLoaded) {
*/
@Nullable
public Style getStyle() {
if (style == null || !style.isStyleLoaded()) {
if (style == null || !style.isFullyLoaded()) {
return null;
} else {
return style;
Expand Down
Loading

0 comments on commit 9f254c5

Please sign in to comment.