[android] - decouple style loading from OnMapReady
This commit is contained in:
@@ -57,6 +57,11 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
initLocation
|
||||
}
|
||||
|
||||
override fun validateTestSetup() {
|
||||
super.validateTestSetup()
|
||||
assertThat(mapboxMap.getStyle(), notNullValue())
|
||||
}
|
||||
|
||||
@Before
|
||||
override fun beforeTest() {
|
||||
super.beforeTest()
|
||||
@@ -152,7 +157,8 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
mapboxMap.setStyle(Style.LIGHT)
|
||||
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
|
||||
component.activateLocationComponent(context, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
@@ -231,6 +237,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun locationComponentOptions_loadsForegroundBitmapFromNameOption() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -272,6 +279,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun locationComponentOptions_loadsGpsNameWithGpsRenderMode() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -302,6 +310,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun locationComponentOptions_customIconNameRevertsToDefault() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -335,6 +344,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun locationComponentOptions_customGpsIconNameChangeBackWithMode() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -368,6 +378,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun stillStaleAfterResuming() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -402,6 +413,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun stillNotStaleAfterResuming() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -424,6 +436,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun locationComponentOptions_accuracyRingWithColor() {
|
||||
validateTestSetup()
|
||||
val color = Color.parseColor("#4A90E2")
|
||||
val rgbaColor = ColorUtils.colorToRgbaString(color)
|
||||
|
||||
@@ -454,6 +467,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun forceLocationUpdate_doesMoveLocationLayerIconToCorrectPosition() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -474,6 +488,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun disablingComponentHidesPuck() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -496,6 +511,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun disablingComponentAndChangingStyleAllowsToEnableAgain() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -505,7 +521,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
|
||||
component.isLocationComponentEnabled = false
|
||||
mapboxMap.setStyle(Style.LIGHT)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
|
||||
|
||||
component.isLocationComponentEnabled = true
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
@@ -517,6 +533,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun lifecycle_isDisabledOnStart() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -534,6 +551,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun lifecycle_keepsEnabledWhenStoppedAndStarted() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -550,6 +568,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun lifecycle_keepsDisabledWhenStoppedAndStarted() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -567,6 +586,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun lifecycle_ableToChangeStyleAfterResuming() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -576,7 +596,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
component.onStop()
|
||||
component.onStart()
|
||||
|
||||
mapboxMap.setStyle(Style.DARK)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.DARK))
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
}
|
||||
}
|
||||
@@ -585,12 +605,13 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun lifecycle_interruptedDuringStyleChange() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
mapboxMap.setStyle(Style.DARK)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.DARK))
|
||||
component.onStop()
|
||||
component.onStart()
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
@@ -601,6 +622,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun lifecycle_forceLocationUpdateAfterStopped() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -618,6 +640,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun lifecycle_acceptAndReuseLocationUpdatesBeforeLayerStarted() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -638,13 +661,14 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun lifecycle_lifecycleChangeRightAfterStyleReload() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
component.activateLocationComponent(context, false)
|
||||
component.isLocationComponentEnabled = true
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.setStyle(Style.LIGHT)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
|
||||
component.onStop()
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
component.onStart()
|
||||
@@ -666,6 +690,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun mapChange_settingComponentStyle() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -691,6 +716,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun mapChange_forcingLocation() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -713,6 +739,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun mapChange_settingMapStyleBeforeComponentCreation() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -738,6 +765,7 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
|
||||
@Test
|
||||
fun animators_layerBearingCorrect() {
|
||||
validateTestSetup()
|
||||
val componentAction = object : LocationComponentAction.OnPerformLocationComponentAction {
|
||||
override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap,
|
||||
uiController: UiController, context: Context) {
|
||||
@@ -747,6 +775,8 @@ class LocationComponentTest : BaseActivityTest() {
|
||||
location.bearing = 77f
|
||||
component.forceLocationUpdate(location)
|
||||
uiController.loopMainThreadForAtLeast(MAX_ANIMATION_DURATION_MS + MAP_RENDER_DELAY)
|
||||
assertThat(mapboxMap.style, notNullValue())
|
||||
assertThat(mapboxMap.style?.getSource(LOCATION_SOURCE), notNullValue())
|
||||
assertEquals(77.0, mapboxMap.querySourceFeatures(LOCATION_SOURCE)[0].getNumberProperty(PROPERTY_GPS_BEARING) as Double, 0.1)
|
||||
|
||||
location.bearing = 92f
|
||||
|
||||
@@ -79,7 +79,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
component.isLocationComponentEnabled = true
|
||||
component.renderMode = RenderMode.NORMAL
|
||||
uiController.loopMainThreadForAtLeast(MAP_RENDER_DELAY)
|
||||
assertThat(mapboxMap.getStyle().getSource(LOCATION_SOURCE), notNullValue())
|
||||
assertThat(mapboxMap.getStyle()!!.getSource(LOCATION_SOURCE), notNullValue())
|
||||
}
|
||||
}
|
||||
executeComponentTest(componentAction)
|
||||
@@ -212,7 +212,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
component.renderMode = RenderMode.NORMAL
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
mapboxMap.setStyleUrl(Style.LIGHT)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
component.forceLocationUpdate(location)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
@@ -220,7 +220,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
assertThat(component.renderMode, `is`(equalTo(RenderMode.NORMAL)))
|
||||
|
||||
// Check that the Source has been re-added to the new map style
|
||||
val source: GeoJsonSource? = mapboxMap.getStyle().getSourceAs(LOCATION_SOURCE)
|
||||
val source: GeoJsonSource? = mapboxMap.getStyle()!!.getSourceAs(LOCATION_SOURCE)
|
||||
assertThat(source, notNullValue())
|
||||
|
||||
// Check that all layers visibilities are set to visible
|
||||
@@ -253,7 +253,7 @@ class LocationLayerControllerTest : BaseActivityTest() {
|
||||
|
||||
assertThat(renderCheck.invoke(), `is`(true))
|
||||
|
||||
mapboxMap.setStyleUrl(Style.LIGHT)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(Style.LIGHT))
|
||||
uiController.loopMainThreadForAtLeast(MAP_CONNECTION_DELAY)
|
||||
mapboxMap.waitForLayer(uiController, location, FOREGROUND_LAYER)
|
||||
|
||||
|
||||
@@ -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.style.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.style.getLayer(layerId)?.visibility?.value?.equals(Property.VISIBLE)!!
|
||||
return this.style!!.getLayer(layerId)?.visibility?.value?.equals(Property.VISIBLE)!!
|
||||
}
|
||||
|
||||
fun MapboxMap.waitForSource(uiController: UiController, sourceId: String) {
|
||||
@@ -99,7 +99,7 @@ class MapboxTestingUtils {
|
||||
|
||||
fun MapboxMap.addImageFromDrawable(string: String, drawable: Drawable) {
|
||||
val bitmapFromDrawable = getBitmapFromDrawable(drawable)
|
||||
this.style.addImage(string, bitmapFromDrawable)
|
||||
this.style!!.addImage(string, bitmapFromDrawable)
|
||||
}
|
||||
|
||||
private fun getBitmapFromDrawable(drawable: Drawable): Bitmap {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.mapbox.mapboxsdk.location.utils
|
||||
import android.support.test.espresso.IdlingResource
|
||||
import com.mapbox.mapboxsdk.maps.MapView
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
|
||||
/**
|
||||
* Resource, that's idling until the provided style is loaded.
|
||||
@@ -39,6 +40,6 @@ class StyleChangeIdlingResource : IdlingResource {
|
||||
setIdle()
|
||||
}
|
||||
})
|
||||
mapboxMap.setStyleUrl(styleUrl)
|
||||
mapboxMap.setStyle(Style.Builder().fromUrl(styleUrl))
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ import com.mapbox.mapboxsdk.constants.MapboxConstants;
|
||||
import com.mapbox.mapboxsdk.exceptions.InvalidMarkerPositionException;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
import com.mapbox.mapboxsdk.style.layers.TransitionOptions;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.espresso.EspressoTestActivity;
|
||||
@@ -67,9 +68,12 @@ public class MapboxMapTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
|
||||
long transitionDuration = 600;
|
||||
mapboxMap.setTransitionDuration(transitionDuration);
|
||||
mapboxMap.getStyle().setTransition(new TransitionOptions(transitionDuration, 0));
|
||||
assertEquals(
|
||||
"TransitionDuration should match", transitionDuration, mapboxMap.getTransitionDuration(), 0
|
||||
"TransitionDuration should match",
|
||||
transitionDuration,
|
||||
mapboxMap.getStyle().getTransition().getDuration(),
|
||||
0
|
||||
);
|
||||
}));
|
||||
}
|
||||
@@ -79,9 +83,12 @@ public class MapboxMapTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
onView(withId(R.id.mapView)).perform(new MapboxMapAction((uiController, view) -> {
|
||||
long transitionDelay = 50;
|
||||
mapboxMap.setTransitionDelay(transitionDelay);
|
||||
mapboxMap.getStyle().setTransition(new TransitionOptions(600, transitionDelay));
|
||||
assertEquals(
|
||||
"TransitionDelay should match", transitionDelay, mapboxMap.getTransitionDelay(), 0
|
||||
"TransitionDelay should match",
|
||||
transitionDelay,
|
||||
mapboxMap.getStyle().getTransition().getDelay(),
|
||||
0
|
||||
);
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
package com.mapbox.mapboxsdk.style
|
||||
|
||||
import android.support.test.espresso.UiController
|
||||
import com.mapbox.geojson.Feature
|
||||
import com.mapbox.geojson.FeatureCollection
|
||||
import com.mapbox.geojson.Point
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap
|
||||
import com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconImage
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
|
||||
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction.invoke
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest
|
||||
import com.mapbox.mapboxsdk.testapp.activity.maplayout.SimpleMapActivity
|
||||
import org.junit.Test
|
||||
|
||||
class CustomGeometrySourceTest : BaseActivityTest() {
|
||||
|
||||
override fun getActivityClass(): Class<*> = SimpleMapActivity::class.java
|
||||
|
||||
@Test
|
||||
fun sourceUpdateAfterStyleChange() {
|
||||
validateTestSetup()
|
||||
invoke(mapboxMap) { uiController: UiController, mapboxMap: MapboxMap ->
|
||||
val style = mapboxMap.style
|
||||
|
||||
val source = GeoJsonSource(
|
||||
"source-id",
|
||||
FeatureCollection.fromFeature(
|
||||
Feature.fromGeometry(
|
||||
Point.fromLngLat(0.0, 0.0)
|
||||
)
|
||||
)
|
||||
)
|
||||
style.addSource(source)
|
||||
|
||||
style.loadStyle(Style.DARK)
|
||||
|
||||
uiController.loopMainThreadForAtLeast(300)
|
||||
|
||||
source.setGeoJson(
|
||||
FeatureCollection.fromFeature(
|
||||
Feature.fromGeometry(
|
||||
Point.fromLngLat(1.0, 1.0)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun layerUpdateAfterStyleChange() {
|
||||
validateTestSetup()
|
||||
invoke(mapboxMap) { uiController: UiController, mapboxMap: MapboxMap ->
|
||||
val style = mapboxMap.style
|
||||
|
||||
val source = GeoJsonSource(
|
||||
"source-id",
|
||||
FeatureCollection.fromFeature(
|
||||
Feature.fromGeometry(
|
||||
Point.fromLngLat(0.0, 0.0)
|
||||
)
|
||||
)
|
||||
)
|
||||
style.addSource(source)
|
||||
|
||||
val layer = SymbolLayer("test", "source-id")
|
||||
style.addLayer(layer)
|
||||
|
||||
style.loadStyle(Style.DARK)
|
||||
|
||||
layer.setProperties(iconImage("bus-15"))
|
||||
|
||||
uiController.loopMainThreadForAtLeast(300)
|
||||
|
||||
layer.setProperties(iconImage("bus-15"))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import com.mapbox.mapboxsdk.testapp.activity.render.RenderTestActivity;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.SnapshotterIdlingResource;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -58,6 +59,7 @@ public class RenderTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testRender() {
|
||||
onView(withId(android.R.id.content)).check(matches(isDisplayed()));
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ class CustomGeometrySourceTest : BaseActivityTest() {
|
||||
override fun getActivityClass(): Class<*> = GridSourceActivity::class.java
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
fun sourceNotLeakingThreadsTest() {
|
||||
validateTestSetup()
|
||||
waitAction(4000)
|
||||
@@ -39,9 +40,9 @@ class CustomGeometrySourceTest : BaseActivityTest() {
|
||||
fun threadsShutdownWhenSourceRemovedTest() {
|
||||
validateTestSetup()
|
||||
invoke(mapboxMap) { uiController, mapboxMap ->
|
||||
mapboxMap.getStyle().removeLayer(ID_GRID_LAYER)
|
||||
mapboxMap.style!!.removeLayer(ID_GRID_LAYER)
|
||||
uiController.loopMainThreadForAtLeast(3000)
|
||||
mapboxMap.getStyle().removeSource(ID_GRID_SOURCE)
|
||||
mapboxMap.style!!.removeSource(ID_GRID_SOURCE)
|
||||
uiController.loopMainThreadForAtLeast(1000)
|
||||
Assert.assertTrue("There should be no threads running when the source is removed.",
|
||||
Thread.getAllStackTraces().keys.filter {
|
||||
@@ -55,12 +56,12 @@ class CustomGeometrySourceTest : BaseActivityTest() {
|
||||
fun threadsRestartedWhenSourceReAddedTest() {
|
||||
validateTestSetup()
|
||||
invoke(mapboxMap) { uiController, mapboxMap ->
|
||||
mapboxMap.getStyle().removeLayer((rule.activity as GridSourceActivity).layer)
|
||||
mapboxMap.style!!.removeLayer((rule.activity as GridSourceActivity).layer)
|
||||
uiController.loopMainThreadForAtLeast(3000)
|
||||
mapboxMap.getStyle().removeSource(ID_GRID_SOURCE)
|
||||
mapboxMap.style!!.removeSource(ID_GRID_SOURCE)
|
||||
uiController.loopMainThreadForAtLeast(1000)
|
||||
mapboxMap.getStyle().addSource((rule.activity as GridSourceActivity).source)
|
||||
mapboxMap.getStyle().addLayer((rule.activity as GridSourceActivity).layer)
|
||||
mapboxMap.style!!.addSource((rule.activity as GridSourceActivity).source)
|
||||
mapboxMap.style!!.addLayer((rule.activity as GridSourceActivity).layer)
|
||||
uiController.loopMainThreadForAtLeast(1000)
|
||||
Assert.assertTrue("Threads should be restarted when the source is re-added to the map.",
|
||||
Thread.getAllStackTraces().keys.filter {
|
||||
|
||||
@@ -242,7 +242,8 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
Expression expression3 = eq(literal("Łukasz"), literal("lukasz"), collator(literal(false), eq(literal(2),
|
||||
literal(1))));
|
||||
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
mapboxMap.getStyle()
|
||||
.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
Layer layer = new CircleLayer("layer", "source")
|
||||
.withProperties(circleColor(
|
||||
switchCase(
|
||||
@@ -282,7 +283,8 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
mapboxMap.getStyle()
|
||||
.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
@@ -304,7 +306,8 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
mapboxMap.getStyle()
|
||||
.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
@@ -326,7 +329,8 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
mapboxMap.getStyle()
|
||||
.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
@@ -355,7 +359,8 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
mapboxMap.getStyle()
|
||||
.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
@@ -386,7 +391,8 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
mapboxMap.getStyle()
|
||||
.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
@@ -477,7 +483,8 @@ public class ExpressionTest extends BaseActivityTest {
|
||||
validateTestSetup();
|
||||
invoke(mapboxMap, (uiController, mapboxMap) -> {
|
||||
LatLng latLng = new LatLng(51, 17);
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
mapboxMap.getStyle()
|
||||
.addSource(new GeoJsonSource("source", Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())));
|
||||
SymbolLayer layer = new SymbolLayer("layer", "source");
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
|
||||
@@ -39,11 +39,11 @@ public class ImageTest extends BaseActivityTest {
|
||||
Bitmap bitmapSet = ((BitmapDrawable) drawable).getBitmap();
|
||||
mapboxMap.getStyle().addImage(IMAGE_ID, bitmapSet);
|
||||
|
||||
Bitmap bitmapGet = mapboxMap.getImage(IMAGE_ID);
|
||||
Bitmap bitmapGet = mapboxMap.getStyle().getImage(IMAGE_ID);
|
||||
assertTrue(bitmapGet.sameAs(bitmapSet));
|
||||
|
||||
mapboxMap.removeImage(IMAGE_ID);
|
||||
assertNull(mapboxMap.getImage(IMAGE_ID));
|
||||
mapboxMap.getStyle().removeImage(IMAGE_ID);
|
||||
assertNull(mapboxMap.getStyle().getImage(IMAGE_ID));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,9 @@ public class RuntimeStyleTests extends BaseActivityTest {
|
||||
|
||||
// Test inserting with invalid above-id
|
||||
try {
|
||||
mapboxMap.getStyle().addLayerAbove(new CircleLayer("invalid-id-layer-test", source.getId()), "no-such-layer-here-man");
|
||||
mapboxMap.getStyle().addLayerAbove(
|
||||
new CircleLayer("invalid-id-layer-test", source.getId()), "no-such-layer-here-man"
|
||||
);
|
||||
fail("Should have thrown exception");
|
||||
} catch (CannotAddLayerException ex) {
|
||||
// Yeah
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.support.test.espresso.UiController;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.action.MapboxMapAction;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.BaseActivityTest;
|
||||
@@ -37,8 +38,8 @@ public class StyleLoaderTest extends BaseActivityTest {
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
try {
|
||||
String expected = ResourceUtils.readRawResource(rule.getActivity(), R.raw.local_style);
|
||||
mapboxMap.setStyleJson(expected);
|
||||
String actual = mapboxMap.getStyleJson();
|
||||
mapboxMap.setStyle(new Style.Builder().fromJson(expected));
|
||||
String actual = mapboxMap.getStyle().getJson();
|
||||
assertEquals("Style json should match", expected, actual);
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
@@ -55,7 +56,7 @@ public class StyleLoaderTest extends BaseActivityTest {
|
||||
public void onInvokeAction(UiController uiController, MapboxMap mapboxMap) {
|
||||
try {
|
||||
String expected = ResourceUtils.readRawResource(rule.getActivity(), R.raw.local_style);
|
||||
mapboxMap.setStyleJson(expected);
|
||||
mapboxMap.setStyle(new Style.Builder().fromJson(expected));
|
||||
|
||||
// fake activity stop/start
|
||||
MapView mapView = (MapView) rule.getActivity().findViewById(R.id.mapView);
|
||||
@@ -65,8 +66,8 @@ public class StyleLoaderTest extends BaseActivityTest {
|
||||
mapView.onStart();
|
||||
mapView.onResume();
|
||||
|
||||
String actual = mapboxMap.getStyleJson();
|
||||
assertEquals("Style URL should be empty", "", mapboxMap.getStyleUrl());
|
||||
String actual = mapboxMap.getStyle().getJson();
|
||||
assertEquals("Style URL should be empty", "", mapboxMap.getStyle().getUrl());
|
||||
assertEquals("Style json should match", expected, actual);
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
|
||||
@@ -10,12 +10,14 @@ import android.support.test.espresso.IdlingResource;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallback {
|
||||
|
||||
private boolean styleLoaded;
|
||||
private MapboxMap mapboxMap;
|
||||
private IdlingResource.ResourceCallback resourceCallback;
|
||||
|
||||
@@ -25,11 +27,22 @@ public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallb
|
||||
handler.post(() -> {
|
||||
MapView mapView = activity.findViewById(R.id.mapView);
|
||||
if (mapView != null) {
|
||||
mapView.getMapAsync(OnMapReadyIdlingResource.this);
|
||||
mapView.addOnDidFinishLoadingStyleListener(() -> {
|
||||
styleLoaded = true;
|
||||
if (resourceCallback != null) {
|
||||
resourceCallback.onTransitionToIdle();
|
||||
}
|
||||
});
|
||||
mapView.getMapAsync(this::initMap);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initMap(MapboxMap mapboxMap) {
|
||||
this.mapboxMap = mapboxMap;
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return getClass().getSimpleName();
|
||||
@@ -37,7 +50,7 @@ public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallb
|
||||
|
||||
@Override
|
||||
public boolean isIdleNow() {
|
||||
return mapboxMap != null;
|
||||
return styleLoaded;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,8 +66,5 @@ public class OnMapReadyIdlingResource implements IdlingResource, OnMapReadyCallb
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
Assert.assertNotNull("MapboxMap should not be null", mapboxMap);
|
||||
this.mapboxMap = mapboxMap;
|
||||
if (resourceCallback != null) {
|
||||
resourceCallback.onTransitionToIdle();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
public class SingleActivity extends AppCompatActivity {
|
||||
@@ -14,8 +15,9 @@ public class SingleActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_single);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(mapboxMap -> mapboxMap.setStyle(new Style.Builder().fromUrl(Style.MAPBOX_STREETS)));
|
||||
}
|
||||
|
||||
public MapView getMapView() {
|
||||
|
||||
@@ -72,14 +72,15 @@ public class AnimatedSymbolLayerActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_animated_marker);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(map -> {
|
||||
this.mapboxMap = map;
|
||||
this.style = mapboxMap.getStyle();
|
||||
setupCars();
|
||||
animateRandomRoutes();
|
||||
animateTaxi();
|
||||
map.setStyle(Style.MAPBOX_STREETS, style -> {
|
||||
setupCars();
|
||||
animateRandomRoutes();
|
||||
animateTaxi();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.IconUtils;
|
||||
|
||||
@@ -31,10 +32,12 @@ public class DynamicMarkerChangeActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_dynamic_marker);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.setTag(false);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
|
||||
DynamicMarkerChangeActivity.this.mapboxMap = mapboxMap;
|
||||
// Create marker
|
||||
MarkerOptions markerOptions = new MarkerOptions()
|
||||
@@ -46,7 +49,7 @@ public class DynamicMarkerChangeActivity extends AppCompatActivity {
|
||||
marker = mapboxMap.addMarker(markerOptions);
|
||||
});
|
||||
|
||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
FloatingActionButton fab = findViewById(R.id.fab);
|
||||
fab.setColorFilter(ContextCompat.getColor(this, R.color.primary));
|
||||
fab.setOnClickListener(view -> {
|
||||
if (mapboxMap != null) {
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import timber.log.Timber;
|
||||
@@ -65,15 +66,14 @@ public class CameraAnimationTypeActivity extends AppCompatActivity implements On
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_camera_animation_types);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
if (mapView != null) {
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(this);
|
||||
}
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(Style.MAPBOX_STREETS));
|
||||
mapboxMap.getUiSettings().setAttributionEnabled(false);
|
||||
mapboxMap.getUiSettings().setLogoEnabled(false);
|
||||
mapboxMap.addOnCameraIdleListener(cameraIdleListener);
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.FontCache;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils;
|
||||
@@ -71,6 +72,7 @@ public class GestureDetectorActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
GestureDetectorActivity.this.mapboxMap = mapboxMap;
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
initializeMap();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.view.LockableBottomSheetBehavior;
|
||||
|
||||
@@ -52,20 +53,26 @@ public class LatLngBoundsActivity extends AppCompatActivity implements View.OnCl
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_latlngbounds);
|
||||
initBottomSheet();
|
||||
initMapView(savedInstanceState);
|
||||
}
|
||||
|
||||
private void initMapView(Bundle savedInstanceState) {
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(map -> {
|
||||
mapboxMap = map;
|
||||
initMap();
|
||||
disableGestures();
|
||||
moveToBounds(bottomSheet.getMeasuredHeight(), BOUNDS_PADDING_DIVIDER_SMALL, ANIMATION_DURATION_SHORT);
|
||||
loadStyle();
|
||||
});
|
||||
}
|
||||
|
||||
private void initMap() {
|
||||
disableGestures();
|
||||
addMarkers();
|
||||
initFab();
|
||||
initBottomSheet();
|
||||
moveToBounds(bottomSheet.getMeasuredHeight(), BOUNDS_PADDING_DIVIDER_SMALL, ANIMATION_DURATION_SHORT);
|
||||
private void loadStyle() {
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(Style.MAPBOX_STREETS), style -> {
|
||||
addMarkers();
|
||||
initFab();
|
||||
});
|
||||
}
|
||||
|
||||
private void disableGestures() {
|
||||
@@ -96,7 +103,7 @@ public class LatLngBoundsActivity extends AppCompatActivity implements View.OnCl
|
||||
bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
|
||||
@Override
|
||||
public void onStateChanged(@NonNull View bottomSheet, int newState) {
|
||||
if (newState == BottomSheetBehavior.STATE_SETTLING) {
|
||||
if (newState == BottomSheetBehavior.STATE_SETTLING && mapboxMap != null) {
|
||||
moveToBounds(0, BOUNDS_PADDING_DIVIDER_LARGE, ANIMATION_DURATION_LONG);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,11 +31,10 @@ public class ManualZoomActivity extends AppCompatActivity {
|
||||
setContentView(R.layout.activity_manual_zoom);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView.setStyleUrl(Style.SATELLITE);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
ManualZoomActivity.this.mapboxMap = mapboxMap;
|
||||
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(Style.SATELLITE));
|
||||
UiSettings uiSettings = ManualZoomActivity.this.mapboxMap.getUiSettings();
|
||||
uiSettings.setAllGesturesEnabled(false);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(Style.OUTDOORS));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
@@ -35,15 +34,17 @@ public class CustomLayerActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_custom_layer);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(map -> {
|
||||
mapboxMap = map;
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(39.91448, -243.60947), 10));
|
||||
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> initFab());
|
||||
});
|
||||
}
|
||||
|
||||
fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
private void initFab() {
|
||||
fab = findViewById(R.id.fab);
|
||||
fab.setColorFilter(ContextCompat.getColor(this, R.color.primary));
|
||||
fab.setOnClickListener(view -> {
|
||||
if (mapboxMap != null) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.support.v7.app.AppCompatActivity;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
public class DeviceIndependentTestActivity extends AppCompatActivity implements OnMapReadyCallback {
|
||||
@@ -27,6 +28,7 @@ public class DeviceIndependentTestActivity extends AppCompatActivity implements
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
}
|
||||
|
||||
public MapboxMap getMapboxMap() {
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.google.gson.JsonElement;
|
||||
import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import java.util.List;
|
||||
@@ -37,6 +38,9 @@ public class QueryRenderedFeaturesBoxCountActivity extends AppCompatActivity {
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
QueryRenderedFeaturesBoxCountActivity.this.mapboxMap = mapboxMap;
|
||||
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(Style.MAPBOX_STREETS));
|
||||
|
||||
selectionBox.setOnClickListener(view -> {
|
||||
// Query
|
||||
int top = selectionBox.getTop() - mapView.getTop();
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.FillLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
@@ -48,15 +49,10 @@ public class QueryRenderedFeaturesBoxHighlightActivity extends AppCompatActivity
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
QueryRenderedFeaturesBoxHighlightActivity.this.mapboxMap = mapboxMap;
|
||||
|
||||
Style style = mapboxMap.getStyle();
|
||||
|
||||
// Add layer / source
|
||||
final GeoJsonSource source = new GeoJsonSource("highlighted-shapes-source");
|
||||
style.addSource(source);
|
||||
style.addLayer(
|
||||
new FillLayer("highlighted-shapes-layer", "highlighted-shapes-source")
|
||||
.withProperties(fillColor(Color.RED))
|
||||
);
|
||||
final Layer layer = new FillLayer("highlighted-shapes-layer", "highlighted-shapes-source")
|
||||
.withProperties(fillColor(Color.RED));
|
||||
|
||||
selectionBox.setOnClickListener(view -> {
|
||||
// Query
|
||||
@@ -77,6 +73,12 @@ public class QueryRenderedFeaturesBoxHighlightActivity extends AppCompatActivity
|
||||
// Update source data
|
||||
source.setGeoJson(FeatureCollection.fromFeatures(features));
|
||||
});
|
||||
|
||||
mapboxMap.setStyle(new Style.Builder()
|
||||
.fromUrl(Style.MAPBOX_STREETS)
|
||||
.withSource(source)
|
||||
.withLayer(layer)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.feature;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.RectF;
|
||||
import android.os.Bundle;
|
||||
@@ -10,6 +11,8 @@ import android.widget.Toast;
|
||||
import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.BackgroundLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
@@ -20,6 +23,8 @@ import java.util.List;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.rgb;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.backgroundColor;
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.iconImage;
|
||||
|
||||
/**
|
||||
@@ -45,20 +50,31 @@ public class QueryRenderedFeaturesBoxSymbolCountActivity extends AppCompatActivi
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
QueryRenderedFeaturesBoxSymbolCountActivity.this.mapboxMap = mapboxMap;
|
||||
|
||||
// Add a symbol layer (also works with annotations)
|
||||
try {
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource("symbols-source", ResourceUtils.readRawResource(
|
||||
QueryRenderedFeaturesBoxSymbolCountActivity.this, R.raw.test_points_utrecht)));
|
||||
} catch (IOException ioException) {
|
||||
Timber.e(ioException, "Could not load geojson");
|
||||
return;
|
||||
String testPoints = ResourceUtils.readRawResource(mapView.getContext(), R.raw.test_points_utrecht);
|
||||
Bitmap markerImage = BitmapFactory.decodeResource(getResources(), R.drawable.mapbox_marker_icon_default);
|
||||
|
||||
mapboxMap.setStyle(new Style.Builder()
|
||||
.withLayer(
|
||||
new BackgroundLayer("bg")
|
||||
.withProperties(
|
||||
backgroundColor(rgb(120, 161, 226))
|
||||
)
|
||||
)
|
||||
.withLayer(
|
||||
new SymbolLayer("symbols-layer", "symbols-source")
|
||||
.withProperties(
|
||||
iconImage("test-icon")
|
||||
)
|
||||
)
|
||||
.withSource(
|
||||
new GeoJsonSource("symbols-source", testPoints)
|
||||
)
|
||||
.withImage("test-icon", markerImage)
|
||||
);
|
||||
} catch (IOException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
mapboxMap.getStyle().addImage(
|
||||
"test-icon",
|
||||
BitmapFactory.decodeResource(getResources(),
|
||||
R.drawable.mapbox_marker_icon_default)
|
||||
);
|
||||
mapboxMap.getStyle().addLayer(new SymbolLayer("symbols-layer", "symbols-source").withProperties(iconImage("test-icon")));
|
||||
|
||||
selectionBox.setOnClickListener(view -> {
|
||||
// Query
|
||||
|
||||
@@ -66,7 +66,6 @@ public class QueryRenderedFeaturesPropertiesActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_query_features_point);
|
||||
|
||||
|
||||
// Initialize map as normal
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
|
||||
@@ -5,12 +5,13 @@ import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.geojson.FeatureCollection;
|
||||
import com.mapbox.geojson.Point;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
@@ -29,6 +30,7 @@ import static com.mapbox.mapboxsdk.style.expressions.Expression.neq;
|
||||
public class QuerySourceFeaturesActivity extends AppCompatActivity {
|
||||
|
||||
public MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -38,47 +40,53 @@ public class QuerySourceFeaturesActivity extends AppCompatActivity {
|
||||
// Initialize map as normal
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
JsonObject properties = new JsonObject();
|
||||
properties.addProperty("key1", "value1");
|
||||
final GeoJsonSource source = new GeoJsonSource("test-source",
|
||||
FeatureCollection.fromFeatures(new Feature[] {
|
||||
Feature.fromGeometry(Point.fromLngLat(17.1, 51), properties),
|
||||
Feature.fromGeometry(Point.fromLngLat(17.2, 51), properties),
|
||||
Feature.fromGeometry(Point.fromLngLat(17.3, 51), properties),
|
||||
Feature.fromGeometry(Point.fromLngLat(17.4, 51), properties),
|
||||
}));
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
mapView.getMapAsync(map -> {
|
||||
this.mapboxMap = map;
|
||||
mapboxMap.getStyle(this::initStyle);
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
});
|
||||
}
|
||||
|
||||
Expression visible = eq(get("key1"), literal("value1"));
|
||||
Expression invisible = neq(get("key1"), literal("value1"));
|
||||
private void initStyle(Style style) {
|
||||
JsonObject properties = new JsonObject();
|
||||
properties.addProperty("key1", "value1");
|
||||
final GeoJsonSource source = new GeoJsonSource("test-source",
|
||||
FeatureCollection.fromFeatures(new Feature[] {
|
||||
Feature.fromGeometry(Point.fromLngLat(17.1, 51), properties),
|
||||
Feature.fromGeometry(Point.fromLngLat(17.2, 51), properties),
|
||||
Feature.fromGeometry(Point.fromLngLat(17.3, 51), properties),
|
||||
Feature.fromGeometry(Point.fromLngLat(17.4, 51), properties),
|
||||
}));
|
||||
style.addSource(source);
|
||||
|
||||
CircleLayer layer = new CircleLayer("test-layer", source.getId())
|
||||
.withFilter(visible);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
Expression visible = eq(get("key1"), literal("value1"));
|
||||
Expression invisible = neq(get("key1"), literal("value1"));
|
||||
|
||||
// Add a click listener
|
||||
mapboxMap.addOnMapClickListener(point -> {
|
||||
// Query
|
||||
List<Feature> features = source.querySourceFeatures(eq(get("key1"), literal("value1")));
|
||||
Toast.makeText(QuerySourceFeaturesActivity.this, String.format("Found %s features",
|
||||
features.size()), Toast.LENGTH_SHORT).show();
|
||||
CircleLayer layer = new CircleLayer("test-layer", source.getId())
|
||||
.withFilter(visible);
|
||||
style.addLayer(layer);
|
||||
|
||||
return false;
|
||||
});
|
||||
// Add a click listener
|
||||
mapboxMap.addOnMapClickListener(point -> {
|
||||
// Query
|
||||
List<Feature> features = source.querySourceFeatures(eq(get("key1"), literal("value1")));
|
||||
Toast.makeText(QuerySourceFeaturesActivity.this, String.format("Found %s features",
|
||||
features.size()), Toast.LENGTH_SHORT).show();
|
||||
|
||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
fab.setColorFilter(ContextCompat.getColor(this, R.color.primary));
|
||||
fab.setOnClickListener(view -> {
|
||||
Expression visibility = layer.getFilter();
|
||||
if (visibility != null && visibility.equals(visible)) {
|
||||
layer.setFilter(invisible);
|
||||
fab.setImageResource(R.drawable.ic_layers_clear);
|
||||
} else {
|
||||
layer.setFilter(visible);
|
||||
fab.setImageResource(R.drawable.ic_layers);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
fab.setColorFilter(ContextCompat.getColor(this, R.color.primary));
|
||||
fab.setOnClickListener(view -> {
|
||||
Expression visibility = layer.getFilter();
|
||||
if (visibility != null && visibility.equals(visible)) {
|
||||
layer.setFilter(invisible);
|
||||
fab.setImageResource(R.drawable.ic_layers_clear);
|
||||
} else {
|
||||
layer.setFilter(visible);
|
||||
fab.setImageResource(R.drawable.ic_layers);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@ import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition
|
||||
import com.mapbox.mapboxsdk.constants.Style
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMapOptions
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
import com.mapbox.mapboxsdk.maps.SupportMapFragment
|
||||
import com.mapbox.mapboxsdk.testapp.R
|
||||
import kotlinx.android.synthetic.main.activity_recyclerview.*
|
||||
|
||||
@@ -23,14 +23,14 @@ public class PrintActivity extends AppCompatActivity implements MapboxMap.Snapsh
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_print);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(mapboxMap -> PrintActivity.this.mapboxMap = mapboxMap);
|
||||
|
||||
final View fab = findViewById(R.id.fab);
|
||||
if (fab != null) {
|
||||
fab.setOnClickListener(view -> {
|
||||
if (mapboxMap != null) {
|
||||
if (mapboxMap.getStyle() != null) {
|
||||
mapboxMap.snapshot(PrintActivity.this);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -41,7 +41,7 @@ public class SnapshotActivity extends AppCompatActivity implements OnMapReadyCal
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
mapboxMap.setStyleUrl(Style.OUTDOORS);
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(Style.OUTDOORS));
|
||||
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
|
||||
if (fab != null) {
|
||||
fab.setColorFilter(ContextCompat.getColor(SnapshotActivity.this, R.color.primary));
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.mapbox.mapboxsdk.geometry.LatLng
|
||||
import com.mapbox.mapboxsdk.maps.MapView
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap
|
||||
import com.mapbox.mapboxsdk.location.LocationComponent
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
import com.mapbox.mapboxsdk.testapp.R
|
||||
import kotlinx.android.synthetic.main.activity_location_layer_fragment.*
|
||||
import java.lang.Exception
|
||||
@@ -104,10 +105,12 @@ class LocationFragmentActivity : AppCompatActivity() {
|
||||
mapView.onCreate(savedInstanceState)
|
||||
mapView.getMapAsync {
|
||||
mapboxMap = it
|
||||
component = mapboxMap.locationComponent
|
||||
component?.activateLocationComponent(activity)
|
||||
component?.isLocationComponentEnabled = true
|
||||
component?.locationEngine?.getLastLocation(this)
|
||||
it.setStyle(Style.MAPBOX_STREETS) { _ ->
|
||||
component = mapboxMap.locationComponent
|
||||
component?.activateLocationComponent(activity)
|
||||
component?.isLocationComponentEnabled = true
|
||||
component?.locationEngine?.getLastLocation(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.mapbox.mapboxsdk.location.modes.RenderMode;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import java.util.List;
|
||||
@@ -34,11 +35,10 @@ public class LocationMapChangeActivity extends AppCompatActivity implements OnMa
|
||||
|
||||
stylesFab.setOnClickListener(v -> {
|
||||
if (mapboxMap != null) {
|
||||
mapboxMap.setStyleUrl(Utils.getNextStyle());
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(Utils.getNextStyle()));
|
||||
}
|
||||
});
|
||||
|
||||
mapView.setStyleUrl(Utils.getNextStyle());
|
||||
mapView.onCreate(savedInstanceState);
|
||||
|
||||
if (PermissionsManager.areLocationPermissionsGranted(this)) {
|
||||
@@ -73,12 +73,14 @@ public class LocationMapChangeActivity extends AppCompatActivity implements OnMa
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
this.mapboxMap = mapboxMap;
|
||||
activateLocationComponent();
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(Utils.getNextStyle()),
|
||||
style -> activateLocationComponent());
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
private void activateLocationComponent() {
|
||||
LocationComponent locationComponent = mapboxMap.getLocationComponent();
|
||||
locationComponent.onStart();
|
||||
locationComponent.activateLocationComponent(this);
|
||||
locationComponent.setLocationComponentEnabled(true);
|
||||
locationComponent.setRenderMode(RenderMode.COMPASS);
|
||||
|
||||
@@ -12,6 +12,8 @@ import android.view.MenuItem;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mapbox.android.core.location.LocationEngineRequest;
|
||||
import com.mapbox.android.core.permissions.PermissionsListener;
|
||||
import com.mapbox.android.core.permissions.PermissionsManager;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
@@ -121,32 +123,34 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
this.mapboxMap = mapboxMap;
|
||||
|
||||
int[] padding;
|
||||
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
padding = new int[] {0, 750, 0, 0};
|
||||
} else {
|
||||
padding = new int[] {0, 250, 0, 0};
|
||||
}
|
||||
mapboxMap.getStyle(style -> {
|
||||
int[] padding;
|
||||
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
padding = new int[] {0, 750, 0, 0};
|
||||
} else {
|
||||
padding = new int[] {0, 250, 0, 0};
|
||||
}
|
||||
|
||||
LocationComponentOptions options = LocationComponentOptions.builder(this)
|
||||
.padding(padding)
|
||||
.layerBelow("waterway-label")
|
||||
.build();
|
||||
LocationComponentOptions options = LocationComponentOptions.builder(this)
|
||||
.padding(padding)
|
||||
.layerBelow("waterway-label")
|
||||
.build();
|
||||
|
||||
locationComponent = mapboxMap.getLocationComponent();
|
||||
locationComponent.activateLocationComponent(this, true,
|
||||
new LocationEngineRequest.Builder(750)
|
||||
.setFastestInterval(750)
|
||||
.setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
|
||||
.build()
|
||||
);
|
||||
locationComponent.applyStyle(options);
|
||||
locationComponent.setLocationComponentEnabled(true);
|
||||
locationComponent.addOnLocationClickListener(this);
|
||||
locationComponent.addOnCameraTrackingChangedListener(this);
|
||||
locationComponent.setCameraMode(cameraMode);
|
||||
setRendererMode(renderMode);
|
||||
locationComponent.forceLocationUpdate(lastLocation);
|
||||
locationComponent = mapboxMap.getLocationComponent();
|
||||
locationComponent.activateLocationComponent(this, true,
|
||||
new LocationEngineRequest.Builder(750)
|
||||
.setFastestInterval(750)
|
||||
.setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
|
||||
.build()
|
||||
);
|
||||
locationComponent.applyStyle(options);
|
||||
locationComponent.setLocationComponentEnabled(true);
|
||||
locationComponent.addOnLocationClickListener(this);
|
||||
locationComponent.addOnCameraTrackingChangedListener(this);
|
||||
locationComponent.setCameraMode(cameraMode);
|
||||
setRendererMode(renderMode);
|
||||
locationComponent.forceLocationUpdate(lastLocation);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -187,6 +191,10 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea
|
||||
}
|
||||
|
||||
private void toggleStyle() {
|
||||
if (locationComponent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
customStyle = !customStyle;
|
||||
locationComponent.applyStyle(
|
||||
this,
|
||||
@@ -194,11 +202,19 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea
|
||||
}
|
||||
|
||||
private void toggleMapStyle() {
|
||||
String styleUrl = mapboxMap.getStyleUrl().contentEquals(Style.DARK) ? Style.LIGHT : Style.DARK;
|
||||
mapboxMap.setStyle(styleUrl);
|
||||
if (locationComponent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
String styleUrl = Style.DARK.equals(mapboxMap.getStyle().getUrl()) ? Style.LIGHT : Style.DARK;
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(styleUrl));
|
||||
}
|
||||
|
||||
private void disableGesturesManagement() {
|
||||
if (locationComponent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
LocationComponentOptions options = locationComponent
|
||||
.getLocationComponentOptions()
|
||||
.toBuilder()
|
||||
@@ -208,6 +224,10 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea
|
||||
}
|
||||
|
||||
private void enableGesturesManagement() {
|
||||
if (locationComponent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
LocationComponentOptions options = locationComponent
|
||||
.getLocationComponentOptions()
|
||||
.toBuilder()
|
||||
|
||||
@@ -6,7 +6,6 @@ import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mapbox.android.core.location.LocationEngine;
|
||||
import com.mapbox.android.core.location.LocationEngineProvider;
|
||||
import com.mapbox.android.core.location.LocationEngineRequest;
|
||||
@@ -18,6 +17,7 @@ import com.mapbox.mapboxsdk.location.modes.RenderMode;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import java.util.List;
|
||||
@@ -107,16 +107,18 @@ public class ManualLocationUpdatesActivity extends AppCompatActivity implements
|
||||
@SuppressLint("MissingPermission")
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
locationComponent = mapboxMap.getLocationComponent();
|
||||
locationComponent.activateLocationComponent(
|
||||
this,
|
||||
locationEngine,
|
||||
new LocationEngineRequest.Builder(500)
|
||||
.setFastestInterval(500)
|
||||
.setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
|
||||
.build());
|
||||
locationComponent.setLocationComponentEnabled(true);
|
||||
locationComponent.setRenderMode(RenderMode.COMPASS);
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(Style.MAPBOX_STREETS), style -> {
|
||||
locationComponent = mapboxMap.getLocationComponent();
|
||||
locationComponent.activateLocationComponent(
|
||||
this,
|
||||
locationEngine,
|
||||
new LocationEngineRequest.Builder(500)
|
||||
.setFastestInterval(500)
|
||||
.setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY)
|
||||
.build());
|
||||
locationComponent.setLocationComponentEnabled(true);
|
||||
locationComponent.setRenderMode(RenderMode.COMPASS);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,10 +16,11 @@ import android.widget.BaseAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||
import com.mapbox.mapboxsdk.style.layers.Property;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
@@ -81,8 +82,9 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa
|
||||
}
|
||||
|
||||
private void setupMapView(Bundle savedInstanceState) {
|
||||
mapView = findViewById(R.id.mapView);
|
||||
|
||||
MapboxMapOptions mapboxMapOptions = setupMapboxMapOptions();
|
||||
mapView = new MapView(this, mapboxMapOptions);
|
||||
((ViewGroup) findViewById(R.id.coordinator_layout)).addView(mapView);
|
||||
mapView.addOnDidFinishLoadingStyleListener(() -> {
|
||||
if (mapboxMap != null) {
|
||||
setupNavigationView(mapboxMap.getStyle().getLayers());
|
||||
@@ -90,17 +92,23 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa
|
||||
});
|
||||
|
||||
mapView.setTag(true);
|
||||
mapView.setStyleUrl(STYLES[currentStyleIndex]);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(this);
|
||||
mapView.addOnDidFinishLoadingStyleListener(() -> Timber.d("Style loaded"));
|
||||
}
|
||||
|
||||
protected MapboxMapOptions setupMapboxMapOptions() {
|
||||
MapboxMapOptions mapboxMapOptions = new MapboxMapOptions();
|
||||
mapboxMapOptions.styleUrl(Style.MAPBOX_STREETS);
|
||||
return mapboxMapOptions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
|
||||
setupNavigationView(mapboxMap.getStyle().getLayers());
|
||||
mapboxMap.setStyle(
|
||||
new Style.Builder().fromUrl(STYLES[currentStyleIndex]), style -> setupNavigationView(style.getLayers())
|
||||
);
|
||||
setupZoomView();
|
||||
setFpsView();
|
||||
}
|
||||
@@ -113,7 +121,7 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa
|
||||
}
|
||||
|
||||
private void setupNavigationView(List<Layer> layerList) {
|
||||
Timber.v("New style loaded with JSON: %s", mapboxMap.getStyleJson());
|
||||
Timber.v("New style loaded with JSON: %s", mapboxMap.getStyle().getJson());
|
||||
final LayerListAdapter adapter = new LayerListAdapter(this, layerList);
|
||||
ListView listView = findViewById(R.id.listView);
|
||||
listView.setAdapter(adapter);
|
||||
@@ -161,7 +169,7 @@ public class DebugModeActivity extends AppCompatActivity implements OnMapReadyCa
|
||||
if (currentStyleIndex == STYLES.length) {
|
||||
currentStyleIndex = 0;
|
||||
}
|
||||
mapboxMap.setStyleUrl(STYLES[currentStyleIndex]);
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(STYLES[currentStyleIndex]));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -82,7 +82,6 @@ public class DoubleMapActivity extends AppCompatActivity {
|
||||
// MapView mini
|
||||
mapViewMini = view.findViewById(R.id.mini_map);
|
||||
mapViewMini.onCreate(savedInstanceState);
|
||||
mapViewMini.setStyleUrl(Style.LIGHT);
|
||||
mapViewMini.getMapAsync(mapboxMap -> {
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition.Builder().target(MACHU_PICCHU)
|
||||
@@ -90,6 +89,7 @@ public class DoubleMapActivity extends AppCompatActivity {
|
||||
.build()
|
||||
)
|
||||
);
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(Style.LIGHT));
|
||||
|
||||
UiSettings uiSettings = mapboxMap.getUiSettings();
|
||||
uiSettings.setAllGesturesEnabled(false);
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.maplayout;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
/**
|
||||
@@ -24,20 +20,17 @@ public class LocalGlyphActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_local_glyph);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
// Set initial position to Suzhou
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition.Builder()
|
||||
.target(new LatLng(31.3003, 120.7457))
|
||||
.zoom(11)
|
||||
.bearing(0)
|
||||
.tilt(0)
|
||||
.build()));
|
||||
}
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
// Set initial position to Suzhou
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition.Builder()
|
||||
.target(new LatLng(31.3003, 120.7457))
|
||||
.zoom(11)
|
||||
.bearing(0)
|
||||
.tilt(0)
|
||||
.build()));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import android.support.v7.app.AppCompatActivity;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import timber.log.Timber;
|
||||
@@ -17,7 +17,6 @@ import timber.log.Timber;
|
||||
public class MapChangeActivity extends AppCompatActivity {
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -38,8 +37,8 @@ public class MapChangeActivity extends AppCompatActivity {
|
||||
mapView.addOnWillStartRenderingFrameListener(() -> Timber.v("OnWillStartRenderingFrame"));
|
||||
mapView.addOnWillStartRenderingMapListener(() -> Timber.v("OnWillStartRenderingMap"));
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(map -> {
|
||||
mapboxMap = map;
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
|
||||
new LatLng(55.754020, 37.620948), 12), 9000);
|
||||
});
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.UiSettings;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
/**
|
||||
@@ -26,7 +27,7 @@ public class MapPaddingActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_map_padding);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.setTag(true);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
|
||||
@@ -39,6 +40,11 @@ public class MapPaddingActivity extends AppCompatActivity {
|
||||
int paddingTop = (int) getResources().getDimension(R.dimen.map_padding_top);
|
||||
mapboxMap.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom);
|
||||
|
||||
UiSettings settings = mapboxMap.getUiSettings();
|
||||
settings.setLogoMargins(paddingLeft, 0, 0, paddingBottom);
|
||||
settings.setCompassMargins(0, paddingTop, paddingRight, 0);
|
||||
settings.setAttributionEnabled(false);
|
||||
|
||||
moveToBangalore();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.graphics.*
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.view.View
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
import com.mapbox.mapboxsdk.testapp.R
|
||||
import kotlinx.android.synthetic.main.activity_overlay.*
|
||||
|
||||
@@ -19,6 +20,9 @@ class OverlayMapActivity : AppCompatActivity() {
|
||||
setContentView(R.layout.activity_overlay)
|
||||
mapView.onCreate(savedInstanceState)
|
||||
parentView.addView(OverlayView(this))
|
||||
mapView.getMapAsync {
|
||||
it.setStyle(Style.MAPBOX_STREETS)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
|
||||
@@ -2,8 +2,8 @@ package com.mapbox.mapboxsdk.testapp.activity.maplayout;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
/**
|
||||
@@ -17,8 +17,11 @@ public class SimpleMapActivity extends AppCompatActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_map_simple);
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(mapboxMap -> mapboxMap.setStyle(
|
||||
new Style.Builder().fromUrl(Style.MAPBOX_STREETS)
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -27,14 +27,13 @@ class MergeOfflineRegionsActivity : AppCompatActivity() {
|
||||
// forcing offline state
|
||||
Mapbox.setConnected(false)
|
||||
|
||||
mapView.setStyleUrl(TEST_STYLE)
|
||||
|
||||
mapView.onCreate(savedInstanceState)
|
||||
load_region_btn.setOnClickListener {
|
||||
copyAsset()
|
||||
}
|
||||
mapView.getMapAsync {
|
||||
it.isDebugActive = true
|
||||
it.setStyle(Style.Builder().fromUrl(TEST_STYLE))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +58,9 @@ class MergeOfflineRegionsActivity : AppCompatActivity() {
|
||||
FileSource.getResourcesCachePath(this) + "/" + TEST_DB_FILE_NAME,
|
||||
object : OfflineManager.MergeOfflineRegionsCallback {
|
||||
override fun onMerge(offlineRegions: Array<OfflineRegion>) {
|
||||
mapView.setStyleUrl(TEST_STYLE)
|
||||
mapView.getMapAsync{
|
||||
it.setStyle(Style.Builder().fromUrl(TEST_STYLE))
|
||||
}
|
||||
Toast.makeText(
|
||||
this@MergeOfflineRegionsActivity,
|
||||
String.format("Merged %d regions.", offlineRegions.size),
|
||||
|
||||
@@ -76,12 +76,11 @@ public class OfflineActivity extends AppCompatActivity
|
||||
|
||||
// Set up map
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView.setStyleUrl(STYLE_URL);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
Timber.d("Map is ready");
|
||||
OfflineActivity.this.mapboxMap = mapboxMap;
|
||||
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(STYLE_URL));
|
||||
// Set initial position to UNHQ in NYC
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition.Builder()
|
||||
|
||||
@@ -40,7 +40,7 @@ public class UpdateMetadataActivity extends AppCompatActivity implements Adapter
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_metadata_update);
|
||||
|
||||
ListView listView = (ListView) findViewById(R.id.listView);
|
||||
ListView listView = findViewById(R.id.listView);
|
||||
listView.setAdapter(adapter = new OfflineRegionMetadataAdapter(this));
|
||||
listView.setEmptyView(findViewById(android.R.id.empty));
|
||||
listView.setOnItemClickListener(this);
|
||||
@@ -73,11 +73,11 @@ public class UpdateMetadataActivity extends AppCompatActivity implements Adapter
|
||||
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
ViewGroup container = (ViewGroup) findViewById(R.id.container);
|
||||
ViewGroup container = findViewById(R.id.container);
|
||||
container.removeAllViews();
|
||||
container.addView(mapView = new MapView(view.getContext()));
|
||||
mapView.setOfflineRegionDefinition(adapter.getItem(position).getDefinition());
|
||||
mapView.onCreate(null);
|
||||
mapView.getMapAsync(map -> map.setOfflineRegionDefinition(adapter.getItem(position).getDefinition()));
|
||||
mapView.onStart();
|
||||
mapView.onResume();
|
||||
return true;
|
||||
|
||||
@@ -34,7 +34,7 @@ public class MapSnapshotterActivity extends AppCompatActivity {
|
||||
|
||||
// Find the grid view and start snapshotting as soon
|
||||
// as the view is measured
|
||||
grid = (GridLayout) findViewById(R.id.snapshot_grid);
|
||||
grid = findViewById(R.id.snapshot_grid);
|
||||
grid.getViewTreeObserver()
|
||||
.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,7 @@ import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.storage.FileSource;
|
||||
import com.mapbox.mapboxsdk.storage.Resource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
@@ -18,7 +18,6 @@ import timber.log.Timber;
|
||||
public class UrlTransformActivity extends AppCompatActivity {
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
|
||||
/**
|
||||
* Be sure to use an isolated class so the activity is not leaked when
|
||||
@@ -48,7 +47,7 @@ public class UrlTransformActivity extends AppCompatActivity {
|
||||
|
||||
mapView.getMapAsync(map -> {
|
||||
Timber.i("Map loaded");
|
||||
mapboxMap = map;
|
||||
map.setStyle(Style.MAPBOX_STREETS);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.mapbox.mapboxsdk.geometry.LatLngQuad;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.RasterLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.ImageSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
@@ -52,22 +53,24 @@ public class AnimatedImageSourceActivity extends AppCompatActivity implements On
|
||||
public void onMapReady(@NonNull final MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
|
||||
// add source
|
||||
LatLngQuad quad = new LatLngQuad(
|
||||
map.setStyle(Style.MAPBOX_STREETS, style -> {
|
||||
// add source
|
||||
LatLngQuad quad = new LatLngQuad(
|
||||
new LatLng(46.437, -80.425),
|
||||
new LatLng(46.437, -71.516),
|
||||
new LatLng(37.936, -71.516),
|
||||
new LatLng(37.936, -80.425));
|
||||
mapboxMap.getStyle().addSource(new ImageSource(ID_IMAGE_SOURCE, quad, R.drawable.southeast_radar_0));
|
||||
mapboxMap.getStyle().addSource(new ImageSource(ID_IMAGE_SOURCE, quad, R.drawable.southeast_radar_0));
|
||||
|
||||
// add layer
|
||||
RasterLayer layer = new RasterLayer(ID_IMAGE_LAYER, ID_IMAGE_SOURCE);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
// add layer
|
||||
RasterLayer layer = new RasterLayer(ID_IMAGE_LAYER, ID_IMAGE_SOURCE);
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
|
||||
// loop refresh geojson
|
||||
handler = new Handler();
|
||||
runnable = new RefreshImageRunnable(mapboxMap, handler);
|
||||
handler.postDelayed(runnable, 100);
|
||||
// loop refresh geojson
|
||||
handler = new Handler();
|
||||
runnable = new RefreshImageRunnable(mapboxMap, handler);
|
||||
handler.postDelayed(runnable, 100);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -43,13 +43,14 @@ public class BuildingFillExtrusionActivity extends AppCompatActivity {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_building_layer);
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(map -> {
|
||||
mapboxMap = map;
|
||||
Style style = map.getStyle();
|
||||
setupBuildings(style);
|
||||
setupLight();
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> {
|
||||
setupBuildings(style);
|
||||
setupLight();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -74,18 +74,18 @@ public class CircleLayerActivity extends AppCompatActivity implements View.OnCli
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(map -> {
|
||||
mapboxMap = map;
|
||||
addBusStopSource();
|
||||
addBusStopCircleLayer();
|
||||
initFloatingActionButtons();
|
||||
isLoadingStyle = false;
|
||||
|
||||
mapboxMap.setStyle(Style.SATELLITE_STREETS, style -> {
|
||||
addBusStopSource();
|
||||
addBusStopCircleLayer();
|
||||
initFloatingActionButtons();
|
||||
isLoadingStyle = false;
|
||||
});
|
||||
});
|
||||
|
||||
mapView.addOnDidFinishLoadingStyleListener(new MapView.OnDidFinishLoadingStyleListener() {
|
||||
@Override
|
||||
public void onDidFinishLoadingStyle() {
|
||||
addBusStop();
|
||||
isLoadingStyle = false;
|
||||
}
|
||||
mapView.addOnDidFinishLoadingStyleListener(() -> {
|
||||
addBusStop();
|
||||
isLoadingStyle = false;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -219,7 +219,7 @@ public class CircleLayerActivity extends AppCompatActivity implements View.OnCli
|
||||
}
|
||||
|
||||
private void loadNewStyle() {
|
||||
mapboxMap.setStyleUrl(getNextStyle());
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl(getNextStyle()));
|
||||
}
|
||||
|
||||
private void addBusStop() {
|
||||
|
||||
@@ -47,51 +47,54 @@ public class CustomSpriteActivity extends AppCompatActivity {
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(map -> {
|
||||
mapboxMap = map;
|
||||
final FloatingActionButton fab = findViewById(R.id.fab);
|
||||
fab.setColorFilter(ContextCompat.getColor(CustomSpriteActivity.this, R.color.primary));
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
private Point point;
|
||||
map.getStyle(style -> {
|
||||
final FloatingActionButton fab = findViewById(R.id.fab);
|
||||
fab.setColorFilter(ContextCompat.getColor(CustomSpriteActivity.this, R.color.primary));
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (point == null) {
|
||||
Timber.i("First click -> Car");
|
||||
// Add an icon to reference later
|
||||
mapboxMap.getStyle().addImage(CUSTOM_ICON, BitmapFactory.decodeResource(getResources(), R.drawable.ic_car_top));
|
||||
private Point point;
|
||||
|
||||
// Add a source with a geojson point
|
||||
point = Point.fromLngLat(13.400972d, 52.519003d);
|
||||
source = new GeoJsonSource(
|
||||
"point",
|
||||
FeatureCollection.fromFeatures(new Feature[] {Feature.fromGeometry(point)})
|
||||
);
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (point == null) {
|
||||
Timber.i("First click -> Car");
|
||||
// Add an icon to reference later
|
||||
style.addImage(CUSTOM_ICON, BitmapFactory.decodeResource(getResources(), R.drawable.ic_car_top));
|
||||
|
||||
// Add a symbol layer that references that point source
|
||||
layer = new SymbolLayer("layer", "point");
|
||||
layer.setProperties(
|
||||
// Set the id of the sprite to use
|
||||
iconImage(CUSTOM_ICON),
|
||||
iconAllowOverlap(true),
|
||||
iconIgnorePlacement(true)
|
||||
);
|
||||
// Add a source with a geojson point
|
||||
point = Point.fromLngLat(13.400972d, 52.519003d);
|
||||
source = new GeoJsonSource(
|
||||
"point",
|
||||
FeatureCollection.fromFeatures(new Feature[] {Feature.fromGeometry(point)})
|
||||
);
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
|
||||
// lets add a circle below labels!
|
||||
mapboxMap.getStyle().addLayerBelow(layer, "waterway-label");
|
||||
// Add a symbol layer that references that point source
|
||||
layer = new SymbolLayer("layer", "point");
|
||||
layer.setProperties(
|
||||
// Set the id of the sprite to use
|
||||
iconImage(CUSTOM_ICON),
|
||||
iconAllowOverlap(true),
|
||||
iconIgnorePlacement(true)
|
||||
);
|
||||
|
||||
fab.setImageResource(R.drawable.ic_directions_car_black);
|
||||
} else {
|
||||
// Update point
|
||||
point = Point.fromLngLat(point.longitude() + 0.001,
|
||||
// lets add a circle below labels!
|
||||
mapboxMap.getStyle().addLayerBelow(layer, "waterway-label");
|
||||
|
||||
fab.setImageResource(R.drawable.ic_directions_car_black);
|
||||
} else {
|
||||
// Update point
|
||||
point = Point.fromLngLat(point.longitude() + 0.001,
|
||||
point.latitude() + 0.001);
|
||||
source.setGeoJson(FeatureCollection.fromFeatures(new Feature[] {Feature.fromGeometry(point)}));
|
||||
source.setGeoJson(FeatureCollection.fromFeatures(new Feature[] {Feature.fromGeometry(point)}));
|
||||
|
||||
// Move the camera as well
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(
|
||||
point.latitude(), point.longitude())));
|
||||
// Move the camera as well
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(
|
||||
point.latitude(), point.longitude())));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.FillLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
import com.mapbox.mapboxsdk.style.sources.Source;
|
||||
@@ -63,11 +64,13 @@ public class DataDrivenStyleActivity extends AppCompatActivity {
|
||||
// Store for later
|
||||
mapboxMap = map;
|
||||
|
||||
// Add a parks layer
|
||||
addParksLayer();
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> {
|
||||
// Add a parks layer
|
||||
addParksLayer();
|
||||
|
||||
// Add debug overlay
|
||||
setupDebugZoomView();
|
||||
// Add debug overlay
|
||||
setupDebugZoomView();
|
||||
});
|
||||
|
||||
// Center and Zoom (Amsterdam, zoomed to streets)
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(52.379189, 4.899431), 14));
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng
|
||||
import com.mapbox.mapboxsdk.maps.MapView
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap
|
||||
import com.mapbox.mapboxsdk.maps.Style
|
||||
import com.mapbox.mapboxsdk.style.layers.PropertyFactory.*
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource
|
||||
@@ -67,12 +68,13 @@ class DraggableMarkerActivity : AppCompatActivity() {
|
||||
mapView.getMapAsync { mapboxMap ->
|
||||
this.mapboxMap = mapboxMap
|
||||
|
||||
val style = mapboxMap.style
|
||||
|
||||
// Setting up markers icon, source and layer
|
||||
mapboxMap.getStyle().addImage(markerImageId, IconFactory.getInstance(this).defaultMarker().bitmap)
|
||||
style.addSource(source)
|
||||
style.addLayer(layer)
|
||||
mapboxMap.setStyle(
|
||||
Style.Builder()
|
||||
.fromUrl(Style.MAPBOX_STREETS)
|
||||
.withImage(markerImageId, IconFactory.getInstance(this).defaultMarker().bitmap)
|
||||
.withSource(source)
|
||||
.withLayer(layer)
|
||||
)
|
||||
|
||||
// Add initial markers
|
||||
addMarker(LatLng(52.407210, 16.924324))
|
||||
|
||||
@@ -9,13 +9,14 @@ import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.FillExtrusionLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.geojson.Polygon;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionColor;
|
||||
@@ -28,51 +29,50 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.fillExtrusionOpa
|
||||
public class FillExtrusionActivity extends AppCompatActivity {
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_fill_extrusion_layer);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(map -> {
|
||||
mapboxMap = map;
|
||||
List<List<Point>> lngLats = Arrays.asList(
|
||||
Arrays.asList(
|
||||
Point.fromLngLat(5.12112557888031, 52.09071040847704),
|
||||
Point.fromLngLat(5.121227502822875, 52.09053901776669),
|
||||
Point.fromLngLat(5.121484994888306, 52.090601641371805),
|
||||
Point.fromLngLat(5.1213884353637695, 52.090766439912635),
|
||||
Point.fromLngLat(5.12112557888031, 52.09071040847704)
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS, style -> {
|
||||
List<List<Point>> lngLats = Collections.singletonList(
|
||||
Arrays.asList(
|
||||
Point.fromLngLat(5.12112557888031, 52.09071040847704),
|
||||
Point.fromLngLat(5.121227502822875, 52.09053901776669),
|
||||
Point.fromLngLat(5.121484994888306, 52.090601641371805),
|
||||
Point.fromLngLat(5.1213884353637695, 52.090766439912635),
|
||||
Point.fromLngLat(5.12112557888031, 52.09071040847704)
|
||||
)
|
||||
);
|
||||
);
|
||||
|
||||
Polygon domTower = Polygon.fromLngLats(lngLats);
|
||||
Polygon domTower = Polygon.fromLngLats(lngLats);
|
||||
GeoJsonSource source = new GeoJsonSource("extrusion-source", domTower);
|
||||
style.addSource(source);
|
||||
|
||||
GeoJsonSource source = new GeoJsonSource("extrusion-source", domTower);
|
||||
map.getStyle().addSource(source);
|
||||
style.addLayer(
|
||||
new FillExtrusionLayer("extrusion-layer", source.getId())
|
||||
.withProperties(
|
||||
fillExtrusionHeight(40f),
|
||||
fillExtrusionOpacity(0.5f),
|
||||
fillExtrusionColor(Color.RED)
|
||||
)
|
||||
);
|
||||
|
||||
mapboxMap.getStyle().addLayer(
|
||||
new FillExtrusionLayer("extrusion-layer", source.getId())
|
||||
.withProperties(
|
||||
fillExtrusionHeight(40f),
|
||||
fillExtrusionOpacity(0.5f),
|
||||
fillExtrusionColor(Color.RED)
|
||||
)
|
||||
);
|
||||
|
||||
mapboxMap.animateCamera(
|
||||
CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition.Builder()
|
||||
.target(new LatLng(52.09071040847704, 5.12112557888031))
|
||||
.tilt(45.0)
|
||||
.zoom(18)
|
||||
.build()
|
||||
),
|
||||
10000
|
||||
);
|
||||
mapboxMap.animateCamera(
|
||||
CameraUpdateFactory.newCameraPosition(
|
||||
new CameraPosition.Builder()
|
||||
.target(new LatLng(52.09071040847704, 5.12112557888031))
|
||||
.tilt(45.0)
|
||||
.zoom(18)
|
||||
.build()
|
||||
),
|
||||
10000
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.expressions.Expression;
|
||||
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
|
||||
@@ -66,13 +67,19 @@ public class GeoJsonClusteringActivity extends AppCompatActivity {
|
||||
mapView.getMapAsync(map -> {
|
||||
mapboxMap = map;
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(37.7749, 122.4194), 0));
|
||||
mapboxMap.getStyle().addImage(
|
||||
"icon-id",
|
||||
BitmapUtils.getBitmapFromDrawable(getResources().getDrawable(R.drawable.ic_hearing_black_24dp)),
|
||||
true
|
||||
);
|
||||
// Add a clustered source with some layers
|
||||
addClusteredGeoJsonSource();
|
||||
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
|
||||
@Override
|
||||
public void onStyleLoaded(Style style) {
|
||||
style.addImage(
|
||||
"icon-id",
|
||||
BitmapUtils.getBitmapFromDrawable(getResources().getDrawable(R.drawable.ic_hearing_black_24dp)),
|
||||
true
|
||||
);
|
||||
// Add a clustered source with some layers
|
||||
addClusteredGeoJsonSource(style);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -129,10 +136,10 @@ public class GeoJsonClusteringActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private void addClusteredGeoJsonSource() {
|
||||
private void addClusteredGeoJsonSource(Style style) {
|
||||
// Add a clustered source
|
||||
try {
|
||||
mapboxMap.getStyle().addSource(
|
||||
style.addSource(
|
||||
new GeoJsonSource("earthquakes",
|
||||
new URL("https://www.mapbox.com/mapbox-gl-js/assets/earthquakes.geojson"),
|
||||
new GeoJsonOptions()
|
||||
@@ -169,7 +176,7 @@ public class GeoJsonClusteringActivity extends AppCompatActivity {
|
||||
)
|
||||
);
|
||||
unclustered.setFilter(has("mag"));
|
||||
mapboxMap.getStyle().addLayer(unclustered);
|
||||
style.addLayer(unclustered);
|
||||
|
||||
for (int i = 0; i < layers.length; i++) {
|
||||
// Add some nice circles
|
||||
@@ -189,7 +196,7 @@ public class GeoJsonClusteringActivity extends AppCompatActivity {
|
||||
lt(pointCount, literal(layers[i - 1][0]))
|
||||
)
|
||||
);
|
||||
mapboxMap.getStyle().addLayer(circles);
|
||||
style.addLayer(circles);
|
||||
}
|
||||
|
||||
// Add the count labels
|
||||
@@ -201,7 +208,7 @@ public class GeoJsonClusteringActivity extends AppCompatActivity {
|
||||
textIgnorePlacement(true),
|
||||
textAllowOverlap(true)
|
||||
);
|
||||
mapboxMap.getStyle().addLayer(count);
|
||||
style.addLayer(count);
|
||||
|
||||
|
||||
// Zoom out to start
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.support.v7.app.AppCompatActivity;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.LineLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonOptions;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
@@ -35,7 +36,6 @@ import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineWidth;
|
||||
public class GradientLineActivity extends AppCompatActivity implements OnMapReadyCallback {
|
||||
|
||||
public static final String LINE_SOURCE = "gradient";
|
||||
private MapboxMap mapboxMap;
|
||||
private MapView mapView;
|
||||
|
||||
@Override
|
||||
@@ -49,25 +49,25 @@ public class GradientLineActivity extends AppCompatActivity implements OnMapRead
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap map) {
|
||||
this.mapboxMap = map;
|
||||
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
try {
|
||||
String geoJson = ResourceUtils.readRawResource(GradientLineActivity.this, R.raw.test_line_gradient_feature);
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource(LINE_SOURCE, geoJson, new GeoJsonOptions().withLineMetrics(true)));
|
||||
mapboxMap.getStyle().addLayer(new LineLayer("gradient", LINE_SOURCE)
|
||||
.withProperties(
|
||||
lineGradient(interpolate(
|
||||
linear(), lineProgress(),
|
||||
stop(0f, rgb(0, 0, 255)),
|
||||
stop(0.5f, rgb(0, 255, 0)),
|
||||
stop(1f, rgb(255, 0, 0)))
|
||||
),
|
||||
lineColor(Color.RED),
|
||||
lineWidth(10.0f),
|
||||
lineCap(LINE_CAP_ROUND),
|
||||
lineJoin(LINE_JOIN_ROUND)
|
||||
)
|
||||
mapboxMap.setStyle(new Style.Builder()
|
||||
.fromJson(geoJson)
|
||||
.withSource(new GeoJsonSource(LINE_SOURCE, geoJson, new GeoJsonOptions().withLineMetrics(true)))
|
||||
.withLayer(new LineLayer("gradient", LINE_SOURCE)
|
||||
.withProperties(
|
||||
lineGradient(interpolate(
|
||||
linear(), lineProgress(),
|
||||
stop(0f, rgb(0, 0, 255)),
|
||||
stop(0.5f, rgb(0, 255, 0)),
|
||||
stop(1f, rgb(255, 0, 0)))
|
||||
),
|
||||
lineColor(Color.RED),
|
||||
lineWidth(10.0f),
|
||||
lineCap(LINE_CAP_ROUND),
|
||||
lineJoin(LINE_JOIN_ROUND)
|
||||
))
|
||||
);
|
||||
} catch (IOException exception) {
|
||||
Timber.e(exception);
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.LineLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.CustomGeometrySource;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeometryTileProvider;
|
||||
@@ -34,7 +35,6 @@ public class GridSourceActivity extends AppCompatActivity implements OnMapReadyC
|
||||
public static final String ID_GRID_LAYER = "grid_layer";
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
|
||||
// public for testing purposes
|
||||
public CustomGeometrySource source;
|
||||
@@ -102,19 +102,17 @@ public class GridSourceActivity extends AppCompatActivity implements OnMapReadyC
|
||||
|
||||
@Override
|
||||
public void onMapReady(@NonNull final MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
|
||||
// add source
|
||||
source = new CustomGeometrySource(ID_GRID_SOURCE, new GridProvider());
|
||||
mapboxMap.getStyle().addSource(source);
|
||||
|
||||
// add layer
|
||||
layer = new LineLayer(ID_GRID_LAYER, ID_GRID_SOURCE);
|
||||
layer.setProperties(
|
||||
lineColor(Color.parseColor("#000000"))
|
||||
);
|
||||
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
map.setStyle(new Style.Builder()
|
||||
.fromUrl(Style.MAPBOX_STREETS)
|
||||
.withLayer(layer)
|
||||
.withSource(source)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.HeatmapLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
@@ -53,13 +54,16 @@ public class HeatmapLayerActivity extends AppCompatActivity {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_heatmaplayer);
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(map -> {
|
||||
mapboxMap = map;
|
||||
addEarthquakeSource();
|
||||
addHeatmapLayer();
|
||||
addCircleLayer();
|
||||
|
||||
mapboxMap.setStyle(Style.DARK, style -> {
|
||||
addEarthquakeSource();
|
||||
addHeatmapLayer();
|
||||
addCircleLayer();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.HillshadeLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.RasterDemSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
@@ -33,10 +34,12 @@ public class HillshadeLayerActivity extends AppCompatActivity {
|
||||
mapboxMap = map;
|
||||
|
||||
RasterDemSource rasterDemSource = new RasterDemSource(SOURCE_ID, SOURCE_URL);
|
||||
mapboxMap.getStyle().addSource(rasterDemSource);
|
||||
|
||||
HillshadeLayer hillshadeLayer = new HillshadeLayer(LAYER_ID, SOURCE_ID);
|
||||
mapboxMap.getStyle().addLayerBelow(hillshadeLayer, LAYER_BELOW_ID);
|
||||
mapboxMap.setStyle(new Style.Builder()
|
||||
.fromUrl(Style.MAPBOX_STREETS)
|
||||
.withLayer(hillshadeLayer)
|
||||
.withSource(rasterDemSource)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.support.v7.app.AppCompatActivity;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
@@ -51,22 +52,27 @@ public class RealTimeGeoJsonActivity extends AppCompatActivity implements OnMapR
|
||||
public void onMapReady(@NonNull final MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
|
||||
// add source
|
||||
try {
|
||||
mapboxMap.getStyle().addSource(new GeoJsonSource(ID_GEOJSON_SOURCE, new URL(URL_GEOJSON_SOURCE)));
|
||||
} catch (MalformedURLException malformedUrlException) {
|
||||
Timber.e(malformedUrlException, "Invalid URL");
|
||||
}
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() {
|
||||
@Override
|
||||
public void onStyleLoaded(Style style) {
|
||||
// add source
|
||||
try {
|
||||
style.addSource(new GeoJsonSource(ID_GEOJSON_SOURCE, new URL(URL_GEOJSON_SOURCE)));
|
||||
} catch (MalformedURLException malformedUrlException) {
|
||||
Timber.e(malformedUrlException, "Invalid URL");
|
||||
}
|
||||
|
||||
// add layer
|
||||
SymbolLayer layer = new SymbolLayer(ID_GEOJSON_LAYER, ID_GEOJSON_SOURCE);
|
||||
layer.setProperties(iconImage("rocket-15"));
|
||||
mapboxMap.getStyle().addLayer(layer);
|
||||
// add layer
|
||||
SymbolLayer layer = new SymbolLayer(ID_GEOJSON_LAYER, ID_GEOJSON_SOURCE);
|
||||
layer.setProperties(iconImage("rocket-15"));
|
||||
style.addLayer(layer);
|
||||
|
||||
// loop refresh geojson
|
||||
handler = new Handler();
|
||||
runnable = new RefreshGeoJsonRunnable(mapboxMap, handler);
|
||||
handler.postDelayed(runnable, 2000);
|
||||
// loop refresh geojson
|
||||
handler = new Handler();
|
||||
runnable = new RefreshGeoJsonRunnable(mapboxMap, handler);
|
||||
handler.postDelayed(runnable, 2000);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,13 +7,13 @@ import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.geojson.FeatureCollection;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.FillLayer;
|
||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||
@@ -30,14 +30,13 @@ import com.mapbox.mapboxsdk.style.sources.TileSet;
|
||||
import com.mapbox.mapboxsdk.style.sources.VectorSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils;
|
||||
import timber.log.Timber;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.all;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.color;
|
||||
import static com.mapbox.mapboxsdk.style.expressions.Expression.eq;
|
||||
@@ -75,6 +74,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
private boolean styleLoaded;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -82,10 +82,9 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
setContentView(R.layout.activity_runtime_style);
|
||||
|
||||
// Initialize map as normal
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
|
||||
|
||||
mapView.getMapAsync(map -> {
|
||||
// Store for later
|
||||
mapboxMap = map;
|
||||
@@ -93,8 +92,12 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
// Center and Zoom (Amsterdam, zoomed to streets)
|
||||
mapboxMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(52.379189, 4.899431), 14));
|
||||
|
||||
// set custom transition
|
||||
mapboxMap.getStyle().setTransition(new TransitionOptions(250, 50));
|
||||
mapboxMap.setStyle(
|
||||
new Style.Builder()
|
||||
.fromUrl(Style.MAPBOX_STREETS)
|
||||
// set custom transition
|
||||
.withTransition(new TransitionOptions(250, 50)), style -> styleLoaded = true
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -148,6 +151,10 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (!styleLoaded) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_list_layers:
|
||||
listLayers();
|
||||
@@ -490,7 +497,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void styleFillFilterLayer() {
|
||||
mapboxMap.setStyleUrl("asset://fill_filter_style.json");
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl("asset://fill_filter_style.json"));
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(31, -100), 3));
|
||||
|
||||
Handler handler = new Handler(getMainLooper());
|
||||
@@ -518,7 +525,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void styleLineFilterLayer() {
|
||||
mapboxMap.setStyleUrl("asset://line_filter_style.json");
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl("asset://line_filter_style.json"));
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(40, -97), 5));
|
||||
|
||||
Handler handler = new Handler(getMainLooper());
|
||||
@@ -546,7 +553,7 @@ public class RuntimeStyleActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void styleNumericFillLayer() {
|
||||
mapboxMap.setStyleUrl("asset://numeric_filter_style.json");
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl("asset://numeric_filter_style.json"));
|
||||
mapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(40, -97), 5));
|
||||
|
||||
Handler handler = new Handler(getMainLooper());
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.CircleLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.VectorSource;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
@@ -33,8 +34,6 @@ public class RuntimeStyleTimingTestActivity extends AppCompatActivity {
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
RuntimeStyleTimingTestActivity.this.mapboxMap = mapboxMap;
|
||||
VectorSource museums = new VectorSource("museums_source", "mapbox://mapbox.2opop9hr");
|
||||
mapboxMap.getStyle().addSource(museums);
|
||||
|
||||
CircleLayer museumsLayer = new CircleLayer("museums", "museums_source");
|
||||
museumsLayer.setSourceLayer("museum-cusco");
|
||||
@@ -44,7 +43,11 @@ public class RuntimeStyleTimingTestActivity extends AppCompatActivity {
|
||||
circleColor(Color.argb(1, 55, 148, 179))
|
||||
);
|
||||
|
||||
mapboxMap.getStyle().addLayer(museumsLayer);
|
||||
VectorSource museums = new VectorSource("museums_source", "mapbox://mapbox.2opop9hr");
|
||||
mapboxMap.setStyle(new Style.Builder()
|
||||
.fromUrl(Style.MAPBOX_STREETS)
|
||||
.withSource(museums)
|
||||
.withLayer(museumsLayer));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.widget.Toast;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
import com.mapbox.mapboxsdk.testapp.utils.ResourceUtils;
|
||||
|
||||
@@ -78,7 +79,7 @@ public class StyleFileActivity extends AppCompatActivity {
|
||||
Timber.d("Read json, %s", json);
|
||||
MapboxMap mapboxMap = this.mapboxMap.get();
|
||||
if (mapboxMap != null) {
|
||||
mapboxMap.setStyleJson(json);
|
||||
mapboxMap.setStyle(new Style.Builder().fromJson(json));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -116,7 +117,7 @@ public class StyleFileActivity extends AppCompatActivity {
|
||||
// Actual file:// usage
|
||||
MapboxMap mapboxMap = this.mapboxMap.get();
|
||||
if (mapboxMap != null) {
|
||||
mapboxMap.setStyleUrl("file://" + cacheStyleFile.getAbsolutePath());
|
||||
mapboxMap.setStyle(new Style.Builder().fromUrl("file://" + cacheStyleFile.getAbsolutePath()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.style.layers.Property;
|
||||
import com.mapbox.mapboxsdk.style.layers.SymbolLayer;
|
||||
import com.mapbox.mapboxsdk.style.sources.GeoJsonSource;
|
||||
@@ -72,6 +73,7 @@ public class SymbolLayerActivity extends AppCompatActivity implements MapboxMap.
|
||||
private MapboxMap mapboxMap;
|
||||
private MapView mapView;
|
||||
private boolean initialFont;
|
||||
private boolean styleLoaded;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@@ -85,7 +87,6 @@ public class SymbolLayerActivity extends AppCompatActivity implements MapboxMap.
|
||||
.zoom(13)
|
||||
.build()
|
||||
);
|
||||
mapboxMapOptions.styleUrl("asset://streets.json");
|
||||
|
||||
// Create map programmatically, add to view hierarchy
|
||||
mapView = new MapView(this, mapboxMapOptions);
|
||||
@@ -97,50 +98,50 @@ public class SymbolLayerActivity extends AppCompatActivity implements MapboxMap.
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap mapboxMap) {
|
||||
this.mapboxMap = mapboxMap;
|
||||
|
||||
// Add a sdf image for the makers
|
||||
// image
|
||||
Drawable icLayersDrawable = getResources().getDrawable(R.drawable.ic_layers);
|
||||
Bitmap icLayersBitmap = BitmapUtils.getBitmapFromDrawable(icLayersDrawable);
|
||||
mapboxMap.getStyle().addImage(
|
||||
MARKER_ICON,
|
||||
icLayersBitmap,
|
||||
true
|
||||
);
|
||||
|
||||
// Add a source
|
||||
// source
|
||||
markerCollection = FeatureCollection.fromFeatures(new Feature[] {
|
||||
Feature.fromGeometry(Point.fromLngLat(4.91638, 52.35673), featureProperties("Marker 1")),
|
||||
Feature.fromGeometry(Point.fromLngLat(4.91638, 52.34673), featureProperties("Marker 2"))
|
||||
});
|
||||
mapboxMap.getStyle().addSource(geoJsonSource = new GeoJsonSource(MARKER_SOURCE, markerCollection));
|
||||
geoJsonSource = new GeoJsonSource(MARKER_SOURCE, markerCollection);
|
||||
|
||||
// Add the symbol-layer
|
||||
mapboxMap.getStyle().addLayer(
|
||||
new SymbolLayer(MARKER_LAYER, MARKER_SOURCE)
|
||||
.withProperties(
|
||||
iconImage(MARKER_ICON),
|
||||
iconIgnorePlacement(true),
|
||||
iconAllowOverlap(true),
|
||||
iconSize(switchCase(toBool(get(SELECTED_FEATURE_PROPERTY)), literal(3.0f), literal(1.0f))),
|
||||
iconAnchor(Property.ICON_ANCHOR_BOTTOM),
|
||||
iconColor(Color.RED),
|
||||
textField(
|
||||
format(
|
||||
formatEntry("this is", formatFontScale(0.75)),
|
||||
formatEntry(
|
||||
concat(literal("\n"), get(TITLE_FEATURE_PROPERTY)),
|
||||
formatFontScale(1.25),
|
||||
formatTextFont(new String[] {"DIN Offc Pro Bold", "Arial Unicode MS Regular"})
|
||||
)
|
||||
// layer
|
||||
SymbolLayer layer = new SymbolLayer(MARKER_LAYER, MARKER_SOURCE)
|
||||
.withProperties(
|
||||
iconImage(MARKER_ICON),
|
||||
iconIgnorePlacement(true),
|
||||
iconAllowOverlap(true),
|
||||
iconSize(switchCase(toBool(get(SELECTED_FEATURE_PROPERTY)), literal(3.0f), literal(1.0f))),
|
||||
iconAnchor(Property.ICON_ANCHOR_BOTTOM),
|
||||
iconColor(Color.RED),
|
||||
textField(
|
||||
format(
|
||||
formatEntry("this is", formatFontScale(0.75)),
|
||||
formatEntry(
|
||||
concat(literal("\n"), get(TITLE_FEATURE_PROPERTY)),
|
||||
formatFontScale(1.25),
|
||||
formatTextFont(new String[] {"DIN Offc Pro Bold", "Arial Unicode MS Regular"})
|
||||
)
|
||||
),
|
||||
textFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"}),
|
||||
textColor(Color.RED),
|
||||
textAllowOverlap(true),
|
||||
textIgnorePlacement(true),
|
||||
textAnchor(Property.TEXT_ANCHOR_TOP),
|
||||
textSize(10f)
|
||||
)
|
||||
)
|
||||
),
|
||||
textFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"}),
|
||||
textColor(Color.RED),
|
||||
textAllowOverlap(true),
|
||||
textIgnorePlacement(true),
|
||||
textAnchor(Property.TEXT_ANCHOR_TOP),
|
||||
textSize(10f)
|
||||
);
|
||||
|
||||
mapboxMap.setStyle(new Style.Builder()
|
||||
.fromUrl("asset://streets.json")
|
||||
.withImage(MARKER_ICON, icLayersBitmap)
|
||||
.withSource(geoJsonSource)
|
||||
.withLayer(layer),
|
||||
style -> styleLoaded = true
|
||||
);
|
||||
|
||||
// Set a click-listener so we can manipulate the map
|
||||
@@ -246,6 +247,10 @@ public class SymbolLayerActivity extends AppCompatActivity implements MapboxMap.
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (!styleLoaded) {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_toggle_text_size:
|
||||
toggleTextSize();
|
||||
|
||||
@@ -76,14 +76,16 @@ public class ZoomFunctionSymbolLayerActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_zoom_symbol_layer);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(map -> {
|
||||
mapboxMap = map;
|
||||
Style style = map.getStyle();
|
||||
updateSource(style);
|
||||
addLayer(style);
|
||||
map.addOnMapClickListener(mapClickListener);
|
||||
|
||||
map.setStyle(Style.MAPBOX_STREETS, style -> {
|
||||
updateSource(style);
|
||||
addLayer(style);
|
||||
map.addOnMapClickListener(mapClickListener);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import java.util.Locale;
|
||||
@@ -58,6 +59,8 @@ public class TextureViewAnimationActivity extends AppCompatActivity {
|
||||
mapView.getMapAsync(mapboxMap -> {
|
||||
TextureViewAnimationActivity.this.mapboxMap = mapboxMap;
|
||||
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
|
||||
setFpsView(mapboxMap);
|
||||
|
||||
// Animate the map view
|
||||
|
||||
@@ -1,290 +1,18 @@
|
||||
package com.mapbox.mapboxsdk.testapp.activity.textureview;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMapOptions;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.mapbox.mapboxsdk.style.layers.Layer;
|
||||
import com.mapbox.mapboxsdk.style.layers.Property;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.visibility;
|
||||
import com.mapbox.mapboxsdk.testapp.activity.maplayout.DebugModeActivity;
|
||||
|
||||
/**
|
||||
* Test activity showcasing the different debug modes and allows to cycle between the default map styles.
|
||||
*/
|
||||
public class TextureViewDebugModeActivity extends AppCompatActivity implements OnMapReadyCallback {
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
private ActionBarDrawerToggle actionBarDrawerToggle;
|
||||
private int currentStyleIndex = 0;
|
||||
private IdleListener idleListener;
|
||||
|
||||
private static final String[] STYLES = new String[] {
|
||||
Style.MAPBOX_STREETS,
|
||||
Style.OUTDOORS,
|
||||
Style.LIGHT,
|
||||
Style.DARK,
|
||||
Style.SATELLITE,
|
||||
Style.SATELLITE_STREETS,
|
||||
Style.TRAFFIC_DAY,
|
||||
Style.TRAFFIC_NIGHT
|
||||
};
|
||||
public class TextureViewDebugModeActivity extends DebugModeActivity implements OnMapReadyCallback {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_textureview_debug_mode);
|
||||
setupToolbar();
|
||||
setupMapView(savedInstanceState);
|
||||
setupDebugChangeView();
|
||||
setupStyleChangeView();
|
||||
}
|
||||
|
||||
private void setupToolbar() {
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setHomeButtonEnabled(true);
|
||||
|
||||
DrawerLayout drawerLayout = findViewById(R.id.drawer_layout);
|
||||
actionBarDrawerToggle = new ActionBarDrawerToggle(this,
|
||||
drawerLayout,
|
||||
R.string.navigation_drawer_open,
|
||||
R.string.navigation_drawer_close
|
||||
);
|
||||
actionBarDrawerToggle.setDrawerIndicatorEnabled(true);
|
||||
actionBarDrawerToggle.syncState();
|
||||
}
|
||||
}
|
||||
|
||||
private void setupMapView(Bundle savedInstanceState) {
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
|
||||
mapView.addOnDidFinishLoadingStyleListener(() -> {
|
||||
if (mapboxMap != null) {
|
||||
setupNavigationView(mapboxMap.getStyle().getLayers());
|
||||
}
|
||||
});
|
||||
|
||||
mapView.setTag(true);
|
||||
mapView.setStyleUrl(STYLES[currentStyleIndex]);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReady(@NonNull MapboxMap map) {
|
||||
mapboxMap = map;
|
||||
|
||||
setupNavigationView(mapboxMap.getStyle().getLayers());
|
||||
setupZoomView();
|
||||
setFpsView();
|
||||
}
|
||||
|
||||
private void setFpsView() {
|
||||
final TextView fpsView = findViewById(R.id.fpsView);
|
||||
mapboxMap.setOnFpsChangedListener(fps -> fpsView.setText(String.format(Locale.US, "FPS: %4.2f", fps)));
|
||||
}
|
||||
|
||||
private void setupNavigationView(List<Layer> layerList) {
|
||||
Timber.v("New style loaded with JSON: %s", mapboxMap.getStyleJson());
|
||||
final LayerListAdapter adapter = new LayerListAdapter(this, layerList);
|
||||
ListView listView = findViewById(R.id.listView);
|
||||
listView.setAdapter(adapter);
|
||||
listView.setOnItemClickListener((parent, view, position, id) -> {
|
||||
Layer clickedLayer = adapter.getItem(position);
|
||||
toggleLayerVisibility(clickedLayer);
|
||||
closeNavigationView();
|
||||
});
|
||||
}
|
||||
|
||||
private void toggleLayerVisibility(Layer layer) {
|
||||
boolean isVisible = layer.getVisibility().getValue().equals(Property.VISIBLE);
|
||||
layer.setProperties(
|
||||
visibility(
|
||||
isVisible ? Property.NONE : Property.VISIBLE
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private void closeNavigationView() {
|
||||
DrawerLayout drawerLayout = findViewById(R.id.drawer_layout);
|
||||
drawerLayout.closeDrawers();
|
||||
}
|
||||
|
||||
private void setupZoomView() {
|
||||
final TextView textView = findViewById(R.id.textZoom);
|
||||
mapboxMap.addOnCameraIdleListener(idleListener = new IdleListener(mapboxMap, textView));
|
||||
}
|
||||
|
||||
private void setupDebugChangeView() {
|
||||
FloatingActionButton fabDebug = findViewById(R.id.fabDebug);
|
||||
fabDebug.setOnClickListener(view -> {
|
||||
if (mapboxMap != null) {
|
||||
Timber.d("Debug FAB: isDebug Active? %s", mapboxMap.isDebugActive());
|
||||
mapboxMap.cycleDebugOptions();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void setupStyleChangeView() {
|
||||
mapView.addOnDidFinishLoadingStyleListener(() -> Timber.d("Style loaded"));
|
||||
|
||||
FloatingActionButton fabStyles = findViewById(R.id.fabStyles);
|
||||
fabStyles.setOnClickListener(view -> {
|
||||
if (mapboxMap != null) {
|
||||
currentStyleIndex++;
|
||||
if (currentStyleIndex == STYLES.length) {
|
||||
currentStyleIndex = 0;
|
||||
}
|
||||
mapboxMap.setStyleUrl(STYLES[currentStyleIndex]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
return actionBarDrawerToggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
mapView.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
mapView.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
mapView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
mapView.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mapboxMap != null && idleListener != null) {
|
||||
mapboxMap.removeOnCameraIdleListener(idleListener);
|
||||
}
|
||||
mapView.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
mapView.onLowMemory();
|
||||
}
|
||||
|
||||
private static class LayerListAdapter extends BaseAdapter {
|
||||
|
||||
private LayoutInflater layoutInflater;
|
||||
private List<Layer> layers;
|
||||
|
||||
LayerListAdapter(Context context, List<Layer> layers) {
|
||||
this.layoutInflater = LayoutInflater.from(context);
|
||||
this.layers = layers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return layers.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Layer getItem(int position) {
|
||||
return layers.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
Layer layer = layers.get(position);
|
||||
View view = convertView;
|
||||
if (view == null) {
|
||||
view = layoutInflater.inflate(android.R.layout.simple_list_item_2, parent, false);
|
||||
ViewHolder holder = new ViewHolder(
|
||||
view.findViewById(android.R.id.text1),
|
||||
view.findViewById(android.R.id.text2)
|
||||
);
|
||||
view.setTag(holder);
|
||||
}
|
||||
ViewHolder holder = (ViewHolder) view.getTag();
|
||||
holder.text.setText(layer.getClass().getSimpleName());
|
||||
holder.subText.setText(layer.getId());
|
||||
return view;
|
||||
}
|
||||
|
||||
private static class ViewHolder {
|
||||
final TextView text;
|
||||
final TextView subText;
|
||||
|
||||
ViewHolder(TextView text, TextView subText) {
|
||||
this.text = text;
|
||||
this.subText = subText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class IdleListener implements MapboxMap.OnCameraIdleListener {
|
||||
|
||||
private MapboxMap mapboxMap;
|
||||
private TextView textView;
|
||||
|
||||
IdleListener(MapboxMap mapboxMap, TextView textView) {
|
||||
this.mapboxMap = mapboxMap;
|
||||
this.textView = textView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCameraIdle() {
|
||||
Context context = textView.getContext();
|
||||
CameraPosition position = mapboxMap.getCameraPosition();
|
||||
textView.setText(String.format(context.getString(R.string.debug_zoom), position.zoom));
|
||||
}
|
||||
protected MapboxMapOptions setupMapboxMapOptions() {
|
||||
MapboxMapOptions mapboxMapOptions = super.setupMapboxMapOptions();
|
||||
mapboxMapOptions.textureMode(true);
|
||||
return mapboxMapOptions;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import android.view.View;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Style;
|
||||
import com.mapbox.mapboxsdk.testapp.R;
|
||||
|
||||
/**
|
||||
@@ -17,7 +18,6 @@ import com.mapbox.mapboxsdk.testapp.R;
|
||||
public class TextureViewResizeActivity extends AppCompatActivity {
|
||||
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -37,12 +37,17 @@ public class TextureViewResizeActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void setupMapView(Bundle savedInstanceState) {
|
||||
mapView = (MapView) findViewById(R.id.mapView);
|
||||
mapView.getMapAsync(mapboxMap -> TextureViewResizeActivity.this.mapboxMap = mapboxMap);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(this::setupMap);
|
||||
}
|
||||
|
||||
private void setupMap(MapboxMap mapboxMap) {
|
||||
mapboxMap.setStyle(Style.MAPBOX_STREETS);
|
||||
}
|
||||
|
||||
private void setupFab() {
|
||||
FloatingActionButton fabDebug = (FloatingActionButton) findViewById(R.id.fabResize);
|
||||
FloatingActionButton fabDebug = findViewById(R.id.fabResize);
|
||||
fabDebug.setOnClickListener(view -> {
|
||||
if (mapView != null) {
|
||||
View parent = findViewById(R.id.coordinator_layout);
|
||||
|
||||
@@ -16,14 +16,6 @@
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@+id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:mapbox_uiAttribution="false"
|
||||
app:mapbox_uiCompass="false"
|
||||
app:mapbox_uiLogo="false"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textZoom"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
app:mapbox_cameraTargetLng="7.497989"
|
||||
app:mapbox_cameraZoom="9"
|
||||
app:mapbox_cameraBearing="140"
|
||||
app:mapbox_cameraTilt="60"
|
||||
app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"/>
|
||||
app:mapbox_cameraTilt="60"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@@ -7,5 +7,4 @@
|
||||
android:layout_height="match_parent"
|
||||
app:mapbox_cameraTargetLat="45.38301927899065"
|
||||
app:mapbox_cameraTargetLng="8.63525390625"
|
||||
app:mapbox_cameraZoom="7"
|
||||
app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"/>
|
||||
app:mapbox_cameraZoom="7"/>
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:mapbox_styleUrl="@string/mapbox_style_dark"/>
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
android:id="@id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"
|
||||
app:mapbox_localIdeographFontFamily="Droid Sans" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"
|
||||
app:mapbox_uiAttribution="false" />
|
||||
|
||||
<LinearLayout
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
<View
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/viewParent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context=".activity.maplayout.SimpleMapActivity">
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/viewParent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context=".activity.maplayout.SimpleMapActivity">
|
||||
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@id/mapView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"
|
||||
android:visibility="invisible"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
android:layout_gravity="end|bottom"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
android:src="@drawable/ic_print"
|
||||
app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"
|
||||
app:backgroundTint="@color/accent"/>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
android:layout_height="match_parent"
|
||||
app:mapbox_cameraTargetLat="52.0907"
|
||||
app:mapbox_cameraTargetLng="5.1214"
|
||||
app:mapbox_cameraZoom="16"/>
|
||||
app:mapbox_cameraZoom="16"
|
||||
app:mapbox_styleUrl="@string/mapbox_style_mapbox_streets"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
Reference in New Issue
Block a user