Skip to content

Commit

Permalink
Update glnative to v11.9.0-rc.1 and add precipitations API and exampl…
Browse files Browse the repository at this point in the history
…e. (#2874)
  • Loading branch information
pengdev authored Dec 9, 2024
1 parent a63644b commit e76cdca
Show file tree
Hide file tree
Showing 41 changed files with 7,478 additions and 16 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,20 @@
Mapbox welcomes participation and contributions from everyone.

# 11.9.0-rc.1

## Features ✨ and improvements 🏁
* Add `toHsla` expression.
* Introduce experimental `Snow` and `Rain` APIs to show the snow or rain effect on the map.
* [compose] Introduce experimental `SnowState` and `RainState` APIs to show the snow or rain effect on the map.

## Bug fixes 🐞
* Improve character spacing for text offsets.
* Fixed crash on Android API level < 26.
* Do not load vector icons for client-provided sprites.
* Fall back to the feature's original ID when promoteId is an object and the source layer is not specified as a key in the object.
* Fixed crash caused by a repeated command buffer commit call.

## Dependencies
* Update gl-native to v11.9.0-rc.1 and common to v24.9.0-rc.1.

# 11.8.1 December 03, 2024
## Bug fixes 🐞
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ License: [The Apache Software License, Version 2.0](http://www.apache.org/licens

===========================================================================

### MapboxCoreMaps,11.10.0-beta.1,Mapbox ToS,Mapbox,https://www.mapbox.com/
### MapboxCoreMaps,11.9.0-rc.1,Mapbox ToS,Mapbox,https://www.mapbox.com/

```
Mapbox Core Maps version 11.0
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1414,5 +1414,17 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".ExampleOverviewActivity" />
</activity>
<activity
android:name=".examples.style.PrecipitationActivity"
android:description="@string/description_precipitation"
android:exported="true"
android:label="@string/activity_precipitation">
<meta-data
android:name="@string/category"
android:value="@string/category_styles" />
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".ExampleOverviewActivity" />
</activity>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.mapbox.maps.testapp.examples.style

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.precipitations.generated.rain
import com.mapbox.maps.extension.style.precipitations.generated.removeRain
import com.mapbox.maps.extension.style.precipitations.generated.removeSnow
import com.mapbox.maps.extension.style.precipitations.generated.setRain
import com.mapbox.maps.extension.style.precipitations.generated.setSnow
import com.mapbox.maps.extension.style.precipitations.generated.snow
import com.mapbox.maps.extension.style.style
import com.mapbox.maps.testapp.databinding.ActivityPrecipitationsBinding

/**
* Showcase snow and rain effect.
*/
@OptIn(MapboxExperimental::class)
class PrecipitationActivity : AppCompatActivity() {

private var isSnowing: Boolean = true
private var isRaining: Boolean = true
private val rain = rain {
intensity(0.6)
opacity(0.5)
vignette(0.5)
}
private val snow = snow {
intensity(0.6)
opacity(0.5)
vignette(0.5)
}
private lateinit var binding: ActivityPrecipitationsBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityPrecipitationsBinding.inflate(layoutInflater)
setContentView(binding.root)
val mapboxMap = binding.mapView.mapboxMap
mapboxMap.setCamera(
CameraOptions.Builder()
.center(Point.fromLngLat(24.943849, 60.171924))
.bearing(-17.6)
.pitch(45.0)
.zoom(16.0)
.build()
)

mapboxMap.loadStyle(
style(Style.STANDARD) {
+snow
+rain
}
)

// change snow intensity on fab click
binding.toggleSnow.setOnClickListener {
isSnowing = !isSnowing
if (isSnowing) {
mapboxMap.setSnow(snow)
} else {
mapboxMap.removeSnow()
}
}

binding.toggleRain.setOnClickListener {
isRaining = !isRaining
if (isRaining) {
mapboxMap.setRain(rain)
} else {
mapboxMap.removeRain()
}
}
}
}
35 changes: 35 additions & 0 deletions app/src/main/res/layout/activity_precipitations.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<com.mapbox.maps.MapView
android:id="@id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/toggle_rain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_marginEnd="16dp"
android:layout_marginBottom="82dp"
android:text="Toggle rain"
app:backgroundTint="@color/accent"
app:layout_anchorGravity="top"
tools:ignore="HardcodedText" />

<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/toggle_snow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="16dp"
android:text="Toggle snow"
app:backgroundTint="@color/primary"
tools:ignore="HardcodedText" />

</FrameLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values/example_descriptions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,5 @@
<string name="description_clip_layer">Showcase the usage of clip layer.</string>
<string name="description_standard_interactions">Showcase of the Standard Style interactions.</string>
<string name="description_location_component_model_animation">Animate 3D location puck on the map</string>
<string name="description_precipitation">Showcase rain and snow effects.</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/example_titles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,5 @@
<string name="activity_clip_layer">Clip layer example</string>
<string name="activity_standard_interactions">Standard Style interactions</string>
<string name="activity_location_component_model_animation">Location component model animation</string>
<string name="activity_precipitation">Precipitations example</string>
</resources>
10 changes: 10 additions & 0 deletions compose-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,16 @@
android:name="@string/category"
android:value="@string/category_styles" />
</activity>
<activity
android:name=".examples.style.PrecipitationsActivity"
android:description="@string/description_precipitations"
android:exported="true"
android:label="@string/activity_precipitations"
android:parentActivityName=".ExampleOverviewActivity">
<meta-data
android:name="@string/category"
android:value="@string/category_styles" />
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
package com.mapbox.maps.compose.testapp.examples.style

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.FloatingActionButton
import androidx.compose.material.Text
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.mapbox.maps.MapboxExperimental
import com.mapbox.maps.Style
import com.mapbox.maps.compose.testapp.ExampleScaffold
import com.mapbox.maps.compose.testapp.examples.utils.CityLocations
import com.mapbox.maps.compose.testapp.ui.theme.MapboxMapComposeTheme
import com.mapbox.maps.extension.compose.MapboxMap
import com.mapbox.maps.extension.compose.animation.viewport.rememberMapViewportState
import com.mapbox.maps.extension.compose.style.DoubleValue
import com.mapbox.maps.extension.compose.style.MapStyle
import com.mapbox.maps.extension.compose.style.precipitations.generated.RainState
import com.mapbox.maps.extension.compose.style.precipitations.generated.SnowState
import com.mapbox.maps.extension.compose.style.precipitations.generated.rememberRainState
import com.mapbox.maps.extension.compose.style.precipitations.generated.rememberSnowState
import com.mapbox.maps.extension.compose.style.rememberStyleState

/**
* Example to showcase usage of [RainState] and [SnowState].
*/
@OptIn(MapboxExperimental::class)
public class PrecipitationsActivity : ComponentActivity() {

/**
* Describes the heaviness of precipitation.
*/
public sealed class PrecipitationState(
public val intensity: Double,
public val density: Double,
public val opacity: Double,
public val text: String
) {
public object None : PrecipitationState(intensity = 0.0, density = 0.0, opacity = 0.0, text = "no")

public object Light : PrecipitationState(intensity = 0.2, density = 0.2, opacity = 0.3, text = "light")

public object Medium : PrecipitationState(intensity = 0.6, density = 0.6, opacity = 0.5, text = "medium")

public object Heavy : PrecipitationState(intensity = 1.0, density = 1.0, opacity = 0.8, text = "heavy")

public fun toggleNext(): PrecipitationState {
return when (this) {
Heavy -> None
None -> Light
Light -> Medium
Medium -> Heavy
}
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContent {
var snowPrecipitationState: PrecipitationState by remember {
mutableStateOf(PrecipitationState.Light)
}

var rainPrecipitationState: PrecipitationState by remember {
mutableStateOf(PrecipitationState.Light)
}

val mapViewportState = rememberMapViewportState {
setCameraOptions {
zoom(ZOOM)
pitch(PITCH)
bearing(BEARING)
center(CityLocations.HELSINKI)
}
}

val rainState = rememberRainState().also {
it.opacity = DoubleValue(rainPrecipitationState.opacity)
it.intensity = DoubleValue(rainPrecipitationState.intensity)
it.density = DoubleValue(rainPrecipitationState.density)
}

val snowState = rememberSnowState().also {
it.opacity = DoubleValue(snowPrecipitationState.opacity)
it.intensity = DoubleValue(snowPrecipitationState.intensity)
it.density = DoubleValue(snowPrecipitationState.density)
}

MapboxMapComposeTheme {
ExampleScaffold(
floatingActionButton = {
Column {
FloatingActionButton(
modifier = Modifier.padding(bottom = 10.dp),
onClick = {
rainPrecipitationState = rainPrecipitationState.toggleNext()
},
shape = RoundedCornerShape(16.dp),
) {
Text(
modifier = Modifier.padding(10.dp),
text = "${rainPrecipitationState.text} rain"
)
}
FloatingActionButton(
modifier = Modifier.padding(bottom = 10.dp),
onClick = {
snowPrecipitationState = snowPrecipitationState.toggleNext()
},
shape = RoundedCornerShape(16.dp),
) {
Text(
modifier = Modifier.padding(10.dp),
text = "${snowPrecipitationState.text} snow"
)
}
}
}
) {
MapboxMap(
Modifier.fillMaxSize(),
mapViewportState = mapViewportState,
style = {
MapStyle(
style = Style.STANDARD,
styleState = rememberStyleState().apply {
this.rainState =
if (rainPrecipitationState == PrecipitationState.None) RainState.DISABLED else rainState
this.snowState =
if (snowPrecipitationState == PrecipitationState.None) SnowState.DISABLED else snowState
}
)
}
)
}
}
}
}

private companion object {
private const val ZOOM: Double = 16.0
private const val PITCH: Double = 40.0
private const val BEARING: Double = 70.0
}
}
1 change: 1 addition & 0 deletions compose-app/src/main/res/values/example_descriptions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
<string name="description_standard_style">Showcase usage of Standard style</string>
<string name="description_clip_layer">Showcase the usage of clip layer.</string>
<string name="description_interactions">Showcase the interactions.</string>
<string name="description_precipitations">Showcase the rain and snow effects.</string>
</resources>
1 change: 1 addition & 0 deletions compose-app/src/main/res/values/example_titles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@
<string name="activity_standard_style">Standard style</string>
<string name="activity_clip_layer">Clip layer example</string>
<string name="activity_interactions">Interactions example</string>
<string name="activity_precipitations">Precipitations example</string>
</resources>
Loading

0 comments on commit e76cdca

Please sign in to comment.