Skip to content

Commit

Permalink
Add documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandrocalles committed Jun 2, 2024
1 parent 2c5bff7 commit e0c0db1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ import org.ramani.compose.Circle
import org.ramani.compose.MapLibre
import org.ramani.compose.Symbol

/**
* A Composable to select a location on a map.
*
* @param initialLocation The location at which the map must be initialized.
* @param locationCallback The function to call when the selected location changes.
*/
@Composable
fun LocationSelector(
modifier: Modifier = Modifier,
Expand Down Expand Up @@ -52,6 +58,11 @@ fun LocationSelector(
}
}

/**
* A Composable to display a location on a mpa.
*
* @param position The location to be displayed.
*/
@Composable
fun LocationDisplayer(
modifier: Modifier = Modifier,
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/com/github/swent/echo/compose/map/Map.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ import com.mapbox.mapboxsdk.geometry.LatLng
val MAP_CENTER = Location("EPFL", 46.5191, 6.5668)
const val DEFAULT_ZOOM = 13.0

/**
* Wrapper around an [AndroidView] to facilitate readability.
*
* @param factory The factory that will product a [View].
* @param update The function to update said [View].
* @param events The list of events to be displayed by the map. Whenever this list changes, the
* event markers in the map will be automatically updated to match the list.
* @param callback The function to be called when a marker on the map is clicked on. The [Event]
* corresponding to the marker will be passed as an argument to this function.
* @param withLocation Whether the [View] should display the location of the user.
* @param launchEventCreation A function to enable the [View] to launch event creations.
*/
@Composable
fun <T : View> EchoAndroidView(
modifier: Modifier = Modifier,
Expand All @@ -28,6 +40,7 @@ fun <T : View> EchoAndroidView(
withLocation: Boolean,
launchEventCreation: (LatLng) -> Unit
) {
// Will change when the map construction is done in order to trigger an update.
var trigger by remember { mutableStateOf(false) }
AndroidView(
modifier = modifier.testTag("mapAndroidView"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import com.mapbox.mapboxsdk.geometry.LatLng
* [EchoAndroidView][com.github.swent.echo.compose.map.EchoAndroidView]. The methods `factory` and
* `update` directly correspond to the parameters of the same name in an
* [EchoAndroidView][com.github.swent.echo.compose.map.EchoAndroidView].
*
* @author alejandrocalles
*/
interface MapViewProvider<T : View> {
fun factory(
Expand All @@ -23,5 +21,11 @@ interface MapViewProvider<T : View> {

fun update(view: T, events: List<Event>, callback: (Event) -> Unit, withLocation: Boolean)

/**
* Forces this provider to set the position of its camera according to the given parameters.
*
* @param newPosition The position on which to center the camera.
* @param zoomLevel The level of zoom at which to set the camera.
*/
fun setSavedCameraPosition(newPosition: LatLng, zoomLevel: Double)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.mapbox.mapboxsdk.maps.MapView
import com.mapbox.mapboxsdk.maps.MapboxMap
import com.mapbox.mapboxsdk.maps.Style

/** An implementation of a [MapViewProvider] that produces [MapView]s. */
class MapViewProviderImpl : MapViewProvider<MapView> {

// Stores the last camera position so we can restore it when the map is recreated (i.e. when the
Expand Down Expand Up @@ -68,7 +69,7 @@ class MapViewProviderImpl : MapViewProvider<MapView> {
locationComponent!!.activateLocationComponent(locationComponentActivationOptions)
locationComponent!!.isLocationComponentEnabled = true
locationComponent!!.cameraMode = CameraMode.NONE
locationComponent?.lastKnownLocation?.apply {
locationComponent!!.lastKnownLocation?.apply {
if (firstRecenter) {
firstRecenter = false
val pos = LatLng(latitude, longitude)
Expand Down

0 comments on commit e0c0db1

Please sign in to comment.