增加Obu他车绘制
This commit is contained in:
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -31,7 +31,7 @@
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="Embedded JDK" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="Embedded JDK" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="VisualizationToolProject">
|
||||
|
||||
@@ -34,7 +34,7 @@ allprojects {
|
||||
* 步骤2:添加依赖关系
|
||||
```groovy
|
||||
dependencies {
|
||||
implementation 'com.zhidao.support.obu:mogoobu:1.0.0.7'
|
||||
implementation 'com.zhidao.support.obu:mogoobu:1.0.0.8'
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
@@ -1,28 +1,25 @@
|
||||
package com.mogo.module.obu.mogo;
|
||||
package com.mogo.module.obu.mogo
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.obu.IMoGoObuProvider;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import android.content.Context
|
||||
import com.alibaba.android.arouter.facade.annotation.Route
|
||||
import com.mogo.module.obu.mogo.MogoPrivateObuManager.Companion.INSTANCE
|
||||
import com.mogo.module.obu.mogo.map.ObuRecognizedResultDrawer
|
||||
import com.mogo.service.MogoServicePaths
|
||||
import com.mogo.service.obu.IMoGoObuProvider
|
||||
import com.mogo.utils.logger.Logger
|
||||
|
||||
/**
|
||||
* @author xiaoyuzhou
|
||||
* @date 2021/8/2 5:52 下午
|
||||
*/
|
||||
@Route(path = MogoServicePaths.PATH_V2X_OBU_MOGO)
|
||||
public class MoGoObuProvider implements IMoGoObuProvider {
|
||||
private String TAG = "MoGoObuProvider";
|
||||
class MoGoObuProvider : IMoGoObuProvider {
|
||||
private val TAG = "MoGoObuProvider"
|
||||
override fun init(context: Context) {
|
||||
Logger.d(MogoObuConst.TAG_MOGO_OBU, "初始化蘑菇自研OBU……")
|
||||
|
||||
@Override
|
||||
public void init(Context context) {
|
||||
Logger.d(MogoObuConst.TAG_MOGO_OBU, "初始化蘑菇自研OBU……");
|
||||
|
||||
// MogoPrivateObuManager.getInstance().init(context);
|
||||
MogoPrivateObuManager.Companion.getINSTANCE().init(context);
|
||||
// MogoPrivateObuManager.getInstance().init(context);
|
||||
INSTANCE.init(context)
|
||||
ObuRecognizedResultDrawer()
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package com.mogo.module.obu.mogo.map
|
||||
|
||||
import android.content.Context
|
||||
import android.os.Handler
|
||||
import android.os.Message
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
import com.mogo.map.MogoLatLng
|
||||
import com.mogo.map.marker.IMogoMarker
|
||||
import com.mogo.map.marker.MogoMarkerOptions
|
||||
import com.mogo.module.common.MogoApisHandler
|
||||
import com.mogo.module.common.R
|
||||
import com.mogo.module.common.constants.DataTypes
|
||||
import com.mogo.utils.WorkThreadHandler
|
||||
import com.mogo.utils.logger.Logger
|
||||
import com.zhidao.support.obu.model.CvxRvInfoIndInfo
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
/**
|
||||
* @author xiaoyuzhou
|
||||
* @date 2021/8/9 11:08 上午
|
||||
*/
|
||||
class ObuRecognizedResultDrawer() {
|
||||
|
||||
private val TAG = "ObuRecognizedResultDrawer"
|
||||
|
||||
private var mContext: Context? = null
|
||||
|
||||
// 维护Obu识别的他车集合
|
||||
private val mCvxRvInfoIndInfoMap = ConcurrentHashMap<String, CvxRvInfoIndInfo>()
|
||||
|
||||
// 地图内部资源md5缓存,便于资源复用
|
||||
private val mMarkerCachesResMd5Values = ConcurrentHashMap<Int, String>()
|
||||
|
||||
// 上一帧数据的缓存,用来做移动动画
|
||||
private val mMarkersCaches = ConcurrentHashMap<String, IMogoMarker>()
|
||||
|
||||
//
|
||||
private val notShowThresholdValue = 1000
|
||||
|
||||
// 动画持续时间
|
||||
private val stepTime = 100L
|
||||
|
||||
// 维护一个线程定时轮询数据进行地图绘制
|
||||
private val mDrawerHandler: Handler =
|
||||
object : Handler(WorkThreadHandler.newInstance("other_car_obu_drawer").looper) {
|
||||
override fun handleMessage(msg: Message) {
|
||||
super.handleMessage(msg)
|
||||
drawerCvxRvInfo()
|
||||
|
||||
// 延时50毫秒重复发送自己,定时轮询进行车辆绘制,可以及时将已经不存在车辆删除
|
||||
sendEmptyMessageDelayed(0, 100L)
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
mContext = AbsMogoApplication.getApp()
|
||||
mDrawerHandler.sendEmptyMessageDelayed(1, 0L)
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加识别的数据
|
||||
*/
|
||||
fun addCvxRvInfoIndInfo(key: String, value: CvxRvInfoIndInfo) {
|
||||
mCvxRvInfoIndInfoMap[key] = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除识别的数据
|
||||
*/
|
||||
fun removeCvxRvInfoIndInfo(key: String) {
|
||||
mCvxRvInfoIndInfoMap.remove(key)
|
||||
}
|
||||
|
||||
/**
|
||||
* 绘制
|
||||
*/
|
||||
private fun drawerCvxRvInfo() {
|
||||
//Logger.d(TAG, "drawerCvxRvInfo")
|
||||
// 数据为空的时候清除所有数据
|
||||
if (mCvxRvInfoIndInfoMap.isEmpty()) {
|
||||
mMarkersCaches.forEach {
|
||||
it.value.remove()
|
||||
}
|
||||
mMarkersCaches.clear()
|
||||
} else {
|
||||
// 循环绘制识别的数据
|
||||
mCvxRvInfoIndInfoMap.forEach {
|
||||
// 如果数据已经存在 Marker,取出做动画
|
||||
if (mMarkersCaches[it.key] != null) {
|
||||
mMarkersCaches[it.key]?.let { it1 ->
|
||||
changeDynamicMarker(it1, it.value)
|
||||
}
|
||||
}
|
||||
// 不存在的添加Marker绘制
|
||||
else {
|
||||
drawObuRecognizedDataMarker(it.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 绘制单条
|
||||
*/
|
||||
private fun drawObuRecognizedDataMarker(cvxRvInfoIndInfo: CvxRvInfoIndInfo): IMogoMarker {
|
||||
val resId: Int = R.raw.tachexiaoche
|
||||
val resIdVal = resId.toString() + ""
|
||||
|
||||
val options = MogoMarkerOptions()
|
||||
.owner(DataTypes.TYPE_MARKER_ADAS)
|
||||
.anchor(0.5f, 0.5f)
|
||||
.set3DMode(true)
|
||||
.gps(true)
|
||||
.controlAngle(true)
|
||||
.resName(mMarkerCachesResMd5Values[resIdVal])
|
||||
.icon3DRes(resId)
|
||||
.rotate(cvxRvInfoIndInfo.basic_info.heading.toFloat())
|
||||
.position(
|
||||
MogoLatLng(
|
||||
cvxRvInfoIndInfo.basic_info.position.latitude,
|
||||
cvxRvInfoIndInfo.basic_info.position.longitude
|
||||
)
|
||||
)
|
||||
val marker = MogoApisHandler.getInstance().apis.mapServiceApi.getMarkerManager(mContext)
|
||||
.addMarker(DataTypes.TYPE_MARKER_ADAS, options)
|
||||
|
||||
// 缓存数据
|
||||
mMarkersCaches[cvxRvInfoIndInfo.vehicle_id] = marker
|
||||
return marker
|
||||
}
|
||||
|
||||
/**
|
||||
* 带动画的修改Marker
|
||||
*/
|
||||
private fun changeDynamicMarker(
|
||||
marker: IMogoMarker,
|
||||
cvxRvInfoIndInfo: CvxRvInfoIndInfo
|
||||
): IMogoMarker {
|
||||
|
||||
val renderLoc = MogoLatLng(
|
||||
cvxRvInfoIndInfo.basic_info.position.latitude,
|
||||
cvxRvInfoIndInfo.basic_info.position.longitude
|
||||
)
|
||||
|
||||
marker.addDynamicAnchorPosition(
|
||||
renderLoc,
|
||||
cvxRvInfoIndInfo.basic_info.heading.toFloat(),
|
||||
stepTime
|
||||
)
|
||||
|
||||
return marker
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user