-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update glnative to v11.9.0-rc.1 and add precipitations API and exampl…
…e. (#2874)
- Loading branch information
Showing
41 changed files
with
7,478 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
app/src/main/java/com/mapbox/maps/testapp/examples/style/PrecipitationActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
...pp/src/main/java/com/mapbox/maps/compose/testapp/examples/style/PrecipitationsActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.