Skip to content

Commit

Permalink
Make LatLng, LatLngBounds, CameraPosition as pure kotlin class to pre…
Browse files Browse the repository at this point in the history
…pare KMP (#130)

* Make LatLng, LatLngBounds as pure kotlin class to prepare KMP

* Make CameraPosition as pure kotlin class to prepare KMP

* Use compose LatLng, instead of original LatLng

* Fix compile error

* Fix spotless
  • Loading branch information
fornewid authored Nov 28, 2024
1 parent 4ff7b2f commit 1b23cef
Show file tree
Hide file tree
Showing 53 changed files with 725 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.pointerInteropFilter
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.naver.maps.geometry.LatLng
import com.naver.maps.map.CameraPosition
import com.naver.maps.map.compose.CameraPosition
import com.naver.maps.map.compose.CameraPositionState
import com.naver.maps.map.compose.ExperimentalNaverMapApi
import com.naver.maps.map.compose.LatLng
import com.naver.maps.map.compose.MapProperties
import com.naver.maps.map.compose.MapType
import com.naver.maps.map.compose.MapUiSettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.naver.maps.geometry.LatLng
import com.naver.maps.map.CameraAnimation
import com.naver.maps.map.CameraPosition
import com.naver.maps.map.CameraUpdate
import com.naver.maps.map.compose.CameraPosition
import com.naver.maps.map.compose.ExperimentalNaverMapApi
import com.naver.maps.map.compose.LatLng
import com.naver.maps.map.compose.Marker
import com.naver.maps.map.compose.NaverMap
import com.naver.maps.map.compose.demo.R
Expand Down Expand Up @@ -79,7 +79,7 @@ fun CameraAnimationScreen(upPress: () -> Unit) {
val animation = if (flag) CameraAnimation.Linear else CameraAnimation.Easing
coroutineScope.launch {
cameraPositionState.animate(
CameraUpdate.toCameraPosition(position),
CameraUpdate.toCameraPosition(position.asOriginal()),
animation = animation,
durationMs = 5000,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.naver.maps.geometry.LatLng
import com.naver.maps.map.CameraAnimation
import com.naver.maps.map.CameraUpdate
import com.naver.maps.map.compose.ExperimentalNaverMapApi
import com.naver.maps.map.compose.LatLng
import com.naver.maps.map.compose.Marker
import com.naver.maps.map.compose.NaverMap
import com.naver.maps.map.compose.demo.R
Expand Down Expand Up @@ -170,15 +170,15 @@ fun CameraEventScreen(upPress: () -> Unit) {
} else {
// TODO: How to improve the chains of camera animations?
cameraPositionState.move(
CameraUpdate.scrollTo(COORD_1)
CameraUpdate.scrollTo(COORD_1.asOriginal())
.animate(CameraAnimation.Fly, 3000)
.cancelCallback {
isMovingByAnimation = false
context.showToast(R.string.camera_update_cancelled)
}
.finishCallback {
cameraPositionState.move(
CameraUpdate.scrollTo(COORD_2)
CameraUpdate.scrollTo(COORD_2.asOriginal())
.animate(CameraAnimation.Fly, 3000)
.cancelCallback {
isMovingByAnimation = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.naver.maps.geometry.LatLng
import com.naver.maps.map.CameraUpdate
import com.naver.maps.map.compose.ExperimentalNaverMapApi
import com.naver.maps.map.compose.LatLng
import com.naver.maps.map.compose.Marker
import com.naver.maps.map.compose.NaverMap
import com.naver.maps.map.compose.demo.R
Expand Down Expand Up @@ -71,7 +71,7 @@ fun CameraMoveScreen(upPress: () -> Unit) {
backgroundColor = MaterialTheme.colors.primary,
onClick = {
val coord = if (flag) COORD_2 else COORD_1
cameraPositionState.move(CameraUpdate.scrollTo(coord))
cameraPositionState.move(CameraUpdate.scrollTo(coord.asOriginal()))
flag = !flag
},
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.naver.maps.geometry.LatLng
import com.naver.maps.map.CameraAnimation
import com.naver.maps.map.CameraUpdate
import com.naver.maps.map.CameraUpdateParams
import com.naver.maps.map.compose.ExperimentalNaverMapApi
import com.naver.maps.map.compose.LatLng
import com.naver.maps.map.compose.NaverMap
import com.naver.maps.map.compose.demo.R
import com.naver.maps.map.compose.demo.common.DefaultTopAppBar
Expand Down Expand Up @@ -82,7 +82,7 @@ fun CameraUpdateParamsScreen(upPress: () -> Unit) {
onClick = {
val params = CameraUpdateParams()
when (step) {
0 -> params.scrollTo(COORD).zoomTo(10.0).tiltTo(0.0)
0 -> params.scrollTo(COORD.asOriginal()).zoomTo(10.0).tiltTo(0.0)
1 -> params.scrollBy(PointF(deltaX, deltaY)).zoomBy(3.0)
else -> params.rotateBy(90.0).tiltTo(40.0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.naver.maps.geometry.LatLng
import com.naver.maps.geometry.LatLngBounds
import com.naver.maps.map.CameraAnimation
import com.naver.maps.map.CameraUpdate
import com.naver.maps.map.compose.ExperimentalNaverMapApi
import com.naver.maps.map.compose.LatLng
import com.naver.maps.map.compose.LatLngBounds
import com.naver.maps.map.compose.Marker
import com.naver.maps.map.compose.NaverMap
import com.naver.maps.map.compose.demo.R
Expand Down Expand Up @@ -85,7 +85,7 @@ fun FitBoundsScreen(upPress: () -> Unit) {
val bounds = if (flag) BOUNDS_2 else BOUNDS_1
coroutineScope.launch {
cameraPositionState.animate(
CameraUpdate.fitBounds(bounds, padding),
CameraUpdate.fitBounds(bounds.asOriginal(), padding),
animation = CameraAnimation.Fly,
durationMs = 5000,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.naver.maps.geometry.LatLng
import com.naver.maps.map.CameraUpdate
import com.naver.maps.map.compose.ExperimentalNaverMapApi
import com.naver.maps.map.compose.LatLng
import com.naver.maps.map.compose.Marker
import com.naver.maps.map.compose.NaverMap
import com.naver.maps.map.compose.demo.R
Expand Down Expand Up @@ -73,7 +73,7 @@ fun PivotScreen(upPress: () -> Unit) {
onClick = {
val coord = if (flag) COORD_2 else COORD_1
val pivot = if (flag) PIVOT_2 else PIVOT_1
cameraPositionState.move(CameraUpdate.scrollTo(coord).pivot(pivot))
cameraPositionState.move(CameraUpdate.scrollTo(coord.asOriginal()).pivot(pivot))
flag = !flag
},
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import com.naver.maps.geometry.LatLng
import com.naver.maps.map.CameraPosition
import com.naver.maps.map.clustering.Clusterer
import com.naver.maps.map.clustering.DefaultLeafMarkerUpdater
import com.naver.maps.map.clustering.LeafMarkerInfo
import com.naver.maps.map.compose.CameraPosition
import com.naver.maps.map.compose.DisposableMapEffect
import com.naver.maps.map.compose.ExperimentalNaverMapApi
import com.naver.maps.map.compose.LatLng
import com.naver.maps.map.compose.NaverMap
import com.naver.maps.map.compose.NaverMapConstants
import com.naver.maps.map.compose.demo.R
import com.naver.maps.map.compose.demo.common.DefaultTopAppBar
import com.naver.maps.map.compose.rememberCameraPositionState
import com.naver.maps.map.overlay.Marker
import com.naver.maps.map.overlay.Overlay
import com.naver.maps.map.util.MapConstants
import com.naver.maps.map.util.MarkerIcons

@Composable
Expand All @@ -62,7 +62,10 @@ fun ClusteringScreen(upPress: () -> Unit) {
@Composable
private fun Clustering() {
val cameraPositionState = rememberCameraPositionState {
position = CameraPosition(MapConstants.EXTENT_KOREA.center, 4.0)
position = CameraPosition(
target = NaverMapConstants.ExtentKorea.center,
zoom = NaverMapConstants.MinZoomKorea,
)
}
NaverMap(
modifier = Modifier.fillMaxSize(),
Expand All @@ -86,16 +89,19 @@ private fun Clustering() {
.apply { this.map = map }
}
val keyTagMap = buildMap(5000) {
val south = MapConstants.EXTENT_KOREA.southLatitude
val west = MapConstants.EXTENT_KOREA.westLongitude
val height = MapConstants.EXTENT_KOREA.northLatitude - south
val width = MapConstants.EXTENT_KOREA.eastLongitude - west
val south = NaverMapConstants.ExtentKorea.southLatitude
val west = NaverMapConstants.ExtentKorea.westLongitude
val height = NaverMapConstants.ExtentKorea.northLatitude - south
val width = NaverMapConstants.ExtentKorea.eastLongitude - west

repeat(5000) { i ->
put(
ItemKey(
i,
LatLng(height * Math.random() + south, width * Math.random() + west),
LatLng(
latitude = height * Math.random() + south,
longitude = width * Math.random() + west,
),
),
(Math.random() * ICONS.size).toInt(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.naver.maps.geometry.LatLng
import com.naver.maps.map.CameraPosition
import com.naver.maps.map.clustering.Clusterer
import com.naver.maps.map.clustering.DefaultClusterMarkerUpdater
import com.naver.maps.map.clustering.DefaultClusterOnClickListener
import com.naver.maps.map.clustering.DefaultDistanceStrategy
import com.naver.maps.map.clustering.DefaultMarkerManager
import com.naver.maps.map.clustering.DistanceStrategy
import com.naver.maps.map.clustering.Node
import com.naver.maps.map.compose.CameraPosition
import com.naver.maps.map.compose.DisposableMapEffect
import com.naver.maps.map.compose.ExperimentalNaverMapApi
import com.naver.maps.map.compose.LatLng
import com.naver.maps.map.compose.NaverMap
import com.naver.maps.map.compose.NaverMapConstants
import com.naver.maps.map.compose.demo.R
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package com.naver.maps.map.compose.demo.clustering

import com.naver.maps.geometry.LatLng
import com.naver.maps.map.clustering.ClusteringKey
import com.naver.maps.map.compose.LatLng

class ItemKey(val id: Int, private val latLng: LatLng) : ClusteringKey {
override fun getPosition() = latLng
override fun getPosition(): com.naver.maps.geometry.LatLng = latLng.asOriginal()

override fun equals(other: Any?): Boolean {
if (this === other) return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import com.naver.maps.geometry.LatLng
import com.naver.maps.map.CameraPosition
import com.naver.maps.map.compose.CameraPosition
import com.naver.maps.map.compose.DisposableMapEffect
import com.naver.maps.map.compose.ExperimentalNaverMapApi
import com.naver.maps.map.compose.LatLng
import com.naver.maps.map.compose.NaverMap
import com.naver.maps.map.compose.demo.R
import com.naver.maps.map.compose.demo.common.DefaultTopAppBar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import com.naver.maps.geometry.LatLng
import com.naver.maps.map.compose.ExperimentalNaverMapApi
import com.naver.maps.map.compose.LatLng
import com.naver.maps.map.compose.Marker
import com.naver.maps.map.compose.MarkerDefaults
import com.naver.maps.map.compose.NaverMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import com.naver.maps.geometry.LatLng
import com.naver.maps.map.LocationSource
import com.naver.maps.map.compose.ExperimentalNaverMapApi
import com.naver.maps.map.compose.LatLng
import com.naver.maps.map.compose.LocationTrackingMode
import com.naver.maps.map.compose.MapProperties
import com.naver.maps.map.compose.NaverMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.naver.maps.map.CameraPosition
import com.naver.maps.map.compose.CameraPosition
import com.naver.maps.map.compose.ExperimentalNaverMapApi
import com.naver.maps.map.compose.MapProperties
import com.naver.maps.map.compose.NaverMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import com.naver.maps.geometry.LatLng
import com.naver.maps.map.CameraPosition
import com.naver.maps.map.compose.CameraPosition
import com.naver.maps.map.compose.ExperimentalNaverMapApi
import com.naver.maps.map.compose.LatLng
import com.naver.maps.map.compose.MapProperties
import com.naver.maps.map.compose.MapUiSettings
import com.naver.maps.map.compose.NaverMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.naver.maps.map.CameraPosition
import com.naver.maps.map.compose.CameraPosition
import com.naver.maps.map.compose.ExperimentalNaverMapApi
import com.naver.maps.map.compose.MapProperties
import com.naver.maps.map.compose.MapType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.naver.maps.map.CameraPosition
import com.naver.maps.map.compose.CameraPosition
import com.naver.maps.map.compose.ExperimentalNaverMapApi
import com.naver.maps.map.compose.MapProperties
import com.naver.maps.map.compose.MapType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import com.naver.maps.geometry.LatLng
import com.naver.maps.map.compose.ExperimentalNaverMapApi
import com.naver.maps.map.compose.LatLng
import com.naver.maps.map.compose.MapProperties
import com.naver.maps.map.compose.MapType
import com.naver.maps.map.compose.Marker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.naver.maps.geometry.LatLng
import com.naver.maps.map.CameraAnimation
import com.naver.maps.map.CameraPosition
import com.naver.maps.map.CameraUpdate
import com.naver.maps.map.compose.CameraPosition
import com.naver.maps.map.compose.ExperimentalNaverMapApi
import com.naver.maps.map.compose.LatLng
import com.naver.maps.map.compose.Marker
import com.naver.maps.map.compose.NaverMap
import com.naver.maps.map.compose.NaverMapConstants
Expand Down Expand Up @@ -190,7 +190,7 @@ fun ContentPaddingScreen(upPress: () -> Unit) {
val coord = if (flag) COORD_1 else COORD_2
coroutineScope.launch {
cameraPositionState.animate(
CameraUpdate.scrollTo(coord),
CameraUpdate.scrollTo(coord.asOriginal()),
animation = CameraAnimation.Fly,
durationMs = 3000,
)
Expand All @@ -209,5 +209,5 @@ fun ContentPaddingScreen(upPress: () -> Unit) {
}
}

private val COORD_1 = LatLng(37.5666102, 126.9783881)
private val COORD_2 = LatLng(35.1798159, 129.0750222)
private val COORD_1 = LatLng(latitude = 37.5666102, longitude = 126.9783881)
private val COORD_2 = LatLng(latitude = 35.1798159, longitude = 129.0750222)
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import com.naver.maps.geometry.LatLng
import com.naver.maps.map.CameraPosition
import com.naver.maps.map.compose.CameraPosition
import com.naver.maps.map.compose.ExperimentalNaverMapApi
import com.naver.maps.map.compose.LatLng
import com.naver.maps.map.compose.MapProperties
import com.naver.maps.map.compose.MapUiSettings
import com.naver.maps.map.compose.NaverMap
Expand Down
Loading

0 comments on commit 1b23cef

Please sign in to comment.