873 lines
30 KiB
Kotlin
873 lines
30 KiB
Kotlin
package com.mogo.map
|
||
|
||
import android.graphics.Point
|
||
import android.graphics.Rect
|
||
import android.os.Bundle
|
||
import android.os.Handler
|
||
import android.os.HandlerThread
|
||
import android.text.TextUtils
|
||
import android.view.MotionEvent
|
||
import android.view.View
|
||
import com.mogo.eagle.core.data.deva.chain.ChainConstant
|
||
import com.mogo.eagle.core.data.enums.TrafficTypeEnum
|
||
import com.mogo.eagle.core.data.map.MogoLatLng
|
||
import com.mogo.eagle.core.data.map.MogoLocation
|
||
import com.mogo.eagle.core.function.call.map.CallerMapDataCollectorManager.setIsInit
|
||
import com.mogo.eagle.core.function.call.map.CallerMapDevaListenerManager.invokeUploadLogFile
|
||
import com.mogo.eagle.core.function.call.map.CallerMapRoadListenerManager.invokeListenersOnRoadIdGet
|
||
import com.mogo.eagle.core.function.call.map.CallerMapRoadListenerManager.invokeListenersOnStopLineGet
|
||
import com.mogo.eagle.core.function.call.map.CallerMapRoadListenerManager.invokeRoadChange
|
||
import com.mogo.eagle.core.function.call.map.CallerMapRomaListener.invokeMapRomaStatus
|
||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.d
|
||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.e
|
||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.i
|
||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.w
|
||
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_MAP
|
||
import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
|
||
import com.mogo.map.listener.MogoMapListenerHandler.Companion.mogoMapListenerHandler
|
||
import com.mogo.map.uicontroller.*
|
||
import com.mogo.map.utils.MapTraceUtil
|
||
import com.mogo.map.utils.MogoMapUtils
|
||
import com.mogo.map.utils.ObjectUtils
|
||
import com.zhidaoauto.map.data.point.LonLatPoint
|
||
import com.zhidaoauto.map.data.road.RoadCross
|
||
import com.zhidaoauto.map.data.road.StopLine
|
||
import com.zhidaoauto.map.sdk.open.MapAutoApi
|
||
import com.zhidaoauto.map.sdk.open.MapAutoApi.registerLogListener
|
||
import com.zhidaoauto.map.sdk.open.MapAutoApi.unregisterLogListener
|
||
import com.zhidaoauto.map.sdk.open.abs.*
|
||
import com.zhidaoauto.map.sdk.open.abs.log.ILog
|
||
import com.zhidaoauto.map.sdk.open.business.PointCloudHelper.setIsDrawPointCloud
|
||
import com.zhidaoauto.map.sdk.open.business.PointCloudHelper.setPointCloudColor
|
||
import com.zhidaoauto.map.sdk.open.business.PointCloudHelper.setPointCloudSize
|
||
import com.zhidaoauto.map.sdk.open.business.PointCloudHelper.updatePointCloudDataByPb
|
||
import com.zhidaoauto.map.sdk.open.camera.CameraPosition
|
||
import com.zhidaoauto.map.sdk.open.camera.CameraUpdateFactory.newLatLngBounds
|
||
import com.zhidaoauto.map.sdk.open.location.MyLocationStyle
|
||
import com.zhidaoauto.map.sdk.open.marker.BitmapDescriptorFactory.convertViewToBitmap
|
||
import com.zhidaoauto.map.sdk.open.marker.Marker
|
||
import com.zhidaoauto.map.sdk.open.marker.OnMarkClickListener
|
||
import com.zhidaoauto.map.sdk.open.tools.MapTools.fromScreenLocation
|
||
import com.zhidaoauto.map.sdk.open.tools.MapTools.getVisibleRegion
|
||
import com.zhidaoauto.map.sdk.open.tools.MapTools.toScreenLocation
|
||
import com.zhidaoauto.map.sdk.open.view.MapAutoView
|
||
import com.zhjt.service.chain.ChainLog
|
||
import java.util.concurrent.atomic.AtomicInteger
|
||
import kotlin.properties.Delegates
|
||
|
||
class AMapViewWrapper(mMapView: MapAutoView) : IMogoMapView, IMogoMapUIController,
|
||
OnMapLoadedListener, OnCameraChangeListener, OnMapClickListener, OnMapTouchListener,
|
||
OnMarkClickListener, OnMapStyleListener, OnMapViewVisualAngleChangeListener, OnRoadInfoListener,
|
||
ILog, OnRoamStatusListener {
|
||
|
||
companion object {
|
||
private const val TAG = "AMapViewWrapper"
|
||
}
|
||
|
||
private var mMapView: MapAutoView
|
||
private val mIMap: IMogoMap
|
||
private val DEFAULT_OPTION = CarCursorOption.Builder()
|
||
.carCursorRes(R.drawable.map_api_ic_current_location2)
|
||
.naviCursorRes(R.drawable.ic_amap_navi_cursor)
|
||
.build()
|
||
private var mCarCursorOption = DEFAULT_OPTION
|
||
|
||
@Volatile
|
||
private var visualLock = false
|
||
|
||
@Volatile
|
||
private var mCurrentUI: EnumMapUI = EnumMapUI.MAP_STYLE_NIGHT_VR
|
||
override var currentMapVisualAngle: VisualAngleMode = VisualAngleMode.MODE_MEDIUM_SIGHT
|
||
private set
|
||
|
||
//地图的接口回调操作都在主线程返回,基于此类回调,业务在使用时注意切换子线程/线程池处理
|
||
private val handler by lazy {
|
||
val thread = HandlerThread(TAG)
|
||
thread.start()
|
||
Handler(thread.looper)
|
||
}
|
||
|
||
init {
|
||
i(M_MAP + TAG, "AMapViewWrapper: init")
|
||
this.mMapView = mMapView
|
||
initViews()
|
||
initListeners()
|
||
mIMap = AMapWrapper(this.mMapView.getMapAutoViewHelper(), this.mMapView, this)
|
||
handler.post {}
|
||
}
|
||
|
||
private fun initViews() {
|
||
// 初始化首次地图进入的时候的样式, MapAutoApi.INSTANCE.init(context, mapParams);将影响这里的数据
|
||
val mapStyle = mMapView.getMapStyleParams()!!.getStyleMode()
|
||
d(M_MAP + TAG, "默认配置地图模式:mapStyle=$mapStyle")
|
||
when (mapStyle) {
|
||
MapAutoApi.MAP_STYLE_DAY -> mCurrentUI = EnumMapUI.MAP_STYLE_DAY
|
||
MapAutoApi.MAP_STYLE_DAY_NAV -> mCurrentUI = EnumMapUI.MAP_STYLE_DAY_NAV
|
||
MapAutoApi.MAP_STYLE_NIGHT -> mCurrentUI = EnumMapUI.MAP_STYLE_NIGHT
|
||
MapAutoApi.MAP_STYLE_NIGHT_NAV -> mCurrentUI = EnumMapUI.MAP_STYLE_NIGHT_NAV
|
||
MapAutoApi.MAP_STYLE_DAY_VR -> mCurrentUI = EnumMapUI.MAP_STYLE_DAY_VR
|
||
MapAutoApi.MAP_STYLE_NIGHT_VR -> mCurrentUI = EnumMapUI.MAP_STYLE_NIGHT_VR
|
||
else -> e(M_MAP + TAG, "暂不支持此地图模式,默认使用VR夜间模式")
|
||
}
|
||
}
|
||
|
||
private fun initListeners() {
|
||
mMapView.setOnMarkClickListener(this)
|
||
mMapView.setOnMapLoadedListener(this)
|
||
mMapView.setOnMapTouchListener(this)
|
||
mMapView.setOnMapClickListener(this)
|
||
mMapView.setOnCameraChangeListener(this)
|
||
mMapView.setOnMapStyleListener(this)
|
||
mMapView.setOnRoamStatusListener(this)
|
||
mMapView.setOnMapViewVisualAngleChangeListener(this)
|
||
mMapView.setOnRoadInfoListener(this, 1)
|
||
registerLogListener(this, mMapView.getEventController())
|
||
d(M_MAP + TAG, "initListeners - setOnMapStyleListener - view $mMapView")
|
||
}
|
||
|
||
override fun getMapView(): View {
|
||
return mMapView
|
||
}
|
||
|
||
override fun getMap(): IMogoMap {
|
||
return mIMap
|
||
}
|
||
|
||
override fun onCreate(bundle: Bundle?) {
|
||
mMapView.onCreate(bundle)
|
||
d(M_MAP + TAG, "map onCreate")
|
||
}
|
||
|
||
override fun onResume() {
|
||
mMapView.onResume()
|
||
d(M_MAP + TAG, "map onResume")
|
||
}
|
||
|
||
override fun onPause() {
|
||
mMapView.onPause()
|
||
d(M_MAP + TAG, "map onPause")
|
||
}
|
||
|
||
override fun onDestroy() {
|
||
mMapView.onDestroy()
|
||
mMapView.setOnMarkClickListener(null)
|
||
mMapView.setOnMapLoadedListener(null)
|
||
mMapView.setOnMapTouchListener(null)
|
||
mMapView.setOnMapClickListener(null)
|
||
mMapView.setOnCameraChangeListener(null)
|
||
mMapView.setOnMapStyleListener(null)
|
||
mMapView.setOnMapViewVisualAngleChangeListener(null)
|
||
unregisterLogListener(this, mMapView.getEventController())
|
||
d(M_MAP + TAG, "map onDestroy")
|
||
}
|
||
|
||
override fun onSaveInstanceState(outState: Bundle) {
|
||
mMapView.onSaveInstanceState(outState)
|
||
d(M_MAP + TAG, "map onSaveInstanceState")
|
||
}
|
||
|
||
override fun onLowMemory() {}
|
||
|
||
//渲染第一帧
|
||
@ChainLog(
|
||
linkChainLog = ChainConstant.CHAIN_TYPE_STATUS,
|
||
linkCode = ChainConstant.CHAIN_SOURCE_INIT,
|
||
nodeAliasCode = ChainConstant.CHAIN_CODE_INIT_ON_MAP_INIT,
|
||
paramIndexes = [-1]
|
||
)
|
||
override fun onMapInit() {
|
||
i(M_MAP + TAG, "onMapInit: ")
|
||
mogoMapListenerHandler.onMapLoaded()
|
||
}
|
||
|
||
//地图视图准备
|
||
@ChainLog(
|
||
linkChainLog = ChainConstant.CHAIN_TYPE_STATUS,
|
||
linkCode = ChainConstant.CHAIN_SOURCE_INIT,
|
||
nodeAliasCode = ChainConstant.CHAIN_CODE_INIT_ON_MAP_LOADED,
|
||
paramIndexes = [-1]
|
||
)
|
||
override fun onMapLoaded() {
|
||
i(M_MAP + TAG, "onMapLoaded: ")
|
||
if (checkAMapView()) {
|
||
val cameraPosition = mMapView.getMapAutoViewHelper()!!
|
||
.getCameraPosition()
|
||
mogoMapListenerHandler.onMapChanged(
|
||
ObjectUtils.fromAMap(cameraPosition.target),
|
||
cameraPosition.zoom,
|
||
cameraPosition.tilt,
|
||
cameraPosition.bearing
|
||
)
|
||
loadPreVehicleModel()
|
||
}
|
||
}
|
||
|
||
override fun onRoadLoaded(roadInfo: String?) {
|
||
|
||
}
|
||
|
||
/**
|
||
* 修改获取当前车道号
|
||
*
|
||
* @param roadId
|
||
* @param laneId
|
||
*/
|
||
override fun onRoadIdInfo(roadId: String?, laneId: String?) {
|
||
handler.post {
|
||
if (roadId != null && !TextUtils.isEmpty(roadId)) {
|
||
invokeListenersOnRoadIdGet(roadId)
|
||
}
|
||
}
|
||
}
|
||
|
||
private var roadCross: RoadCross? by Delegates.observable(null) { _, oldValue, newValue ->
|
||
oldValue?.let {
|
||
//对驶入驶出路口做二次过滤,防止多次回调
|
||
if (it.status == 0 && newValue!!.status == 1) {
|
||
//径直进入路口
|
||
handler.post {
|
||
// i("$M_MAP$TAG", "进入路口 :${newValue.cross_id}")
|
||
invokeRoadChange(0, newValue)
|
||
}
|
||
}
|
||
if ((it.status == 1 && newValue!!.status == 0)) {
|
||
//径直驶出路口
|
||
handler.post {
|
||
// i("$M_MAP$TAG", "驶出路口 上个:${oldValue.cross_id_end} , 下个:${newValue.cross_id_end}")
|
||
invokeRoadChange(1, newValue)
|
||
}
|
||
return@let
|
||
}
|
||
if ((newValue!!.cross_id_end.isNotEmpty() && oldValue.cross_id_end != newValue.cross_id_end)) {
|
||
//路口发生变化
|
||
handler.post {
|
||
// i("$M_MAP$TAG", "路段发生变化 上个:${oldValue.cross_id_end} , 下个:${newValue.cross_id_end}")
|
||
invokeRoadChange(2, newValue)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
override fun onRoadCrossInfo(roadCross: RoadCross?) {
|
||
roadCross?.let {
|
||
this.roadCross = it
|
||
}
|
||
}
|
||
|
||
override fun onStopLineInfo(stopLine: StopLine?) {
|
||
stopLine?.let {
|
||
handler.post {
|
||
if (it.road_id.isNotEmpty() && it.points.size > 0) {
|
||
d(M_MAP + TAG, "onStopLineInfo: $it")
|
||
invokeListenersOnStopLineGet(it)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
override fun changeZoom(zoom: Float) {
|
||
if (checkAMapView()) {
|
||
mMapView.getMapAutoViewHelper()!!.setZoom(zoom.toInt())
|
||
}
|
||
}
|
||
|
||
override fun changeZoom2(zoom: Float) {
|
||
if (checkAMapView()) {
|
||
mMapView.getMapAutoViewHelper()!!.setZoomVal(zoom)
|
||
}
|
||
}
|
||
|
||
override fun changeMapVisualAngle(angelMode: VisualAngleMode, mogoLatLng: MogoLatLng?) {
|
||
if (visualLock) {
|
||
e(M_MAP + TAG, "视角切换已锁定")
|
||
return
|
||
}
|
||
val mapAutoViewHelper = mMapView.getMapAutoViewHelper()
|
||
if (mapAutoViewHelper != null) {
|
||
currentMapVisualAngle = angelMode
|
||
if (angelMode == VisualAngleMode.MODE_CLOSE_SIGHT) {
|
||
if (mogoLatLng == null) {
|
||
e(M_MAP + TAG, "切换地图近景需要传入要移动的经纬度数据")
|
||
return
|
||
}
|
||
// 近景传入经纬度为点击地图上静态marker经纬度数据,为GPS坐标点。
|
||
mapAutoViewHelper.setNearViewAnglePosition(
|
||
LonLatPoint(
|
||
mogoLatLng.lon,
|
||
mogoLatLng.lat
|
||
), true
|
||
)
|
||
} else {
|
||
mapAutoViewHelper.setMapViewVisualAngle(angelMode.code)
|
||
}
|
||
}
|
||
}
|
||
|
||
@ChainLog(
|
||
linkChainLog = ChainConstant.CHAIN_TYPE_HD_MAP,
|
||
linkCode = ChainConstant.CHAIN_SOURCE_MAP,
|
||
nodeAliasCode = ChainConstant.CHAIN_CODE_HD_MAP_CALL,
|
||
paramIndexes = [0]
|
||
)
|
||
override fun setRoamTrajectory(routeList: ArrayList<LonLatPoint>) {
|
||
if (checkAMapView()) {
|
||
mMapView.getMapAutoViewHelper()?.setRoamTrajectory(routeList)
|
||
}
|
||
}
|
||
|
||
@ChainLog(
|
||
linkChainLog = ChainConstant.CHAIN_TYPE_HD_MAP,
|
||
linkCode = ChainConstant.CHAIN_SOURCE_MAP,
|
||
parentNodeAliasCode = ChainConstant.CHAIN_CODE_ROMA_REQUEST_OK,
|
||
nodeAliasCode = ChainConstant.CHAIN_CODE_ROMA_MODE_INVOKE,
|
||
paramIndexes = [0],
|
||
endPoint = false
|
||
)
|
||
override fun setRomaMode(mode: Int) {
|
||
if (checkAMapView()) {
|
||
mMapView.getMapAutoViewHelper()!!.setRoamStyle(mode, 1800f, MapAutoApi.ROAM_SPEED_40)
|
||
}
|
||
}
|
||
|
||
override fun moveToCenter(latLng: MogoLatLng) {
|
||
moveToCenter(latLng, true)
|
||
}
|
||
|
||
private fun checkAMapView(): Boolean {
|
||
if (mMapView.getMapAutoViewHelper() == null) {
|
||
e(M_MAP + TAG, "自研mapView实例为空,请检查")
|
||
return false
|
||
}
|
||
return true
|
||
}
|
||
|
||
override fun moveToCenter(latLng: MogoLatLng, animate: Boolean) {
|
||
d(M_MAP + TAG, "move to center $latLng")
|
||
if (latLng.lat == 0.0 || latLng.lon == 0.0) {
|
||
e(M_MAP + TAG, "latLng = null or is illegal")
|
||
return
|
||
}
|
||
if (checkAMapView()) {
|
||
mMapView.getMapAutoViewHelper()!!
|
||
.animateCamera(LonLatPoint(latLng.lon, latLng.lat))
|
||
}
|
||
}
|
||
|
||
override fun showMyLocation(visible: Boolean) {
|
||
d(M_MAP + TAG, "showMyLocation1 $visible")
|
||
// 如果是VR模式
|
||
if (isVrMold) {
|
||
return
|
||
}
|
||
// 不是VR模式情况强制刷新下
|
||
if (checkAMapView()) {
|
||
val style = mMapView.getMapAutoViewHelper()!!
|
||
.getMyLocationStyle()
|
||
if (visible) {
|
||
// 强制刷新一遍车标
|
||
style!!.myLocationIcon(mCarCursorOption!!.carCursorRes)
|
||
}
|
||
mMapView.getMapAutoViewHelper()!!.setMyLocationStyle(style!!)
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @return true-是,false=不是
|
||
*/
|
||
private val isVrMold: Boolean
|
||
get() {
|
||
val isVrMode =
|
||
mCurrentUI === EnumMapUI.MAP_STYLE_NIGHT_VR || mCurrentUI === EnumMapUI.MAP_STYLE_DAY_VR
|
||
d(M_MAP + TAG, "是否是VR模式: $isVrMode")
|
||
return isVrMode
|
||
}
|
||
|
||
/**
|
||
* 是否是白天模式
|
||
*
|
||
* @return true-是,false-不是
|
||
*/
|
||
override val isDayMode: Boolean
|
||
get() = mCurrentUI === EnumMapUI.MAP_STYLE_DAY_VR || mCurrentUI === EnumMapUI.MAP_STYLE_DAY || mCurrentUI === EnumMapUI.MAP_STYLE_DAY_NAV
|
||
|
||
override fun showMyLocation(view: View) {
|
||
if (checkAMapView()) {
|
||
val style = mMapView.getMapAutoViewHelper()!!.getMyLocationStyle()
|
||
style!!.myLocationIcon(convertViewToBitmap(view))
|
||
mMapView.getMapAutoViewHelper()!!.setMyLocationStyle(style)
|
||
}
|
||
}
|
||
|
||
override val scalePerPixel: Float
|
||
get() = if (checkAMapView()) {
|
||
mMapView.getMapAutoViewHelper()!!.getScalePerPixel()
|
||
} else 0.0f
|
||
override val zoomLevel: Float
|
||
get() = if (checkAMapView()) {
|
||
mMapView.getMapAutoViewHelper()!!.getZoom().toFloat()
|
||
} else 0.0f
|
||
override val cameraNorthEastPosition: MogoLatLng?
|
||
get() = ObjectUtils.fromAMap(getVisibleRegion(mMapView.getMapController()).rightTopPoint)
|
||
override val cameraSouthWestPosition: MogoLatLng?
|
||
get() {
|
||
try {
|
||
return ObjectUtils.fromAMap(getVisibleRegion(mMapView.getMapController()).leftBottomPoint)
|
||
} catch (e: Exception) {
|
||
e.printStackTrace()
|
||
}
|
||
return null
|
||
}
|
||
override val windowCenterLocation: MogoLatLng?
|
||
get() {
|
||
try {
|
||
if (checkAMapView()) {
|
||
return ObjectUtils.fromAMap(mMapView.getMapAutoViewHelper()!!.getCenter())
|
||
}
|
||
} catch (e: Exception) {
|
||
e.printStackTrace()
|
||
}
|
||
return null
|
||
}
|
||
|
||
override fun setPointToCenter(mapCenterX: Double, mapCenterY: Double) {
|
||
if (checkAMapView()) {
|
||
if (isVrMold) {
|
||
return
|
||
}
|
||
mMapView.getMapAutoViewHelper()!!
|
||
.setPointToCenter(mapCenterX.toFloat(), mapCenterY.toFloat())
|
||
}
|
||
}
|
||
|
||
override fun getLocationPointInScreen(latLng: MogoLatLng): Point? {
|
||
return if (checkAMapView()) {
|
||
try {
|
||
toScreenLocation(ObjectUtils.fromMogo(latLng), mMapView.getMapController())
|
||
} catch (e: Exception) {
|
||
e.printStackTrace()
|
||
null
|
||
}
|
||
} else null
|
||
}
|
||
|
||
override fun getLocationMogoLatLngInScreen(point: Point): MogoLatLng? {
|
||
return if (checkAMapView()) {
|
||
try {
|
||
ObjectUtils.fromAMap(fromScreenLocation(point, mMapView.getMapController()))
|
||
} catch (e: Exception) {
|
||
e.printStackTrace()
|
||
null
|
||
}
|
||
} else null
|
||
}
|
||
|
||
override fun setRenderFps(fps: Int) {
|
||
if (checkAMapView()) {
|
||
if (mMapView.getMapAutoViewHelper() != null) {
|
||
mMapView.getMapAutoViewHelper()!!.setRenderFps(fps)
|
||
}
|
||
}
|
||
}
|
||
|
||
override fun showBounds(
|
||
tag: String,
|
||
carPosition: MogoLatLng,
|
||
lonLats: List<MogoLatLng>,
|
||
bound: Rect,
|
||
lockCarPosition: Boolean
|
||
) {
|
||
if (!checkAMapView()) {
|
||
return
|
||
}
|
||
if (isVrMold) {
|
||
w(M_MAP + TAG, "vr 模式下忽略该设置")
|
||
return
|
||
}
|
||
i(
|
||
M_MAP + TAG,
|
||
"showBounds : " + carPosition.toString() + " , " + bound.toShortString() + " , " + lockCarPosition
|
||
)
|
||
try {
|
||
val latLngBounds = MogoMapUtils.getLatLngBounds(carPosition, lonLats, lockCarPosition)
|
||
mMapView.getMapAutoViewHelper()!!.setCenter(ObjectUtils.fromMogo(carPosition))
|
||
mMapView.getMapAutoViewHelper()!!.moveCamera(
|
||
newLatLngBounds(
|
||
latLngBounds,
|
||
bound.left,
|
||
bound.right,
|
||
bound.top,
|
||
bound.bottom
|
||
)
|
||
)
|
||
} catch (e: Exception) {
|
||
e(M_MAP + TAG, " error : $e")
|
||
}
|
||
}
|
||
|
||
override fun forceRender() {
|
||
if (checkAMapView()) {
|
||
mMapView.getMapAutoViewHelper()!!.runOnDrawFrame()
|
||
}
|
||
}
|
||
|
||
override fun calculateLineDistance(p1: MogoLatLng, p2: MogoLatLng): Float {
|
||
return MogoMapUtils.calculateLineDistance(
|
||
ObjectUtils.fromMogo(p1),
|
||
ObjectUtils.fromMogo(p2)
|
||
)
|
||
}
|
||
|
||
@get:Synchronized
|
||
override val isCarLocked: Boolean
|
||
get() = mMapView.getMapAutoViewHelper()!!.getLockMode()
|
||
|
||
override fun setCarCursorOption(option: CarCursorOption) {
|
||
if (isVrMold) {
|
||
return
|
||
}
|
||
if (!checkAMapView()) {
|
||
return
|
||
}
|
||
if (mCarCursorOption != null && mCarCursorOption !== DEFAULT_OPTION) {
|
||
mCarCursorOption!!.destroy()
|
||
}
|
||
mCarCursorOption = try {
|
||
option.clone()
|
||
} catch (e: Exception) {
|
||
DEFAULT_OPTION
|
||
}
|
||
val style = mMapView.getMapAutoViewHelper()!!.getMyLocationStyle()
|
||
if (mCarCursorOption!!.carCursorBmp != null && !mCarCursorOption!!.carCursorBmp.isRecycled) {
|
||
style!!.myLocationIcon(mCarCursorOption!!.carCursorBmp)
|
||
} else {
|
||
if (mCarCursorOption!!.carCursorRes != 0) {
|
||
style!!.myLocationIcon(mCarCursorOption!!.carCursorRes)
|
||
}
|
||
}
|
||
mMapView.getMapAutoViewHelper()!!.setMyLocationStyle(style!!)
|
||
}
|
||
|
||
/**
|
||
* 设置转向灯和刹车灯
|
||
*
|
||
* @param type :车尾灯类型
|
||
* @param time 闪烁时间 最小500ms 小于500ms 默认为500ms
|
||
*/
|
||
override fun setCarLightsType(type: Int, time: Int) {
|
||
if (checkAMapView()) {
|
||
mMapView.getMapAutoViewHelper()!!.setTailLightsType(type, time)
|
||
}
|
||
}
|
||
|
||
override val mapCameraPosition: MapCameraPosition?
|
||
get() {
|
||
if (checkAMapView()) {
|
||
val cameraPosition = mMapView.getMapAutoViewHelper()!!.getCameraPosition()
|
||
return ObjectUtils.fromAMap(cameraPosition)
|
||
}
|
||
return null
|
||
}
|
||
|
||
override fun changeBearing(bearing: Float) {
|
||
if (checkAMapView()) {
|
||
mMapView.getMapAutoViewHelper()!!.setMapViewRotation(bearing)
|
||
}
|
||
}
|
||
|
||
private var reChangeIconCount = AtomicInteger(0)
|
||
|
||
override fun changeCurrentIcon(iconId: Int) {
|
||
if (checkAMapView()) {
|
||
handler.post {
|
||
val changeResult = mMapView.getMapAutoViewHelper()!!.getMyLocationStyle()!!
|
||
.myLocationIcon(iconId, true)
|
||
if (!changeResult) {
|
||
val count = reChangeIconCount.incrementAndGet()
|
||
MapTraceUtil.log(
|
||
"", ChainConstant.CHAIN_CODE_HD_MAP_ICON_SET, TAG,
|
||
mapOf("changeCurrentIcon-count" to "$count")
|
||
)
|
||
if (count >= 3) {
|
||
return@post
|
||
}
|
||
handler.postDelayed({ changeCurrentIcon(iconId) },300L)
|
||
reChangeIconCount.set(0)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
override fun result(path: String) {
|
||
invokeUploadLogFile(path)
|
||
}
|
||
|
||
override fun onTouch(event: MotionEvent): Boolean {
|
||
mogoMapListenerHandler.onTouch(event)
|
||
return false
|
||
}
|
||
|
||
override fun onMapClick(lonLatPoint: LonLatPoint) {
|
||
mogoMapListenerHandler.onMapClick(ObjectUtils.fromAMap(lonLatPoint))
|
||
}
|
||
|
||
override fun onMapViewVisualAngleChange(type: Int) {
|
||
d(M_MAP + TAG, " 地图自动更改视距 currentThread : " + Thread.currentThread().name)
|
||
currentMapVisualAngle = getVisualAngleMode(type)
|
||
mogoMapListenerHandler.onMapVisualAngleChanged(currentMapVisualAngle)
|
||
}
|
||
|
||
private fun getVisualAngleMode(mode: Int): VisualAngleMode {
|
||
return when (mode) {
|
||
0 -> VisualAngleMode.MODE_CLOSE_SIGHT
|
||
1 -> VisualAngleMode.MODE_MEDIUM_SIGHT
|
||
2 -> VisualAngleMode.MODE_LONG_SIGHT
|
||
3 -> VisualAngleMode.MAP_STYLE_VR_ANGLE_300
|
||
4 -> VisualAngleMode.MAP_STYLE_VR_ANGLE_TOP
|
||
5 -> VisualAngleMode.MAP_STYLE_VR_ANGLE_CROSS
|
||
7 -> VisualAngleMode.MAP_STYLE_VR_ROMA
|
||
else -> VisualAngleMode.MODE_MEDIUM_SIGHT
|
||
}
|
||
}
|
||
|
||
override fun onCameraChange(type: Int, value: Int) {}
|
||
override fun onCameraChangeFinish(position: CameraPosition?) {
|
||
position?.let {
|
||
mogoMapListenerHandler.onMapChanged(
|
||
ObjectUtils.fromAMap(position.target),
|
||
position.zoom,
|
||
position.tilt,
|
||
position.bearing
|
||
)
|
||
}
|
||
}
|
||
|
||
override fun onChangeMapStyle(style: Int) {
|
||
// CallerLogger.INSTANCE.d(M_MAP + TAG, "currentMapStyle = " + styleId + " , current = " + mCurrentUI);
|
||
// 映射地图样式ID到鹰眼样式ID
|
||
when (style) {
|
||
MapAutoApi.MAP_STYLE_DAY, MapAutoApi.MAP_STYLE_DAY_NAV -> {
|
||
mCurrentUI = EnumMapUI.MAP_STYLE_DAY_NAV
|
||
}
|
||
MapAutoApi.MAP_STYLE_NIGHT -> {
|
||
mCurrentUI = EnumMapUI.MAP_STYLE_NIGHT
|
||
}
|
||
MapAutoApi.MAP_STYLE_NIGHT_NAV -> {
|
||
mCurrentUI = EnumMapUI.MAP_STYLE_NIGHT_NAV
|
||
}
|
||
MapAutoApi.MAP_STYLE_NIGHT_VR -> {
|
||
mCurrentUI = EnumMapUI.MAP_STYLE_NIGHT_VR
|
||
}
|
||
MapAutoApi.MAP_STYLE_DAY_VR -> {
|
||
mCurrentUI = EnumMapUI.MAP_STYLE_DAY_VR
|
||
}
|
||
}
|
||
loadPreVehicleModel()
|
||
mogoMapListenerHandler.onMapModeChanged(mCurrentUI)
|
||
}
|
||
|
||
override fun onMarkClick(marker: Marker) {
|
||
|
||
}
|
||
|
||
override fun onRoamStatus(status: Int, msg: String) {
|
||
invokeMapRomaStatus(status, msg)
|
||
}
|
||
|
||
override fun rtkEnable(enable: Boolean) {
|
||
if (checkAMapView()) {
|
||
mMapView.getLocationClient()!!.rtkEnable(enable)
|
||
}
|
||
}
|
||
|
||
override fun stepInDayMode(isDayMode: Boolean) {
|
||
// try {
|
||
// if (mMapView != null && mMapView.getMapAutoViewHelper() != null) {
|
||
// mMapView.getMapAutoViewHelper().setMapStyle();
|
||
// }
|
||
// } catch (Exception e) {
|
||
// e.printStackTrace();
|
||
// }
|
||
}
|
||
|
||
override fun visualAngleLock(lock: Boolean) {
|
||
visualLock = lock
|
||
}
|
||
|
||
override fun setMapDAngle(angle: Float) {
|
||
if (checkAMapView()) {
|
||
mMapView.getMapAutoViewHelper()!!.setMapDAngle(angle)
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 加载3D模型
|
||
*/
|
||
private fun loadPreVehicleModel() {
|
||
d(M_MAP + TAG, "添加感知模型到地图中……")
|
||
ThreadUtils.getIoPool().submit {
|
||
addPreVehicleModelWeiZhi(
|
||
TrafficTypeEnum.TYPE_TRAFFIC_ID_WEI_ZHI,
|
||
"添加感知模型到地图中……preVehicleStrWeiZhi="
|
||
)
|
||
addPreVehicleModelWeiZhi(
|
||
TrafficTypeEnum.TYPE_TRAFFIC_ID_PEOPLE,
|
||
"添加感知模型到地图中……preVehicleStrPeople="
|
||
)
|
||
addPreVehicleModelWeiZhi(
|
||
TrafficTypeEnum.TYPE_TRAFFIC_ID_BICYCLE,
|
||
"添加感知模型到地图中……preVehicleStrBicycle="
|
||
)
|
||
addPreVehicleModelWeiZhi(
|
||
TrafficTypeEnum.TYPE_TRAFFIC_ID_TA_CHE,
|
||
"添加感知模型到地图中……preVehicleStrTaChe="
|
||
)
|
||
addPreVehicleModelWeiZhi(
|
||
TrafficTypeEnum.TYPE_TRAFFIC_ID_MOTO,
|
||
"添加感知模型到地图中……preVehicleStrMoto="
|
||
)
|
||
addPreVehicleModelWeiZhi(
|
||
TrafficTypeEnum.TYPE_TRAFFIC_ID_BUS,
|
||
"添加感知模型到地图中……preVehicleStrBus="
|
||
)
|
||
addPreVehicleModelWeiZhi(
|
||
TrafficTypeEnum.TYPE_TRAFFIC_ID_TRUCK,
|
||
"添加感知模型到地图中……preVehicleStrTruck="
|
||
)
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 添加模型到地图中
|
||
*
|
||
* @param typeTrafficId 障碍物类型ID
|
||
* @param logMsg 日志消息
|
||
*/
|
||
private fun addPreVehicleModelWeiZhi(typeTrafficId: TrafficTypeEnum, logMsg: String) {
|
||
// 根据当前的地图皮肤模式动态替换
|
||
val preVehicleStrWeiZhi: String? = if (isDayMode) {
|
||
map.addPreVehicleModel(typeTrafficId.type, typeTrafficId.traffic3DIconId)
|
||
} else {
|
||
map.addPreVehicleModel(typeTrafficId.type, typeTrafficId.traffic3DNightIconId)
|
||
}
|
||
d(M_MAP + TAG, logMsg + preVehicleStrWeiZhi)
|
||
if (preVehicleStrWeiZhi == null) {
|
||
UiThreadHandler.postDelayed({
|
||
w(M_MAP + TAG, "添加感知模型到地图中失败,尝试重复添加……")
|
||
addPreVehicleModelWeiZhi(typeTrafficId, logMsg)
|
||
}, 1000L)
|
||
}
|
||
}
|
||
|
||
override fun setLockMode(isLock: Boolean) {
|
||
if (checkAMapView()) {
|
||
mMapView.getMapAutoViewHelper()!!.setLockMode(isLock)
|
||
}
|
||
}
|
||
|
||
override fun setScrollGesturesEnable(isEnable: Boolean) {
|
||
if (checkAMapView()) {
|
||
mMapView.getMapAutoViewHelper()!!.setScrollGesturesEnabled(isEnable)
|
||
}
|
||
}
|
||
|
||
override fun setAllGesturesEnabled(isEnable: Boolean) {
|
||
if (checkAMapView()) {
|
||
mMapView.getMapAutoViewHelper()!!.setAllGesturesEnabled(isEnable)
|
||
}
|
||
}
|
||
|
||
override fun setExtraGPSData(gnssInfo: MogoLocation) {
|
||
val locationClient = mMapView.getLocationClient()
|
||
if (locationClient != null) {
|
||
locationClient.setIsUseExtraGPSData(true) //设置是否使用外界坐标
|
||
locationClient.rtkEnable(true) //设置是否是高精定位
|
||
val lonLatPoint = LonLatPoint()
|
||
lonLatPoint.angle = gnssInfo.heading
|
||
lonLatPoint.altitude = gnssInfo.altitude
|
||
lonLatPoint.longitude = gnssInfo.longitude
|
||
lonLatPoint.latitude = gnssInfo.latitude
|
||
lonLatPoint.satelliteTime =
|
||
java.lang.Double.valueOf((gnssInfo.satelliteTime * 1000).toDouble()).toLong()
|
||
lonLatPoint.speed = gnssInfo.gnssSpeed.toDouble()
|
||
locationClient.updateLocation(lonLatPoint) //更新新自动驾驶RTK相关数据
|
||
setIsInit()
|
||
}
|
||
}
|
||
|
||
// 是否绘制点云
|
||
override fun setIsDrawPointCloud(isDrawPointCloud: Boolean) {
|
||
try {
|
||
setIsDrawPointCloud(isDrawPointCloud, mMapView.getMapController())
|
||
} catch (e: Exception) {
|
||
e.printStackTrace()
|
||
}
|
||
}
|
||
|
||
//设置点云大小
|
||
override fun setPointCloudSize(pointCloudSize: Float) {
|
||
setPointCloudSize(pointCloudSize, mMapView.getMapController())
|
||
}
|
||
|
||
// 设置点云颜色
|
||
override fun setPointCloudColor(color: String) {
|
||
setPointCloudColor(color, mMapView.getMapController())
|
||
}
|
||
|
||
//更新点云
|
||
override fun updatePointCloud(
|
||
dataArray: ByteArray?, isTransformer: Boolean, isResidual: Boolean, isReset: Boolean
|
||
): Boolean {
|
||
return updatePointCloudDataByPb(
|
||
dataArray, isTransformer, isResidual, isReset, mMapView.getMapController()
|
||
)
|
||
}
|
||
|
||
override fun animateTo(
|
||
lon: Double,
|
||
lat: Double,
|
||
rotateAngle: Float,
|
||
duration: Int,
|
||
isGps: Boolean
|
||
) {
|
||
if (checkAMapView()) {
|
||
mMapView.getMapAutoViewHelper()!!.animateTo(lon, lat, rotateAngle, duration, isGps)
|
||
}
|
||
}
|
||
|
||
override fun animateTo(
|
||
lon: Double,
|
||
lat: Double,
|
||
v1: Float,
|
||
v2: Float,
|
||
v3: Float,
|
||
v4: Float,
|
||
duration: Int,
|
||
isGps: Boolean
|
||
) {
|
||
if (checkAMapView()) {
|
||
mMapView.getMapAutoViewHelper()!!.animateTo(lon, lat, v1, v2, v3, v4, duration, isGps)
|
||
}
|
||
}
|
||
|
||
override fun clear() {
|
||
if (checkAMapView()) {
|
||
mMapView.getMapAutoViewHelper()!!.clearPanel()
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 自车光圈
|
||
* @param displayAnimEnable 是否展示自车光圈
|
||
*/
|
||
override fun setDisplayAnimEnable(displayAnimEnable: Boolean) {
|
||
if (checkAMapView()) {
|
||
val style: MyLocationStyle? = mMapView.getMapAutoViewHelper()!!.getMyLocationStyle()
|
||
style?.let {
|
||
it.setDisplayAnimEnable(displayAnimEnable)
|
||
mMapView.getMapAutoViewHelper()!!.setMyLocationStyle(it)
|
||
}
|
||
}
|
||
}
|
||
|
||
} |