Skip to content

Commit e76cdca

Browse files
authored
Update glnative to v11.9.0-rc.1 and add precipitations API and example. (#2874)
1 parent a63644b commit e76cdca

File tree

41 files changed

+7478
-16
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+7478
-16
lines changed

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,20 @@
33
Mapbox welcomes participation and contributions from everyone.
44

55
# 11.9.0-rc.1
6-
6+
## Features ✨ and improvements 🏁
77
* Add `toHsla` expression.
8+
* Introduce experimental `Snow` and `Rain` APIs to show the snow or rain effect on the map.
9+
* [compose] Introduce experimental `SnowState` and `RainState` APIs to show the snow or rain effect on the map.
10+
11+
## Bug fixes 🐞
12+
* Improve character spacing for text offsets.
13+
* Fixed crash on Android API level < 26.
14+
* Do not load vector icons for client-provided sprites.
15+
* 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.
16+
* Fixed crash caused by a repeated command buffer commit call.
17+
18+
## Dependencies
19+
* Update gl-native to v11.9.0-rc.1 and common to v24.9.0-rc.1.
820

921
# 11.8.1 December 03, 2024
1022
## Bug fixes 🐞

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ License: [The Apache Software License, Version 2.0](http://www.apache.org/licens
482482

483483
===========================================================================
484484

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

487487
```
488488
Mapbox Core Maps version 11.0

app/src/main/AndroidManifest.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,5 +1414,17 @@
14141414
android:name="android.support.PARENT_ACTIVITY"
14151415
android:value=".ExampleOverviewActivity" />
14161416
</activity>
1417+
<activity
1418+
android:name=".examples.style.PrecipitationActivity"
1419+
android:description="@string/description_precipitation"
1420+
android:exported="true"
1421+
android:label="@string/activity_precipitation">
1422+
<meta-data
1423+
android:name="@string/category"
1424+
android:value="@string/category_styles" />
1425+
<meta-data
1426+
android:name="android.support.PARENT_ACTIVITY"
1427+
android:value=".ExampleOverviewActivity" />
1428+
</activity>
14171429
</application>
14181430
</manifest>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package com.mapbox.maps.testapp.examples.style
2+
3+
import android.os.Bundle
4+
import androidx.appcompat.app.AppCompatActivity
5+
import com.mapbox.geojson.Point
6+
import com.mapbox.maps.CameraOptions
7+
import com.mapbox.maps.MapboxExperimental
8+
import com.mapbox.maps.Style
9+
import com.mapbox.maps.extension.style.precipitations.generated.rain
10+
import com.mapbox.maps.extension.style.precipitations.generated.removeRain
11+
import com.mapbox.maps.extension.style.precipitations.generated.removeSnow
12+
import com.mapbox.maps.extension.style.precipitations.generated.setRain
13+
import com.mapbox.maps.extension.style.precipitations.generated.setSnow
14+
import com.mapbox.maps.extension.style.precipitations.generated.snow
15+
import com.mapbox.maps.extension.style.style
16+
import com.mapbox.maps.testapp.databinding.ActivityPrecipitationsBinding
17+
18+
/**
19+
* Showcase snow and rain effect.
20+
*/
21+
@OptIn(MapboxExperimental::class)
22+
class PrecipitationActivity : AppCompatActivity() {
23+
24+
private var isSnowing: Boolean = true
25+
private var isRaining: Boolean = true
26+
private val rain = rain {
27+
intensity(0.6)
28+
opacity(0.5)
29+
vignette(0.5)
30+
}
31+
private val snow = snow {
32+
intensity(0.6)
33+
opacity(0.5)
34+
vignette(0.5)
35+
}
36+
private lateinit var binding: ActivityPrecipitationsBinding
37+
38+
override fun onCreate(savedInstanceState: Bundle?) {
39+
super.onCreate(savedInstanceState)
40+
binding = ActivityPrecipitationsBinding.inflate(layoutInflater)
41+
setContentView(binding.root)
42+
val mapboxMap = binding.mapView.mapboxMap
43+
mapboxMap.setCamera(
44+
CameraOptions.Builder()
45+
.center(Point.fromLngLat(24.943849, 60.171924))
46+
.bearing(-17.6)
47+
.pitch(45.0)
48+
.zoom(16.0)
49+
.build()
50+
)
51+
52+
mapboxMap.loadStyle(
53+
style(Style.STANDARD) {
54+
+snow
55+
+rain
56+
}
57+
)
58+
59+
// change snow intensity on fab click
60+
binding.toggleSnow.setOnClickListener {
61+
isSnowing = !isSnowing
62+
if (isSnowing) {
63+
mapboxMap.setSnow(snow)
64+
} else {
65+
mapboxMap.removeSnow()
66+
}
67+
}
68+
69+
binding.toggleRain.setOnClickListener {
70+
isRaining = !isRaining
71+
if (isRaining) {
72+
mapboxMap.setRain(rain)
73+
} else {
74+
mapboxMap.removeRain()
75+
}
76+
}
77+
}
78+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent">
7+
8+
<com.mapbox.maps.MapView
9+
android:id="@id/mapView"
10+
android:layout_width="match_parent"
11+
android:layout_height="match_parent" />
12+
13+
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
14+
android:id="@+id/toggle_rain"
15+
android:layout_width="wrap_content"
16+
android:layout_height="wrap_content"
17+
android:layout_gravity="end|bottom"
18+
android:layout_marginEnd="16dp"
19+
android:layout_marginBottom="82dp"
20+
android:text="Toggle rain"
21+
app:backgroundTint="@color/accent"
22+
app:layout_anchorGravity="top"
23+
tools:ignore="HardcodedText" />
24+
25+
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
26+
android:id="@+id/toggle_snow"
27+
android:layout_width="wrap_content"
28+
android:layout_height="wrap_content"
29+
android:layout_gravity="end|bottom"
30+
android:layout_margin="16dp"
31+
android:text="Toggle snow"
32+
app:backgroundTint="@color/primary"
33+
tools:ignore="HardcodedText" />
34+
35+
</FrameLayout>

app/src/main/res/values/example_descriptions.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,5 @@
110110
<string name="description_clip_layer">Showcase the usage of clip layer.</string>
111111
<string name="description_standard_interactions">Showcase of the Standard Style interactions.</string>
112112
<string name="description_location_component_model_animation">Animate 3D location puck on the map</string>
113+
<string name="description_precipitation">Showcase rain and snow effects.</string>
113114
</resources>

app/src/main/res/values/example_titles.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,5 @@
112112
<string name="activity_clip_layer">Clip layer example</string>
113113
<string name="activity_standard_interactions">Standard Style interactions</string>
114114
<string name="activity_location_component_model_animation">Location component model animation</string>
115+
<string name="activity_precipitation">Precipitations example</string>
115116
</resources>

compose-app/src/main/AndroidManifest.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,16 @@
307307
android:name="@string/category"
308308
android:value="@string/category_styles" />
309309
</activity>
310+
<activity
311+
android:name=".examples.style.PrecipitationsActivity"
312+
android:description="@string/description_precipitations"
313+
android:exported="true"
314+
android:label="@string/activity_precipitations"
315+
android:parentActivityName=".ExampleOverviewActivity">
316+
<meta-data
317+
android:name="@string/category"
318+
android:value="@string/category_styles" />
319+
</activity>
310320
</application>
311321

312322
</manifest>
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
package com.mapbox.maps.compose.testapp.examples.style
2+
3+
import android.os.Bundle
4+
import androidx.activity.ComponentActivity
5+
import androidx.activity.compose.setContent
6+
import androidx.compose.foundation.layout.Column
7+
import androidx.compose.foundation.layout.fillMaxSize
8+
import androidx.compose.foundation.layout.padding
9+
import androidx.compose.foundation.shape.RoundedCornerShape
10+
import androidx.compose.material.FloatingActionButton
11+
import androidx.compose.material.Text
12+
import androidx.compose.runtime.getValue
13+
import androidx.compose.runtime.mutableStateOf
14+
import androidx.compose.runtime.remember
15+
import androidx.compose.runtime.setValue
16+
import androidx.compose.ui.Modifier
17+
import androidx.compose.ui.unit.dp
18+
import com.mapbox.maps.MapboxExperimental
19+
import com.mapbox.maps.Style
20+
import com.mapbox.maps.compose.testapp.ExampleScaffold
21+
import com.mapbox.maps.compose.testapp.examples.utils.CityLocations
22+
import com.mapbox.maps.compose.testapp.ui.theme.MapboxMapComposeTheme
23+
import com.mapbox.maps.extension.compose.MapboxMap
24+
import com.mapbox.maps.extension.compose.animation.viewport.rememberMapViewportState
25+
import com.mapbox.maps.extension.compose.style.DoubleValue
26+
import com.mapbox.maps.extension.compose.style.MapStyle
27+
import com.mapbox.maps.extension.compose.style.precipitations.generated.RainState
28+
import com.mapbox.maps.extension.compose.style.precipitations.generated.SnowState
29+
import com.mapbox.maps.extension.compose.style.precipitations.generated.rememberRainState
30+
import com.mapbox.maps.extension.compose.style.precipitations.generated.rememberSnowState
31+
import com.mapbox.maps.extension.compose.style.rememberStyleState
32+
33+
/**
34+
* Example to showcase usage of [RainState] and [SnowState].
35+
*/
36+
@OptIn(MapboxExperimental::class)
37+
public class PrecipitationsActivity : ComponentActivity() {
38+
39+
/**
40+
* Describes the heaviness of precipitation.
41+
*/
42+
public sealed class PrecipitationState(
43+
public val intensity: Double,
44+
public val density: Double,
45+
public val opacity: Double,
46+
public val text: String
47+
) {
48+
public object None : PrecipitationState(intensity = 0.0, density = 0.0, opacity = 0.0, text = "no")
49+
50+
public object Light : PrecipitationState(intensity = 0.2, density = 0.2, opacity = 0.3, text = "light")
51+
52+
public object Medium : PrecipitationState(intensity = 0.6, density = 0.6, opacity = 0.5, text = "medium")
53+
54+
public object Heavy : PrecipitationState(intensity = 1.0, density = 1.0, opacity = 0.8, text = "heavy")
55+
56+
public fun toggleNext(): PrecipitationState {
57+
return when (this) {
58+
Heavy -> None
59+
None -> Light
60+
Light -> Medium
61+
Medium -> Heavy
62+
}
63+
}
64+
}
65+
66+
override fun onCreate(savedInstanceState: Bundle?) {
67+
super.onCreate(savedInstanceState)
68+
69+
setContent {
70+
var snowPrecipitationState: PrecipitationState by remember {
71+
mutableStateOf(PrecipitationState.Light)
72+
}
73+
74+
var rainPrecipitationState: PrecipitationState by remember {
75+
mutableStateOf(PrecipitationState.Light)
76+
}
77+
78+
val mapViewportState = rememberMapViewportState {
79+
setCameraOptions {
80+
zoom(ZOOM)
81+
pitch(PITCH)
82+
bearing(BEARING)
83+
center(CityLocations.HELSINKI)
84+
}
85+
}
86+
87+
val rainState = rememberRainState().also {
88+
it.opacity = DoubleValue(rainPrecipitationState.opacity)
89+
it.intensity = DoubleValue(rainPrecipitationState.intensity)
90+
it.density = DoubleValue(rainPrecipitationState.density)
91+
}
92+
93+
val snowState = rememberSnowState().also {
94+
it.opacity = DoubleValue(snowPrecipitationState.opacity)
95+
it.intensity = DoubleValue(snowPrecipitationState.intensity)
96+
it.density = DoubleValue(snowPrecipitationState.density)
97+
}
98+
99+
MapboxMapComposeTheme {
100+
ExampleScaffold(
101+
floatingActionButton = {
102+
Column {
103+
FloatingActionButton(
104+
modifier = Modifier.padding(bottom = 10.dp),
105+
onClick = {
106+
rainPrecipitationState = rainPrecipitationState.toggleNext()
107+
},
108+
shape = RoundedCornerShape(16.dp),
109+
) {
110+
Text(
111+
modifier = Modifier.padding(10.dp),
112+
text = "${rainPrecipitationState.text} rain"
113+
)
114+
}
115+
FloatingActionButton(
116+
modifier = Modifier.padding(bottom = 10.dp),
117+
onClick = {
118+
snowPrecipitationState = snowPrecipitationState.toggleNext()
119+
},
120+
shape = RoundedCornerShape(16.dp),
121+
) {
122+
Text(
123+
modifier = Modifier.padding(10.dp),
124+
text = "${snowPrecipitationState.text} snow"
125+
)
126+
}
127+
}
128+
}
129+
) {
130+
MapboxMap(
131+
Modifier.fillMaxSize(),
132+
mapViewportState = mapViewportState,
133+
style = {
134+
MapStyle(
135+
style = Style.STANDARD,
136+
styleState = rememberStyleState().apply {
137+
this.rainState =
138+
if (rainPrecipitationState == PrecipitationState.None) RainState.DISABLED else rainState
139+
this.snowState =
140+
if (snowPrecipitationState == PrecipitationState.None) SnowState.DISABLED else snowState
141+
}
142+
)
143+
}
144+
)
145+
}
146+
}
147+
}
148+
}
149+
150+
private companion object {
151+
private const val ZOOM: Double = 16.0
152+
private const val PITCH: Double = 40.0
153+
private const val BEARING: Double = 70.0
154+
}
155+
}

compose-app/src/main/res/values/example_descriptions.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@
2727
<string name="description_standard_style">Showcase usage of Standard style</string>
2828
<string name="description_clip_layer">Showcase the usage of clip layer.</string>
2929
<string name="description_interactions">Showcase the interactions.</string>
30+
<string name="description_precipitations">Showcase the rain and snow effects.</string>
3031
</resources>

0 commit comments

Comments
 (0)