Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sdk] rework event API #18

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,16 @@ abstract class BaseMapTest {

protected open fun loadMap() {
val latch = CountDownLatch(1)
rule.scenario.onActivity {
it.runOnUiThread {
rule.scenario.onActivity { activity ->
activity.runOnUiThread {
mapboxMap = mapView.getMapboxMap()
mapboxMap.loadStyleUri(
Style.MAPBOX_STREETS
) { style ->
this@BaseMapTest.style = style
latch.countDown()
}
Style.MAPBOX_STREETS,
{
this@BaseMapTest.style = it
latch.countDown()
}
)
mapView.onStart()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,37 +53,43 @@ class LocationComponentTest {
fun modelSourceTest() {
rule.scenario.onActivity { activity ->
activity.runOnUiThread {
mapboxMap.loadStyleUri(Style.MAPBOX_STREETS) {
val locationComponent = mapView.getLocationPlugin()
locationComponent.activateLocationComponent(
LocationComponentActivationOptions
.builder(activity, it)
.useDefaultLocationEngine(false)
.locationModelLayerOptions(LocationModelLayerOptions("asset://race_car_model.gltf"))
.build()
)
locationComponent.enabled = true
locationComponent.randomLocationUpdates()
Handler().postDelayed(
{
locationComponent.randomLocationUpdates()
mapboxMap.loadStyleUri(Style.DARK) {
mapboxMap.loadStyleUri(
Style.MAPBOX_STREETS,
{
val locationComponent = mapView.getLocationPlugin()
locationComponent.activateLocationComponent(
LocationComponentActivationOptions
.builder(activity, it)
.useDefaultLocationEngine(false)
.locationModelLayerOptions(LocationModelLayerOptions("asset://race_car_model.gltf"))
.build()
)
locationComponent.enabled = true
locationComponent.randomLocationUpdates()
Handler().postDelayed(
{
locationComponent.randomLocationUpdates()
Handler().postDelayed(
mapboxMap.loadStyleUri(
Style.DARK,
{
locationComponent.randomLocationUpdates()
countDownLatch.countDown()
},
500
Handler().postDelayed(
{
locationComponent.randomLocationUpdates()
countDownLatch.countDown()
},
500
)
locationComponent.randomLocationUpdates()
}
)
locationComponent.randomLocationUpdates()
}
locationComponent.randomLocationUpdates()
},
500
)
locationComponent.randomLocationUpdates()
}
},
500
)
locationComponent.randomLocationUpdates()
}
)
}
}
countDownLatch = CountDownLatch(1)
Expand All @@ -96,36 +102,42 @@ class LocationComponentTest {
fun locationLayerTest() {
rule.scenario.onActivity { activity ->
activity.runOnUiThread {
mapboxMap.loadStyleUri(Style.MAPBOX_STREETS) {
val locationComponent = mapView.getLocationPlugin()
locationComponent.activateLocationComponent(
LocationComponentActivationOptions
.builder(activity, it)
.useDefaultLocationEngine(false)
.build()
)
locationComponent.enabled = true
locationComponent.randomLocationUpdates()
Handler().postDelayed(
{
locationComponent.randomLocationUpdates()
mapboxMap.loadStyleUri(Style.DARK) {
mapboxMap.loadStyleUri(
Style.MAPBOX_STREETS,
{
val locationComponent = mapView.getLocationPlugin()
locationComponent.activateLocationComponent(
LocationComponentActivationOptions
.builder(activity, it)
.useDefaultLocationEngine(false)
.build()
)
locationComponent.enabled = true
locationComponent.randomLocationUpdates()
Handler().postDelayed(
{
locationComponent.randomLocationUpdates()
Handler().postDelayed(
mapboxMap.loadStyleUri(
Style.DARK,
{
locationComponent.randomLocationUpdates()
countDownLatch.countDown()
},
500
Handler().postDelayed(
{
locationComponent.randomLocationUpdates()
countDownLatch.countDown()
},
500
)
locationComponent.randomLocationUpdates()
}
)
locationComponent.randomLocationUpdates()
}
locationComponent.randomLocationUpdates()
},
500
)
locationComponent.randomLocationUpdates()
}
},
500
)
locationComponent.randomLocationUpdates()
}
)
}
}
countDownLatch = CountDownLatch(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ class AnimateMapCameraActivity : AppCompatActivity(), OnMapClickListener {
setContentView(R.layout.activity_camera_animate)
mapboxMap = mapView.getMapboxMap()
mapboxMap.loadStyleUri(
Style.MAPBOX_STREETS
) { // Toast instructing user to tap on the map
Toast.makeText(
this@AnimateMapCameraActivity,
getString(R.string.tap_on_map_instruction),
Toast.LENGTH_LONG
).show()
mapboxMap.addOnMapClickListener(this@AnimateMapCameraActivity)
}
Style.MAPBOX_STREETS,
{
// Toast instructing user to tap on the map
Toast.makeText(
this@AnimateMapCameraActivity,
getString(R.string.tap_on_map_instruction),
Toast.LENGTH_LONG
).show()
mapboxMap.addOnMapClickListener(this@AnimateMapCameraActivity)
}
)
}

override fun onMapClick(point: Point): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ class BasicLocationPulsingCircleActivity : AppCompatActivity() {

private fun onMapReady() {
mapboxMap.loadStyleUri(
Style.MAPBOX_STREETS
) {
initLocationComponent(it)
lastStyleUri = it.styleURI
}
Style.MAPBOX_STREETS,
{
initLocationComponent(it)
lastStyleUri = it.styleURI
}
)
}

private fun initLocationComponent(style: Style) {
Expand Down Expand Up @@ -131,8 +132,8 @@ class BasicLocationPulsingCircleActivity : AppCompatActivity() {
private fun loadNewStyle() {
val styleUrl = if (lastStyleUri == Style.DARK) Style.LIGHT else Style.DARK
mapboxMap.loadStyleUri(
styleUrl
) { lastStyleUri = styleUrl }
styleUrl, { lastStyleUri = styleUrl }
)
}

override fun onRequestPermissionsResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,39 +35,40 @@ class CircleLayerClusteringActivity : AppCompatActivity() {
val mapboxMap = mapView.getMapboxMap()

mapboxMap.loadStyleUri(
Style.LIGHT
) {
// Disable any type of fading transition when icons collide on the map. This enhances the visual
// look of the data clustering together and breaking apart.
it.styleTransition = TransitionOptions.Builder()
.duration(0)
.delay(0)
.enablePlacementTransitions(false)
.build()

mapboxMap.flyTo(
CameraOptions.Builder()
.center(Point.fromLngLat(-79.045, 12.099))
.zoom(3.0)
Style.LIGHT,
{
// Disable any type of fading transition when icons collide on the map. This enhances the visual
// look of the data clustering together and breaking apart.
it.styleTransition = TransitionOptions.Builder()
.duration(0)
.delay(0)
.enablePlacementTransitions(false)
.build()
)

addClusteredGeoJsonSource(it)
mapboxMap.flyTo(
CameraOptions.Builder()
.center(Point.fromLngLat(-79.045, 12.099))
.zoom(3.0)
.build()
)

val drawable = ContextCompat.getDrawable(
this@CircleLayerClusteringActivity,
R.drawable.ic_cross
)
BitmapUtils.getBitmapFromDrawable(drawable)?.let { bitmap ->
it.addImage(CROSS_ICON_ID, bitmap, true)
}
addClusteredGeoJsonSource(it)

Toast.makeText(
this@CircleLayerClusteringActivity,
R.string.zoom_map_in_and_out_instruction,
Toast.LENGTH_SHORT
).show()
}
val drawable = ContextCompat.getDrawable(
this@CircleLayerClusteringActivity,
R.drawable.ic_cross
)
BitmapUtils.getBitmapFromDrawable(drawable)?.let { bitmap ->
it.addImage(CROSS_ICON_ID, bitmap, true)
}

Toast.makeText(
this@CircleLayerClusteringActivity,
R.string.zoom_map_in_and_out_instruction,
Toast.LENGTH_SHORT
).show()
}
)
}

private fun addClusteredGeoJsonSource(style: Style) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ class FillExtrusionActivity : AppCompatActivity() {
)

mapboxMap.loadStyleUri(
Style.MAPBOX_STREETS
) { style ->
setupBuildings(style)
setupLight(style)
}
Style.MAPBOX_STREETS,
{
setupBuildings(it)
setupLight(it)
}
)
}

private fun setupBuildings(style: Style) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class HeatmapLayerActivity : AppCompatActivity() {

mapboxMap = mapView.getMapboxMap()
mapboxMap.loadStyleUri(
styleUri = Style.DARK
) { style -> addRuntimeLayers(style) }
styleUri = Style.DARK, { style -> addRuntimeLayers(style) }
)
}

private fun addRuntimeLayers(style: Style) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import com.mapbox.maps.extension.style.sources.addSource
import com.mapbox.maps.extension.style.sources.generated.GeoJsonSource
import com.mapbox.maps.extension.style.sources.generated.geoJsonSource
import com.mapbox.maps.extension.style.sources.getSource
import com.mapbox.maps.listener.OnCameraChangeListener
import com.mapbox.maps.plugin.animation.MapAnimationOptions.Companion.mapAnimationOptions
import com.mapbox.maps.plugin.animation.flyTo
import com.mapbox.maps.plugin.attribution.getAttributionPlugin
import com.mapbox.maps.plugin.compass.getCompassPlugin
import com.mapbox.maps.plugin.delegates.listeners.OnCameraChangeListener
import com.mapbox.maps.plugin.gestures.getGesturesPlugin
import com.mapbox.maps.plugin.logo.getLogoPlugin
import com.mapbox.maps.plugin.scalebar.getScaleBarPlugin
Expand All @@ -41,8 +41,8 @@ class InsetMapActivity : AppCompatActivity(), OnCameraChangeListener {
mainMapView = findViewById(R.id.mapView)
mainMapboxMap = mainMapView.getMapboxMap()
mainMapboxMap.loadStyleUri(
styleUri = STYLE_URL
) { mainMapboxMap.addOnCameraChangeListener(this@InsetMapActivity) }
styleUri = STYLE_URL, { mainMapboxMap.addOnCameraChangeListener(this@InsetMapActivity) }
)

var insetMapFragment: MapFragment? =
supportFragmentManager.findFragmentByTag(INSET_FRAGMENT_TAG) as? MapFragment
Expand All @@ -54,24 +54,25 @@ class InsetMapActivity : AppCompatActivity(), OnCameraChangeListener {
insetMapFragment.getMapAsync {
insetMapboxMap = it
insetMapboxMap.loadStyleUri(
styleUri = STYLE_URL
) { style ->
val source = geoJsonSource(BOUNDS_LINE_LAYER_SOURCE_ID) {
feature(Feature.fromGeometry(LineString.fromLngLats(getRectanglePoints())))
}
style.addSource(source)

// The layer properties for our line. This is where we make the line dotted, set the color, etc.
val layer = lineLayer(BOUNDS_LINE_LAYER_LAYER_ID, BOUNDS_LINE_LAYER_SOURCE_ID) {
lineCap(LineCap.ROUND)
lineJoin(LineJoin.ROUND)
lineWidth(3.0)
lineColor(Color.YELLOW)
visibility(Visibility.VISIBLE)
styleUri = STYLE_URL,
{ style ->
val source = geoJsonSource(BOUNDS_LINE_LAYER_SOURCE_ID) {
feature(Feature.fromGeometry(LineString.fromLngLats(getRectanglePoints())))
}
style.addSource(source)

// The layer properties for our line. This is where we make the line dotted, set the color, etc.
val layer = lineLayer(BOUNDS_LINE_LAYER_LAYER_ID, BOUNDS_LINE_LAYER_SOURCE_ID) {
lineCap(LineCap.ROUND)
lineJoin(LineJoin.ROUND)
lineWidth(3.0)
lineColor(Color.YELLOW)
visibility(Visibility.VISIBLE)
}
style.addLayer(layer)
updateInsetMapLineLayerBounds(style)
}
style.addLayer(layer)
updateInsetMapLineLayerBounds(style)
}
)
insetMapFragment.getMapView()?.apply {
getLogoPlugin().enabled = false
getScaleBarPlugin().enabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ class LineGradientActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_line_gradient)
mapView.getMapboxMap().loadStyle(createStyle()) {
Logger.d(TAG, "Style loaded: ${it.styleURI}")
}
mapView.getMapboxMap()
.loadStyle(createStyle()) { style ->
Logger.d(TAG, "Style loaded: ${style.styleURI}")
}
}

private fun createStyle() = style(styleUri = Style.TRAFFIC_DAY) {
Expand Down
Loading