code review
This commit is contained in:
parent
4350eee3cf
commit
96c6513463
|
|
@ -3,46 +3,79 @@ package ru.touchin.basemap
|
|||
import android.os.Bundle
|
||||
import android.view.View
|
||||
|
||||
abstract class AbstractMapManager<TMapView: View, TMap: Any, TLocation: Any>(protected val mapView: TMapView) {
|
||||
abstract class AbstractMapManager<TMapView : View, TMap : Any, TLocation : Any>(protected val mapView: TMapView) {
|
||||
|
||||
protected lateinit var map: TMap
|
||||
|
||||
protected var mapListener: AbstractMapListener<TMapView, TMap, TLocation>? = null
|
||||
|
||||
abstract fun getCameraTarget(): TLocation
|
||||
|
||||
abstract fun getCameraZoom(): Float
|
||||
|
||||
abstract fun getCameraAzimuth(): Float
|
||||
|
||||
abstract fun getCameraTilt(): Float
|
||||
|
||||
abstract fun moveCamera(
|
||||
target: TLocation,
|
||||
zoom: Float = getCameraZoom(),
|
||||
azimuth: Float = getCameraAzimuth(),
|
||||
tilt: Float = getCameraTilt()
|
||||
)
|
||||
|
||||
abstract fun smoothMoveCamera(
|
||||
target: TLocation,
|
||||
zoom: Float = getCameraZoom(),
|
||||
azimuth: Float = getCameraAzimuth(),
|
||||
tilt: Float = getCameraTilt()
|
||||
)
|
||||
|
||||
abstract fun smoothMoveCamera(targets: List<TLocation>, padding: Int = 0)
|
||||
|
||||
abstract fun smoothMoveCamera(targets: List<TLocation>, width: Int, height: Int, padding: Int)
|
||||
|
||||
abstract fun setMapAllGesturesEnabled(enabled: Boolean)
|
||||
|
||||
abstract fun setMyLocationEnabled(enabled: Boolean)
|
||||
|
||||
abstract fun isLocationInVisibleRegion(location: TLocation): Boolean
|
||||
|
||||
open fun initialize(mapListener: AbstractMapListener<TMapView, TMap, TLocation>? = null) {
|
||||
this.mapListener = mapListener
|
||||
}
|
||||
|
||||
open fun onCreate(savedInstanceState: Bundle) = Unit
|
||||
|
||||
open fun onDestroy() = Unit
|
||||
|
||||
open fun onStart() = Unit
|
||||
|
||||
open fun onStop() = Unit
|
||||
|
||||
open fun onResume() = Unit
|
||||
|
||||
open fun onPause() = Unit
|
||||
|
||||
open fun onLowMemory() = Unit
|
||||
|
||||
open fun onSaveInstanceState(outState: Bundle) = Unit
|
||||
|
||||
protected open fun initMap(map: TMap) {
|
||||
this.map = map
|
||||
this.mapListener?.onMapInitialized(map)
|
||||
}
|
||||
|
||||
open fun onCreate(savedInstanceState: Bundle) = Unit
|
||||
open fun onDestroy() = Unit
|
||||
open fun onStart() = Unit
|
||||
open fun onStop() = Unit
|
||||
open fun onResume() = Unit
|
||||
open fun onPause() = Unit
|
||||
open fun onLowMemory() = Unit
|
||||
open fun onSaveInstanceState (outState: Bundle) = Unit
|
||||
|
||||
abstract fun getCameraTarget(): TLocation
|
||||
abstract fun getCameraZoom(): Float
|
||||
abstract fun moveCamera(target: TLocation, zoom: Float = getCameraZoom())
|
||||
abstract fun smoothMoveCamera(target: TLocation, zoom: Float = getCameraZoom())
|
||||
abstract fun smoothMoveCamera(targets: List<TLocation>, padding: Int = 0)
|
||||
abstract fun smoothMoveCamera(targets: List<TLocation>, width: Int, height: Int, padding: Int)
|
||||
abstract fun setMapAllGesturesEnabled(enabled: Boolean)
|
||||
abstract fun setMyLocationEnabled(enabled: Boolean)
|
||||
abstract fun isLocationInVisibleRegion(location: TLocation): Boolean
|
||||
|
||||
interface AbstractMapListener<TMapView, TMap, TLocation> {
|
||||
|
||||
fun onMapInitialized(map: TMap)
|
||||
|
||||
fun onMapLoaded() = Unit
|
||||
|
||||
fun onMapTap(location: TLocation) = Unit
|
||||
|
||||
fun onMapLongTap(location: TLocation) = Unit
|
||||
|
||||
fun onCameraMoved(finished: Boolean) = Unit
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,12 +72,16 @@ class GoogleMapManager(mapView: MapView) : AbstractMapManager<MapView, GoogleMap
|
|||
|
||||
override fun getCameraZoom(): Float = map.cameraPosition.zoom
|
||||
|
||||
override fun moveCamera(target: LatLng, zoom: Float) {
|
||||
map.moveCamera(CameraUpdateFactory.newCameraPosition(CameraPosition.Builder().target(target).zoom(zoom).build()))
|
||||
override fun getCameraAzimuth(): Float = map.cameraPosition.bearing
|
||||
|
||||
override fun getCameraTilt(): Float = map.cameraPosition.tilt
|
||||
|
||||
override fun moveCamera(target: LatLng, zoom: Float, azimuth: Float, tilt: Float) {
|
||||
map.moveCamera(CameraUpdateFactory.newCameraPosition(buildCameraPosition(target, zoom, azimuth, tilt)))
|
||||
}
|
||||
|
||||
override fun smoothMoveCamera(target: LatLng, zoom: Float) {
|
||||
map.animateCamera(CameraUpdateFactory.newCameraPosition(CameraPosition.Builder().target(target).zoom(zoom).build()))
|
||||
override fun smoothMoveCamera(target: LatLng, zoom: Float, azimuth: Float, tilt: Float) {
|
||||
map.animateCamera(CameraUpdateFactory.newCameraPosition(buildCameraPosition(target, zoom, azimuth, tilt)))
|
||||
}
|
||||
|
||||
override fun smoothMoveCamera(targets: List<LatLng>, padding: Int) {
|
||||
|
|
@ -105,6 +109,13 @@ class GoogleMapManager(mapView: MapView) : AbstractMapManager<MapView, GoogleMap
|
|||
}
|
||||
.build()
|
||||
|
||||
private fun buildCameraPosition(target: LatLng, zoom: Float, azimuth: Float, tilt: Float) = CameraPosition.Builder()
|
||||
.target(target)
|
||||
.zoom(zoom)
|
||||
.bearing(azimuth)
|
||||
.tilt(tilt)
|
||||
.build()
|
||||
|
||||
interface MapListener : AbstractMapListener<MapView, GoogleMap, LatLng>
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,11 @@ class YandexMapManager(
|
|||
private val isDebug: Boolean = false
|
||||
) : AbstractMapManager<MapView, Map, Point>(mapView), MapLoadedListener, CameraListener, InputListener {
|
||||
|
||||
companion object {
|
||||
private const val CAMERA_ANIMATION_DURATION = 1f
|
||||
private const val CAMERA_OFFSET_ZOOM = 3f
|
||||
}
|
||||
|
||||
private val userLocationLayer by lazy {
|
||||
MapKitFactory.getInstance().createUserLocationLayer(mapView.mapWindow).also { it.isVisible = false }
|
||||
}
|
||||
|
|
@ -75,18 +80,22 @@ class YandexMapManager(
|
|||
|
||||
override fun getCameraZoom(): Float = map.cameraPosition.zoom
|
||||
|
||||
override fun moveCamera(target: Point, zoom: Float) {
|
||||
map.move(CameraPosition(target, zoom, 0.0f, 0.0f), Animation(Animation.Type.LINEAR, 1F), null)
|
||||
override fun getCameraAzimuth(): Float = map.cameraPosition.azimuth
|
||||
|
||||
override fun getCameraTilt(): Float = map.cameraPosition.tilt
|
||||
|
||||
override fun moveCamera(target: Point, zoom: Float, azimuth: Float, tilt: Float) {
|
||||
map.move(CameraPosition(target, zoom, azimuth, tilt), Animation(Animation.Type.LINEAR, CAMERA_ANIMATION_DURATION), null)
|
||||
}
|
||||
|
||||
override fun smoothMoveCamera(target: Point, zoom: Float) {
|
||||
map.move(CameraPosition(target, zoom, 0.0f, 0.0f), Animation(Animation.Type.SMOOTH, 1F), null)
|
||||
override fun smoothMoveCamera(target: Point, zoom: Float, azimuth: Float, tilt: Float) {
|
||||
map.move(CameraPosition(target, zoom, azimuth, tilt), Animation(Animation.Type.SMOOTH, CAMERA_ANIMATION_DURATION), null)
|
||||
}
|
||||
|
||||
override fun smoothMoveCamera(targets: List<Point>, padding: Int) {
|
||||
val boundingBox = BoundingBoxHelper.getBounds(LinearRing(targets))
|
||||
val cameraPosition = map.cameraPosition(boundingBox)
|
||||
smoothMoveCamera(cameraPosition.target, cameraPosition.zoom - 3f)
|
||||
smoothMoveCamera(cameraPosition.target, cameraPosition.zoom - CAMERA_OFFSET_ZOOM)
|
||||
}
|
||||
|
||||
override fun smoothMoveCamera(targets: List<Point>, width: Int, height: Int, padding: Int) {
|
||||
|
|
@ -94,7 +103,9 @@ class YandexMapManager(
|
|||
}
|
||||
|
||||
override fun setMapAllGesturesEnabled(enabled: Boolean) {
|
||||
map.isRotateGesturesEnabled = enabled
|
||||
map.isScrollGesturesEnabled = enabled
|
||||
map.isTiltGesturesEnabled = enabled
|
||||
map.isZoomGesturesEnabled = enabled
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue