834 lines
30 KiB
Kotlin
834 lines
30 KiB
Kotlin
package com.mogo.map
|
||
|
||
import android.graphics.Point
|
||
import android.graphics.Rect
|
||
import android.os.Bundle
|
||
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.MapRoadInfo
|
||
import com.mogo.eagle.core.data.map.MogoLatLng
|
||
import com.mogo.eagle.core.data.map.MogoLocation
|
||
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager.getChassisLocationWGS84
|
||
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.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
|
||
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.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.data.MapDataApi.getNearstFromPointToSegment
|
||
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
|
||
|
||
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
|
||
|
||
init {
|
||
i(SceneConstant.M_MAP + TAG, "AMapViewWrapper: init")
|
||
this.mMapView = mMapView
|
||
initViews()
|
||
initListeners()
|
||
mIMap = AMapWrapper(this.mMapView.getMapAutoViewHelper(), this.mMapView, this)
|
||
}
|
||
|
||
private fun initViews() {
|
||
// 初始化首次地图进入的时候的样式, MapAutoApi.INSTANCE.init(context, mapParams);将影响这里的数据
|
||
val mapStyle = mMapView.getMapStyleParams()!!.getStyleMode()
|
||
d(SceneConstant.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(SceneConstant.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(SceneConstant.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(SceneConstant.M_MAP + TAG, "map onCreate")
|
||
}
|
||
|
||
override fun onResume() {
|
||
mMapView.onResume()
|
||
d(SceneConstant.M_MAP + TAG, "map onResume")
|
||
}
|
||
|
||
override fun onPause() {
|
||
mMapView.onPause()
|
||
d(SceneConstant.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(SceneConstant.M_MAP + TAG, "map onDestroy")
|
||
}
|
||
|
||
override fun onSaveInstanceState(outState: Bundle) {
|
||
mMapView.onSaveInstanceState(outState)
|
||
d(SceneConstant.M_MAP + TAG, "map onSaveInstanceState")
|
||
}
|
||
|
||
override fun onLowMemory() {}
|
||
|
||
//渲染第一帧
|
||
@ChainLog(
|
||
linkChainLog = ChainConstant.CHAIN_TYPE_INIT_STATUS,
|
||
linkCode = ChainConstant.CHAIN_SOURCE_INIT,
|
||
nodeAliasCode = ChainConstant.CHAIN_CODE_INIT_ON_MAP_INIT,
|
||
paramIndexes = [-1]
|
||
)
|
||
override fun onMapInit() {
|
||
i(SceneConstant.M_MAP + TAG, "onMapInit: ")
|
||
mogoMapListenerHandler.onMapLoaded()
|
||
}
|
||
|
||
//地图视图准备
|
||
@ChainLog(
|
||
linkChainLog = ChainConstant.CHAIN_TYPE_INIT_STATUS,
|
||
linkCode = ChainConstant.CHAIN_SOURCE_INIT,
|
||
nodeAliasCode = ChainConstant.CHAIN_CODE_INIT_ON_MAP_LOADED,
|
||
paramIndexes = [-1]
|
||
)
|
||
override fun onMapLoaded() {
|
||
i(SceneConstant.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?) {
|
||
if (roadId != null && !TextUtils.isEmpty(roadId)) {
|
||
invokeListenersOnRoadIdGet(roadId)
|
||
}
|
||
}
|
||
|
||
override fun onRoadCrossInfo(roadCross: RoadCross?) {
|
||
d(SceneConstant.M_MAP + TAG, "onRoadCrossInfo:roadCross$roadCross")
|
||
}
|
||
|
||
//todo 多实例 对象替换
|
||
override fun onStopLineInfo(stopLine: StopLine?) {
|
||
val carLoc = getChassisLocationWGS84()
|
||
if (stopLine != null && stopLine.road_id.isNotEmpty() && stopLine.points.size > 0) {
|
||
val points = stopLine.points
|
||
d(SceneConstant.M_MAP + TAG, "onStopLineInfo:stop_line$stopLine")
|
||
val stopInfo = convert(stopLine)
|
||
val p1 = points[0]
|
||
val p2 = points[points.size - 1]
|
||
val distanceOfCarToStopLine = getNearstFromPointToSegment(
|
||
carLoc.longitude,
|
||
carLoc.latitude,
|
||
p1.longitude,
|
||
p1.latitude,
|
||
p2.longitude,
|
||
p2.latitude
|
||
) * 100000
|
||
stopInfo.distanceOfCarToStopLine = distanceOfCarToStopLine
|
||
d(SceneConstant.M_MAP + TAG, "onStopLineInfo: --- distance: $distanceOfCarToStopLine")
|
||
invokeListenersOnStopLineGet(stopInfo)
|
||
}
|
||
}
|
||
|
||
private fun convert(line: StopLine): MapRoadInfo.StopLine {
|
||
val ret = MapRoadInfo.StopLine()
|
||
ret.distance = line.distance
|
||
ret.laneId = line.lane_id
|
||
ret.roadId = line.road_id
|
||
ret.tieId = line.tile_id
|
||
val points = line.points
|
||
if (points.size > 0) {
|
||
val newPoints: MutableList<MogoLatLng> = ArrayList()
|
||
for (i in points.indices) {
|
||
val lonLatPoint = points[i]
|
||
val latLng = MogoLatLng(lonLatPoint.latitude, lonLatPoint.longitude)
|
||
latLng.duration = lonLatPoint.duration
|
||
latLng.angle = lonLatPoint.angle
|
||
latLng.speed = lonLatPoint.speed
|
||
latLng.altitude = lonLatPoint.altitude
|
||
latLng.provider = lonLatPoint.provider
|
||
newPoints.add(latLng)
|
||
}
|
||
ret.points = newPoints
|
||
}
|
||
return ret
|
||
}
|
||
|
||
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(SceneConstant.M_MAP + TAG, "视角切换已锁定")
|
||
return
|
||
}
|
||
val mapAutoViewHelper = mMapView.getMapAutoViewHelper()
|
||
if (mapAutoViewHelper != null) {
|
||
currentMapVisualAngle = angelMode
|
||
if (angelMode == VisualAngleMode.MODE_CLOSE_SIGHT) {
|
||
if (mogoLatLng == null) {
|
||
e(SceneConstant.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(trajectory: String) {
|
||
if (checkAMapView()) {
|
||
mMapView.getMapAutoViewHelper()!!.setRoamTrajectory(trajectory)
|
||
}
|
||
}
|
||
|
||
@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(SceneConstant.M_MAP + TAG, "自研mapView实例为空,请检查")
|
||
return false
|
||
}
|
||
return true
|
||
}
|
||
|
||
override fun moveToCenter(latLng: MogoLatLng, animate: Boolean) {
|
||
d(SceneConstant.M_MAP + TAG, "move to center $latLng")
|
||
if (latLng.lat == 0.0 || latLng.lon == 0.0) {
|
||
e(SceneConstant.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(SceneConstant.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(SceneConstant.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(SceneConstant.M_MAP + TAG, "vr 模式下忽略该设置")
|
||
return
|
||
}
|
||
i(
|
||
SceneConstant.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(SceneConstant.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)
|
||
}
|
||
}
|
||
|
||
override fun changeCurrentIcon(iconId: Int) {
|
||
if (checkAMapView()) {
|
||
mMapView.getMapAutoViewHelper()!!.getMyLocationStyle()!!.myLocationIcon(iconId, true)
|
||
}
|
||
}
|
||
|
||
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(SceneConstant.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(SceneConstant.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(SceneConstant.M_MAP + TAG, logMsg + preVehicleStrWeiZhi)
|
||
if (preVehicleStrWeiZhi == null) {
|
||
UiThreadHandler.postDelayed({
|
||
w(SceneConstant.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()
|
||
}
|
||
}
|
||
|
||
} |