Skip to content

Commit

Permalink
[MAPSAND-985] Expose lights3d as public api (#1744)
Browse files Browse the repository at this point in the history
* update stylegen to main

* update-api

* expose lights3d public

* update apis and tests

* publish_android_snapshot

* publish_android_snapshot

* rebase develop and update api

---------

Co-authored-by: Tobrun Van Nuland <tobrun.van.nuland@gmail.com>
  • Loading branch information
ank27 and tobrun authored Jun 2, 2023
1 parent 61d8d77 commit 7971a33
Show file tree
Hide file tree
Showing 10 changed files with 2,644 additions and 33 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ Mapbox welcomes participation and contributions from everyone.
* Introduce Expression overload functions `linearInterpolator`, `exponentialInterpolator`, `cubicBezierInterpolator`, `step`, `match` and `switchCase` to construct these expressions with strongly typed parameters.
* Introduce `ImageExtensionImpl.Builder(imageId, image)`, `ImageExtensionImpl.Builder(imageId, image)` constructors and deprecated `ImageExtensionImpl.Builder(imageId)`, `ImageExtensionImpl.Builder.image(image)`, `ImageExtensionImpl.Builder.bitmap(bitmap)`, as image/bitmap is required for `ImageExtensionImpl.Builder`; DSL functions are updated to reflect these changes as well.
* Deprecate `PointAnnotationManager.iconTextFit` and `PointAnnotationManager.iconTextFitPadding` in favor of `PointAnnotation.iconTextFit` and `PointAnnotation.iconTextFitPadding`.
* Introduce experimental lights API to enable a uniform 3D lighting across the map. Use `Style.addLights3D` or `Style.setup3DLights` to enable `Ambient` and `Directional` light.
* Remove experimental `castShadows`, `shadowIntensity` methods from `Light`.

## Bug fixes 🐞
* Fix 3d location layer properties `model-scale-transition` and `model-rotation-transition`, made them non-transitionable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.mapbox.geojson.Point
import com.mapbox.maps.CameraOptions
import com.mapbox.maps.MapboxExperimental
import com.mapbox.maps.Style
import com.mapbox.maps.extension.style.expressions.generated.Expression.Companion.eq
import com.mapbox.maps.extension.style.expressions.generated.Expression.Companion.get
import com.mapbox.maps.extension.style.expressions.generated.Expression.Companion.literal
import com.mapbox.maps.extension.style.layers.addLayer
import com.mapbox.maps.extension.style.layers.generated.FillExtrusionLayer
import com.mapbox.maps.extension.style.light.generated.getLight
import com.mapbox.maps.extension.style.light.addLights3D
import com.mapbox.maps.extension.style.light.generated.ambientLight
import com.mapbox.maps.extension.style.light.generated.directionalLight
import com.mapbox.maps.testapp.databinding.ActivityFillExtrusionBinding

/**
* Extrude the building layer in the Mapbox Light style using FillExtrusionLayer
* and set up the light position.
*/
@OptIn(MapboxExperimental::class)
class FillExtrusionActivity : AppCompatActivity() {

private var isRedColor: Boolean = false
Expand All @@ -29,7 +33,6 @@ class FillExtrusionActivity : AppCompatActivity() {
binding = ActivityFillExtrusionBinding.inflate(layoutInflater)
setContentView(binding.root)
val mapboxMap = binding.mapView.getMapboxMap()

mapboxMap.setCamera(
CameraOptions.Builder()
.center(Point.fromLngLat(-74.0066, 40.7135))
Expand All @@ -43,7 +46,40 @@ class FillExtrusionActivity : AppCompatActivity() {
Style.LIGHT
) { style ->
setupBuildings(style)
setupLight(style)
setupLights3D(style)
}
}

private fun setupLights3D(style: Style) {
// setup 3d light
val ambientLight = ambientLight(AMBIENT_LIGHT_ID) {
color(Color.BLUE)
intensity(0.9)
}
val directionalLight = directionalLight(DIRECTIONAL_LIGHT_ID) {
color(Color.YELLOW)
intensity(0.9)
castShadows(true)
direction(listOf(0.0, 15.0))
}
style.addLights3D(
listOf(
ambientLight,
directionalLight,
)
)
// change color on fab click
binding.fabLightColor.setOnClickListener {
isRedColor = !isRedColor
if (isRedColor) {
ambientLight.color(Color.RED)
} else {
ambientLight.color(Color.BLUE)
}
}

binding.fabLightPosition.setOnClickListener {
directionalLight.direction(listOf(0.0, (directionalLight.direction!![1] + 5.0) % 90.0))
}
}

Expand All @@ -61,24 +97,8 @@ class FillExtrusionActivity : AppCompatActivity() {
style.addLayer(fillExtrusionLayer)
}

private fun setupLight(style: Style) {
val light = style.getLight()
binding.fabLightPosition.setOnClickListener {
isInitPosition = !isInitPosition
if (isInitPosition) {
light.position(1.5, 90.0, 80.0)
} else {
light.position(1.15, 210.0, 30.0)
}
}

binding.fabLightColor.setOnClickListener {
isRedColor = !isRedColor
if (isRedColor) {
light.color(Color.RED)
} else {
light.color(Color.BLUE)
}
}
private companion object {
private const val AMBIENT_LIGHT_ID = "ambient_id"
private const val DIRECTIONAL_LIGHT_ID = "directional_id"
}
}
Loading

0 comments on commit 7971a33

Please sign in to comment.