70 lines
2.2 KiB
Kotlin
Raw Normal View History

2022-07-23 10:58:16 +03:00
package center.sciprog.maps.compose
2022-07-11 09:36:43 +03:00
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
2022-07-11 09:36:43 +03:00
import androidx.compose.ui.Modifier
2022-12-23 22:16:16 +03:00
import center.sciprog.maps.coordinates.Gmc
2022-12-28 20:03:08 +03:00
import center.sciprog.maps.features.*
2022-07-11 09:36:43 +03:00
2022-07-13 11:36:02 +03:00
2022-07-11 09:36:43 +03:00
@Composable
2022-07-23 13:49:47 +03:00
public expect fun MapView(
2023-01-06 22:16:46 +03:00
viewScope: MapViewScope,
features: FeatureGroup<Gmc>,
modifier: Modifier = Modifier.fillMaxSize(),
)
/**
* A builder for a Map with static features.
*/
@Composable
public fun MapView(
mapTileProvider: MapTileProvider,
2023-01-06 22:16:46 +03:00
features: FeatureGroup<Gmc>,
initialViewPoint: ViewPoint<Gmc>? = null,
initialRectangle: Rectangle<Gmc>? = null,
2022-12-24 22:59:33 +03:00
config: ViewConfig<Gmc> = ViewConfig(),
modifier: Modifier = Modifier.fillMaxSize(),
) {
2023-01-06 22:16:46 +03:00
val mapState: MapViewScope = MapViewScope.remember(
mapTileProvider,
config,
initialViewPoint = initialViewPoint,
2023-01-06 22:16:46 +03:00
initialRectangle = initialRectangle ?: features.getBoundingBox(Float.MAX_VALUE),
)
2023-01-06 22:16:46 +03:00
MapView(mapState, features, modifier)
}
/**
* Draw a map using convenient parameters. If neither [initialViewPoint], noe [initialRectangle] is defined,
* use map features to infer view region.
* @param initialViewPoint The view point of the map using center and zoom. Is used if provided
* @param initialRectangle The rectangle to be used for view point computation. Used if [initialViewPoint] is not defined.
* @param buildFeatures - a builder for features
*/
@Composable
2022-07-23 13:49:47 +03:00
public fun MapView(
2022-07-14 20:19:57 +03:00
mapTileProvider: MapTileProvider,
2023-01-06 22:16:46 +03:00
initialViewPoint: ViewPoint<Gmc>? = null,
initialRectangle: Rectangle<Gmc>? = null,
2022-12-24 22:59:33 +03:00
config: ViewConfig<Gmc> = ViewConfig(),
2022-07-14 20:19:57 +03:00
modifier: Modifier = Modifier.fillMaxSize(),
2023-01-02 14:08:20 +03:00
buildFeatures: FeatureGroup<Gmc>.() -> Unit = {},
) {
2023-01-02 14:08:20 +03:00
val featureState = FeatureGroup.remember(WebMercatorSpace, buildFeatures)
2022-12-28 20:03:08 +03:00
2023-01-06 22:16:46 +03:00
val mapState: MapViewScope = MapViewScope.remember(
mapTileProvider,
config,
initialViewPoint = initialViewPoint,
2023-01-06 22:16:46 +03:00
initialRectangle = initialRectangle ?: featureState.features.computeBoundingBox(
WebMercatorSpace,
Float.MAX_VALUE
),
)
MapView(mapState, featureState, modifier)
}