[M2] M2 高精地图设置marker

This commit is contained in:
wangmingjun
2023-02-15 21:00:19 +08:00
parent 142028bd75
commit b8c7334c92
7 changed files with 158 additions and 4 deletions

View File

@@ -0,0 +1,10 @@
package com.mogo.och.bus.passenger.callback
/**
* @author: wangmingjun
* @date: 2023/2/15
*/
interface ADASCallback {
fun updateHDMapStations(stations: MutableList<MutableList<Double>>)
fun removeHDMapStations()
}

View File

@@ -7,8 +7,14 @@ import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils
/**
* Created on 2021/12/6
*/
class URLConst {
class M2Const {
companion object {
//站点UUID
const val M2_MAP_STATION_MAKER = "m2_map_station_maker"
/**
* Marker类型
*/
const val TYPE_MARKER_M2_LINE = "TYPE_MARKER_M2_LINE"
}
}

View File

@@ -1,8 +1,46 @@
package com.mogo.och.bus.passenger.model
import android.content.Context
import com.amap.api.maps.model.LatLng
import com.mogo.och.bus.passenger.bean.PM2Station
import com.mogo.och.bus.passenger.callback.ADASCallback
/**
* @author: wangmingjun
* @date: 2023/2/2
*/
class PM2ADASModel {
class PM2ADASModel private constructor() {
private var mContext: Context? = null
private var mAdasCallback: ADASCallback? = null
companion object {
val TAG = PM2ADASModel::class.java.simpleName
val INSTANCE: PM2ADASModel by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
PM2ADASModel()
}
}
fun init(context : Context){
this.mContext = context
}
fun setAdasCallback(adasCallback: ADASCallback?){
this.mAdasCallback = adasCallback
}
fun updateHDMapStations(stations: MutableList<PM2Station>){
var stationsList = mutableListOf<MutableList<Double>>()
for (i in stations.indices){
var listLatLng = mutableListOf<Double>() // 0: long 1:lat
listLatLng.add(stations[i].lon)
listLatLng.add(stations[i].lat)
stationsList.add(listLatLng)
}
mAdasCallback?.updateHDMapStations(stationsList)
}
fun removeHDMapStations(){
mAdasCallback?.removeHDMapStations()
}
}

View File

@@ -107,7 +107,7 @@ class PM2DrivingModel private constructor() {
mDrivingInfoCallback = drivingInfoCallback
}
fun setAutoStatusCallback(autoPilotStatusCallback: AutoPilotStatusCallback){
fun setAutoStatusCallback(autoPilotStatusCallback: AutoPilotStatusCallback?){
mAutoStatusCallback = autoPilotStatusCallback
}

View File

@@ -1,7 +1,41 @@
package com.mogo.och.bus.passenger.presenter
import androidx.lifecycle.LifecycleOwner
import com.mogo.commons.mvp.Presenter
import com.mogo.och.bus.passenger.callback.ADASCallback
import com.mogo.och.bus.passenger.constant.M2Const.Companion.M2_MAP_STATION_MAKER
import com.mogo.och.bus.passenger.model.PM2ADASModel
import com.mogo.och.bus.passenger.ui.PM2HPMapFragment
class PM2ADASPresenter(view: PM2HPMapFragment?) :
Presenter<PM2HPMapFragment?>(view)
Presenter<PM2HPMapFragment?>(view), ADASCallback {
init {
PM2ADASModel.INSTANCE.init(context)
initListener()
}
private fun initListener() {
PM2ADASModel.INSTANCE.setAdasCallback(this)
}
private fun removeListener() {
PM2ADASModel.INSTANCE.setAdasCallback(null)
}
override fun onDestroy(owner: LifecycleOwner) {
super.onDestroy(owner)
removeListener()
}
override fun updateHDMapStations(stations: MutableList<MutableList<Double>>) {
for (i in stations.indices){
mView?.setMapMaker(M2_MAP_STATION_MAKER,stations[i])
}
}
override fun removeHDMapStations() {
mView?.removeMapMaker(M2_MAP_STATION_MAKER)
}
}

View File

@@ -6,6 +6,7 @@ import com.mogo.eagle.core.utilcode.util.UiThreadHandler
import com.mogo.och.bus.passenger.bean.PM2Station
import com.mogo.och.bus.passenger.callback.AutoPilotStatusCallback
import com.mogo.och.bus.passenger.callback.DrivingInfoCallback
import com.mogo.och.bus.passenger.model.PM2ADASModel
import com.mogo.och.bus.passenger.model.PM2DrivingModel
import com.mogo.och.bus.passenger.ui.PM2DrivingInfoFragment
@@ -14,11 +15,13 @@ class PM2DrivingPresenter(view: PM2DrivingInfoFragment?) :
init {
PM2DrivingModel.INSTANCE.init(context)
PM2ADASModel.INSTANCE.init(context)
initListener()
}
override fun onDestroy(owner: LifecycleOwner) {
super.onDestroy(owner)
destroyListener()
PM2DrivingModel.INSTANCE.releaseListener()
}
@@ -29,6 +32,7 @@ class PM2DrivingPresenter(view: PM2DrivingInfoFragment?) :
private fun destroyListener(){
PM2DrivingModel.INSTANCE.setDrivingInfoCallback(null)
PM2DrivingModel.INSTANCE.setAutoStatusCallback(null)
}
override fun updateSpeed(speed: Int) {
@@ -64,12 +68,16 @@ class PM2DrivingPresenter(view: PM2DrivingInfoFragment?) :
UiThreadHandler.post {
mView?.showNoTaskView(!isTrue)
}
if (isTrue){
PM2ADASModel.INSTANCE.removeHDMapStations()
}
}
override fun updateLineStations(stations: MutableList<PM2Station>) {
UiThreadHandler.post {
mView?.updateLineStations(stations)
}
PM2ADASModel.INSTANCE.updateHDMapStations(stations)
}
override fun updateAutoStatus(isOpen: Boolean) {

View File

@@ -1,8 +1,16 @@
package com.mogo.och.bus.passenger.ui
import com.mogo.commons.AbsMogoApplication
import com.mogo.commons.mvp.MvpFragment
import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager.getMapUIController
import com.mogo.eagle.core.function.call.map.CallerMapUIServiceManager.getMarkerManager
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.d
import com.mogo.map.marker.MogoMarkerOptions
import com.mogo.och.bus.passenger.R
import com.mogo.och.bus.passenger.constant.M2Const.Companion.TYPE_MARKER_M2_LINE
import com.mogo.och.bus.passenger.presenter.PM2ADASPresenter
import com.mogo.och.common.module.utils.OCHThreadPoolManager
import java.util.*
/**
* @author: wangmingjun
@@ -34,4 +42,54 @@ class PM2HPMapFragment :
companion object {
private val TAG = PM2HPMapFragment::class.java.simpleName
}
fun setMapMaker(
uuid: String,
station: MutableList<Double>,
) {
//开启线程执行起终点marker设置
val setMapMarkerRunnable = Runnable {
d(
"setMapMaker= " + Thread.currentThread().name,
uuid + "=latitude=" + station[1] + ",longitude=" + station[0]
)
val options = MogoMarkerOptions()
.owner(TYPE_MARKER_M2_LINE)
.anchor(0.5f, 0.5f)
.set3DMode(true)
.gps(true)
.controlAngle(true)
.icon3DRes(R.raw.bus_di)
.longitude(station[0])
.latitude(station[1])
val marker = Objects.requireNonNull(
getMarkerManager(AbsMogoApplication.getApp())
)?.addMarker(uuid, options)
val centerLine =
getMapUIController()!!
.getCenterLineInfo(
station[0], station[1], -1f
)
if (null != centerLine && marker != null) { // 有可能鹰眼map为空没有角度。判空使用后可能造成maker角度跟道路角度不一致
marker.setRotateAngle(centerLine.angle!!.toFloat())
}
}
OCHThreadPoolManager.getsInstance().execute(setMapMarkerRunnable)
}
fun removeMapMaker(
uuid: String,
) {
//开启线程移除起终点marker设置
val removeMapMarkerRunnable = Runnable {
d("RemoveMapMaker=" + Thread.currentThread().name, uuid)
Objects.requireNonNull(
getMarkerManager(
AbsMogoApplication.getApp()
)
)?.removeMarkers(uuid)
}
OCHThreadPoolManager.getsInstance().execute(removeMapMarkerRunnable)
}
}