Skip to content

Commit 47d1397

Browse files
author
Cameron Mace
authored
Update the icon offset imediately when first loaded. (#310)
1 parent 86b33b8 commit 47d1397

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

app/src/androidTest/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import android.support.test.rule.ActivityTestRule;
99
import android.support.test.runner.AndroidJUnit4;
1010

11+
import com.mapbox.mapboxsdk.camera.CameraPosition;
12+
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
1113
import com.mapbox.mapboxsdk.constants.Style;
1214
import com.mapbox.mapboxsdk.maps.MapboxMap;
1315
import com.mapbox.mapboxsdk.plugins.testapp.activity.location.LocationLayerModesActivity;
@@ -16,6 +18,7 @@
1618
import com.mapbox.mapboxsdk.utils.OnMapReadyIdlingResource;
1719

1820
import org.junit.After;
21+
import org.junit.Assert;
1922
import org.junit.Before;
2023
import org.junit.Rule;
2124
import org.junit.Test;
@@ -204,6 +207,18 @@ public void onLocationLayerAction(LocationLayerPlugin locationLayerPlugin, Mapbo
204207
}});
205208
}
206209

210+
@Test
211+
public void whenMapCameraInitializesTilted_iconsGetPlacedWithCorrectOffset() throws Exception {
212+
executeLocationLayerTest((locationLayerPlugin, mapboxMap, uiController, context) -> {
213+
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder().tilt(60).build()));
214+
locationLayerPlugin.setLocationLayerEnabled(LocationLayerMode.TRACKING);
215+
locationLayerPlugin.forceLocationUpdate(location);
216+
SymbolLayer layer = mapboxMap.getLayerAs(FOREGROUND_LAYER);
217+
Float[] value = layer.getIconOffset().getValue();
218+
Assert.assertEquals((-0.05 * 60), value[1], 0.1);
219+
});
220+
}
221+
207222
@After
208223
public void afterTest() {
209224
Timber.e("@After: unregister idle resource");

plugin-locationlayer/src/main/java/com/mapbox/mapboxsdk/plugins/locationlayer/LocationLayerPlugin.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ public void setLocationLayerEnabled(@LocationLayerMode.Mode int locationLayerMod
162162
locationEngine.addLocationEngineListener(this);
163163
}
164164

165+
// On Camera move is called here so that the layer icon offsets adjusted properly when the
166+
// maps initially tilted.
167+
onCameraMove();
168+
165169
toggleCameraListener();
166170

167171
if (locationLayerMode == LocationLayerMode.COMPASS) {

0 commit comments

Comments
 (0)