Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.mapbox.android.core.location.LocationEnginePriority;
import com.mapbox.android.core.location.LocationEngineProvider;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap;
Expand Down Expand Up @@ -141,13 +142,17 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

if (item.getItemId() == R.id.action_style_change) {
int id = item.getItemId();
if (id == R.id.action_style_change) {
toggleStyle();
return true;
} else if (item.getItemId() == R.id.action_plugin_disable) {
} else if (id == R.id.action_map_style_change) {
toggleMapStyle();
return true;
} else if (id == R.id.action_plugin_disable) {
locationLayerPlugin.setLocationLayerEnabled(false);
return true;
} else if (item.getItemId() == R.id.action_plugin_enabled) {
} else if (id == R.id.action_plugin_enabled) {
locationLayerPlugin.setLocationLayerEnabled(true);
return true;
}
Expand All @@ -162,6 +167,12 @@ public void toggleStyle() {
: R.style.mapbox_LocationLayer);
}

@VisibleForTesting
public void toggleMapStyle() {
String styleUrl = mapboxMap.getStyleUrl().contentEquals(Style.DARK) ? Style.LIGHT : Style.DARK;
mapboxMap.setStyle(styleUrl);
}

@VisibleForTesting
public LocationLayerPlugin getLocationLayerPlugin() {
return locationLayerPlugin;
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/menu/menu_location.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_style_change"
android:title="Toggle custom style"
android:title="Toggle custom LocationLayer style"
app:showAsAction="never"/>

<item android:id="@+id/action_map_style_change"
android:title="Toggle custom Map style"
app:showAsAction="never"/>

<item android:id="@+id/action_plugin_disable"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ final class LocationLayer implements LocationLayerAnimator.OnLayerAnimationsValu

void initializeComponents(LocationLayerOptions options) {
prepareLocationSource();
addLocationSource();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change adds the source before the first location fix is available, resulting in a puck being at null island until we get the first fix instead of being invisible.

addLayers();
applyStyle(options);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ private void initialize() {
updateMapWithOptions(options);

enableLocationLayerPlugin();
setRenderMode(RenderMode.NORMAL);
setCameraMode(CameraMode.NONE);
}

@SuppressLint("MissingPermission")
Expand Down Expand Up @@ -604,6 +606,7 @@ public void onMapChanged(int change) {
locationLayer.initializeComponents(options);
locationLayerCamera.initializeOptions(options);
setRenderMode(locationLayer.getRenderMode());
setCameraMode(locationLayerCamera.getCameraMode());
onStart();
}
}
Expand Down