[清扫车]任务轨迹路线绘制逻辑修改处理

This commit is contained in:
bxb
2023-03-09 23:03:21 +08:00
parent e75fc7567a
commit 1d313e79e4
13 changed files with 510 additions and 300 deletions

View File

@@ -1,5 +1,6 @@
package com.mogo.och.sweeper.bean;
import java.io.Serializable;
import java.util.List;
/**
@@ -7,7 +8,7 @@ import java.util.List;
*
* 订单状态更新请求数据结构
*/
public class SweeperRoutePlanningUpdateReqBean {
public class SweeperRoutePlanningUpdateReqBean implements Serializable {
public String sn;
public int lineId;
public int startSiteId;

View File

@@ -1,10 +1,12 @@
package com.mogo.och.sweeper.callback
import com.mogo.och.sweeper.bean.SweeperMainTaskBean
import com.mogo.och.sweeper.bean.SweeperRoutePlanningUpdateReqBean
import com.mogo.och.sweeper.bean.SweeperSubTaskBean
import com.mogo.och.sweeper.bean.SweeperSubTaskDetailBean
import com.mogo.och.sweeper.constant.SubTaskTypeEnum
import com.mogo.och.sweeper.constant.TaskStatusEnum
import java.util.ArrayList
/**
* @author: wangmingjun
@@ -36,4 +38,9 @@ interface ISweeperTaskCallback {
*/
fun setSubTakDetail(subTaskDetailBean: SweeperSubTaskDetailBean,subTaskTypeEnum: SubTaskTypeEnum)
/**
* 设置轨迹坐标点集合
*/
fun setRouteList(routeList: ArrayList<SweeperRoutePlanningUpdateReqBean.Result>)
}

View File

@@ -0,0 +1,14 @@
package com.mogo.och.sweeper.callback
import com.amap.api.maps.model.LatLng
import com.mogo.och.sweeper.bean.SweeperRoutePlanningUpdateReqBean
import com.mogo.och.sweeper.database.bean.WeltDataBean
import java.util.ArrayList
interface ISweeperTaskDataToFragmentCallback {
fun setRouteList(routeList: ArrayList<SweeperRoutePlanningUpdateReqBean.Result>)
fun setWeltData(weltDatas: ArrayList<WeltDataBean>?, distance: String)
fun clearAllMarkerAndPolyline()
fun setProgress(progress:String)
fun setTaskListCoordinatesLatLng(coordinatesLatLng: ArrayList<LatLng>)
}

View File

@@ -0,0 +1,8 @@
package com.mogo.och.sweeper.callback
import com.mogo.och.sweeper.bean.SweeperRoutePlanningUpdateReqBean
import java.util.ArrayList
interface ISweeperTaskRouteCallback {
fun setRouteList(routeList:ArrayList<SweeperRoutePlanningUpdateReqBean.Result>)
}

View File

@@ -6,7 +6,7 @@ import com.mogo.och.sweeper.database.bean.WeltDataBean;
import java.util.ArrayList;
public class WeltDataEvent{
private int type; //1.添加起点和终点 2.实时添加贴边数据 3.清除数据 4.任务进度
private int type; //1.添加起点和终点 2.实时添加贴边数据 3.清除数据 4.任务进度 5:任务轨迹数据
private ArrayList<WeltDataBean> weltDataBeanList;
private ArrayList<LatLng> markers;
private String distance;//贴边数据

View File

@@ -32,15 +32,17 @@ import com.mogo.map.uicontroller.IMogoMapUIController;
import com.mogo.map.uicontroller.VisualAngleMode;
import com.mogo.och.common.module.map.AmapNaviToDestinationModel;
import com.mogo.och.sweeper.R;
import com.mogo.och.sweeper.bean.SweeperRoutePlanningUpdateReqBean;
import com.mogo.och.sweeper.callback.ISweeperTaskDataToFragmentCallback;
import com.mogo.och.sweeper.callback.IWeltMapSwitchToSmallCallback;
import com.mogo.och.sweeper.database.bean.WeltDataBean;
import com.mogo.och.sweeper.event.WeltDataEvent;
import com.mogo.och.sweeper.view.SweeperTrafficDataView;
import com.mogo.och.sweeper.view.WeltSmallMapView;
import org.greenrobot.eventbus.EventBus;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -55,7 +57,7 @@ import androidx.fragment.app.FragmentTransaction;
* @author tongchenfei
*/
public abstract class BaseSweeperTabFragment<V extends IView, P extends Presenter<V>> extends MvpFragment<V, P> implements IMogoMapListener,
View.OnClickListener, IWeltMapSwitchToSmallCallback,View.OnTouchListener {
View.OnClickListener, IWeltMapSwitchToSmallCallback, View.OnTouchListener {
private static final String TAG = "BaseSweeperTabFragment";
//地图放大缩小
@@ -88,9 +90,11 @@ public abstract class BaseSweeperTabFragment<V extends IView, P extends Presente
private DriverMsgBoxButtonView mViewDriverMsgBoxButton;
private DriverMsgBoxListView mViewDriverMsgBoxList;
private DriverMsgBoxBubbleView mViewDriverMsgBoxBubble;
private ArrayList<WeltDataBean> weltDataBeanList;//存储贴边数据
private ArrayList<LatLng> latLngList;//存储任务起点和终点
private ArrayList<WeltDataBean> mWeltDataBeanList;//存储贴边数据
private ArrayList<LatLng> mSubTaskCoordinates;//存储当前大任务的所有子任务起点和终点
private ArrayList<SweeperRoutePlanningUpdateReqBean.Result> mRouteList;//存储任务的坐标轨迹
private String mProgress;
private ISweeperTaskDataToFragmentCallback mTaskDataToFragmentCallback;
@Override
protected int getLayoutId() {
@@ -167,17 +171,19 @@ public abstract class BaseSweeperTabFragment<V extends IView, P extends Presente
/**
* 设置任务进度
*
* @param progress
*/
protected void setTaskProgress(String progress) {
ThreadUtils.runOnUiThread(()->{
ThreadUtils.runOnUiThread(() -> {
mMapWeltView.setTaskProgress(progress);
mProgress=progress;
mProgress = progress;
if (mTaskDataToFragmentCallback != null) {
mTaskDataToFragmentCallback.setProgress(progress);
}
});
WeltDataEvent weltDataEvent= new WeltDataEvent(4);
weltDataEvent.setProgress(progress);
EventBus.getDefault().postSticky(weltDataEvent);
}
@Override
protected void initViews(Bundle savedInstanceState) {
super.initViews(savedInstanceState);
@@ -409,7 +415,8 @@ public abstract class BaseSweeperTabFragment<V extends IView, P extends Presente
if (isShow) {
mFlWeltMapOverView.setVisibility(View.VISIBLE);
if (mWeltMapOverViewFragment == null) {
mWeltMapOverViewFragment = mWeltMapOverViewFragment.newInstance(this, weltDataBeanList, latLngList,mProgress);
mWeltMapOverViewFragment = mWeltMapOverViewFragment.newInstance((IWeltMapSwitchToSmallCallback) this, mWeltDataBeanList,
mSubTaskCoordinates, mRouteList, mProgress, (SweeperFragment) this);
}
if (mWeltMapOverViewFragment.isHidden()) {
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
@@ -445,33 +452,28 @@ public abstract class BaseSweeperTabFragment<V extends IView, P extends Presente
* @param weltDataBeans
*/
public void setWeltDataToMap(ArrayList<WeltDataBean> weltDataBeans, Boolean isWeltData, String distance) {
if (mMapWeltView != null) {
UiThreadHandler.post(() -> {
mMapWeltView.setWeltData(weltDataBeans, isWeltData, distance);
mMapWeltView.drawablePolyline();
});
}
this.weltDataBeanList = weltDataBeans;
WeltDataEvent weltDataEvent= new WeltDataEvent(2);
weltDataEvent.setWeltDataBeanList(weltDataBeanList);
weltDataEvent.setDistance(distance);
EventBus.getDefault().postSticky(weltDataEvent);
mWeltDataBeanList = weltDataBeans;
ThreadUtils.getSinglePool().execute(new Runnable() {
@Override
public void run() {
if (mMapWeltView != null) {
mMapWeltView.setWeltData(weltDataBeans, isWeltData, distance);
}
if (mTaskDataToFragmentCallback != null) {
mTaskDataToFragmentCallback.setWeltData(weltDataBeans, distance);
}
}
});
}
/**
* 作业任务全览图的添加起点和终点
*/
public void addStartAndEndMarker(LatLng startPoint, LatLng endPoint) {
public void setTaskListCoordinatesLatLng(ArrayList<LatLng> subTaskCoordinates) {
this.mSubTaskCoordinates = subTaskCoordinates;
if (mMapWeltView != null) {
mMapWeltView.addStartAndEndMarker(startPoint, endPoint);
mMapWeltView.setTaskListCoordinatesLatLng(subTaskCoordinates);
}
if (mTaskDataToFragmentCallback != null) {
mTaskDataToFragmentCallback.setTaskListCoordinatesLatLng(subTaskCoordinates);
}
ArrayList<LatLng> latLngs = new ArrayList<>(2);
latLngs.add(0, startPoint);
latLngs.add(1, endPoint);
this.latLngList = latLngs;
WeltDataEvent weltDataEvent= new WeltDataEvent(1);
weltDataEvent.setMarkers(latLngs);
EventBus.getDefault().postSticky(weltDataEvent);
}
/**
@@ -481,7 +483,9 @@ public abstract class BaseSweeperTabFragment<V extends IView, P extends Presente
if (mMapWeltView != null) {
mMapWeltView.clearAllMarkerAndPolyline();
}
EventBus.getDefault().postSticky(new WeltDataEvent(3));
if (mTaskDataToFragmentCallback != null) {
mTaskDataToFragmentCallback.clearAllMarkerAndPolyline();
}
}
/**
@@ -495,10 +499,75 @@ public abstract class BaseSweeperTabFragment<V extends IView, P extends Presente
AmapNaviToDestinationModel.getInstance(getContext()).setVoiceIsMute(isVoicePlay);
}
/**
* 设置任务轨迹点数据
*/
public void setTaskRouteList(ArrayList<SweeperRoutePlanningUpdateReqBean.Result> routeList) {
mRouteList = routeList;
ThreadUtils.getSinglePool().execute(new Runnable() {
@Override
public void run() {
mMapWeltView.setRouteList(routeList);
if (mTaskDataToFragmentCallback != null) {
mTaskDataToFragmentCallback.setRouteList(routeList);
}
}
});
}
public static String format(double value) {
BigDecimal bd = new BigDecimal(value);
bd = bd.setScale(2, RoundingMode.HALF_UP);
return bd.toString();
}
public void setTaskDataToFragmentCallback(ISweeperTaskDataToFragmentCallback mTaskDataToFragmentCallback) {
this.mTaskDataToFragmentCallback = mTaskDataToFragmentCallback;
}
/**
* 结束子任务
*/
public void debugEndSubTask() {
ArrayList<SweeperRoutePlanningUpdateReqBean.Result> resultArrayList = tempData();
setTaskRouteList(resultArrayList);
UiThreadHandler.postDelayed(() -> {
ArrayList<SweeperRoutePlanningUpdateReqBean.Result> routeList =tempData1();
ArrayList<WeltDataBean> weltDataBeans = new ArrayList<>();
ArrayList<LatLng> subTaskCoordinates=new ArrayList<>();
for (int i = 0; i < routeList.size(); i++) {
WeltDataBean weltDataBean = new WeltDataBean();
weltDataBean.setLocLon(routeList.get(i).longitude);
weltDataBean.setLocLat(routeList.get(i).latitude);
weltDataBean.setWeltDistance(Math.random() * 50);
weltDataBeans.add(weltDataBean);
subTaskCoordinates.add(new LatLng(routeList.get(i).latitude,routeList.get(i).longitude));
}
setTaskListCoordinatesLatLng(subTaskCoordinates);
setWeltDataToMap(weltDataBeans, true, format(Math.random() * 50));
}, 2000);
}
private ArrayList<SweeperRoutePlanningUpdateReqBean.Result> tempData() {
ArrayList<SweeperRoutePlanningUpdateReqBean.Result> results = new ArrayList<>();
results.add(getRoute(116.41732262522,39.974576894194));
results.add(getRoute(116.43963532201855,39.9752190287537));
results.add(getRoute(116.4440910789222,39.96469276598098));
results.add(getRoute(116.45254030604285,39.958762580403544));
results.add(getRoute(116.46168616811329,39.94668171374373));
return results;
}
private ArrayList<SweeperRoutePlanningUpdateReqBean.Result> tempData1() {
ArrayList<SweeperRoutePlanningUpdateReqBean.Result> results = new ArrayList<>();
results.add(getRoute(116.41732262522,39.974576894194));
results.add(getRoute(116.43963532201855,39.9752190287537));
results.add(getRoute(116.4440910789222,39.96469276598098));
return results;
}
private SweeperRoutePlanningUpdateReqBean.Result getRoute(double longitude,double latitude){
SweeperRoutePlanningUpdateReqBean.Result result = new SweeperRoutePlanningUpdateReqBean.Result();
result.latitude = latitude;
result.longitude =longitude;
return result;
}
}

View File

@@ -6,6 +6,7 @@ import android.view.View
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import chassis.ChassisStatesOuterClass
import com.amap.api.maps.model.LatLng
import com.mogo.commons.AbsMogoApplication
import com.mogo.eagle.core.data.map.MogoLocation
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.d
@@ -14,14 +15,10 @@ import com.mogo.eagle.core.utilcode.util.ClickUtils
import com.mogo.eagle.core.utilcode.util.ToastUtils
import com.mogo.och.common.module.utils.CoordinateCalculateRouteUtil
import com.mogo.och.sweeper.R
import com.mogo.och.sweeper.bean.SubInfo
import com.mogo.och.sweeper.bean.SweeperMainTaskBean
import com.mogo.och.sweeper.bean.SweeperSubTaskBean
import com.mogo.och.sweeper.bean.SweeperSubTaskDetailBean
import com.mogo.och.sweeper.bean.*
import com.mogo.och.sweeper.constant.SubTaskTypeEnum
import com.mogo.och.sweeper.constant.TaskStatusEnum
import com.mogo.och.sweeper.database.MyDataBase
import com.mogo.och.sweeper.database.bean.WeltDataBean
import com.mogo.och.sweeper.presenter.SweeperPresenter
import com.mogo.och.sweeper.ui.adapter.TaskListAdapter
import com.mogo.och.sweeper.ui.dialog.SweeperManualDrivingDialog
@@ -34,15 +31,17 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.math.BigDecimal
import java.math.RoundingMode
import kotlin.math.roundToInt
/**
* 清扫车主界面
*/
class SweeperFragment : BaseSweeperTabFragment<SweeperFragment?, SweeperPresenter?>(), MenuPopWindow.OnMenuItemOnClickListener {
companion object{
companion object {
const val TAG = "SweeperFragment"
}
private var mAdapter: TaskListAdapter? = null
private var mCurrentSubPosition: Int = 0 //子任务下标
private var mSubMutableList: MutableList<SubInfo>? = null
@@ -68,11 +67,11 @@ class SweeperFragment : BaseSweeperTabFragment<SweeperFragment?, SweeperPresente
mAdapter?.setOnTaskItemClickListener(onTaskItemClickListener)
initListener()
sweeper_cl_work_mode.setTrafficDataView(trafficDataView)
sweeper_current_task_view.readyTaskBtn.setOnClickListener{
if (ClickUtils.isFastClick()){//防止重复点击
if(mSubTaskType.code==SubTaskTypeEnum.MANUAL_DRIVING_SUBTYPE.code){
sweeper_current_task_view.readyTaskBtn.setOnClickListener {
if (ClickUtils.isFastClick()) {//防止重复点击
if (mSubTaskType.code == SubTaskTypeEnum.MANUAL_DRIVING_SUBTYPE.code) {
manualDriving()
}else{
} else {
//开始执行任务
mSubInfo?.apply {
presenter?.startTask(isFirstSubTask(), isLastSubTask(), taskId, mSubTaskType, taskStatus)
@@ -103,7 +102,7 @@ class SweeperFragment : BaseSweeperTabFragment<SweeperFragment?, SweeperPresente
*/
private fun setShowTaskListPanelView(isShow: Boolean) {
tvTaskConfirm.setTextColor(Color.parseColor("#66FFFFFF"))
tvTaskConfirm.isSelected=false
tvTaskConfirm.isSelected = false
if (isShow) {
sweeper_current_task_list_view.visibility = View.VISIBLE
} else {
@@ -211,7 +210,7 @@ class SweeperFragment : BaseSweeperTabFragment<SweeperFragment?, SweeperPresente
/**
* 设置当前主任务列表数据
*/
fun setMainTaskList(mainTaskBeanList: MutableList<SweeperMainTaskBean>?,refresh: Boolean) {
fun setMainTaskList(mainTaskBeanList: MutableList<SweeperMainTaskBean>?, refresh: Boolean) {
setShowCurrentTaskPanelView(false)
setShowTaskListPanelView(true)
sweeper_cl_work_mode.visibility = View.GONE
@@ -223,7 +222,7 @@ class SweeperFragment : BaseSweeperTabFragment<SweeperFragment?, SweeperPresente
noTaskDataView.visibility = View.VISIBLE
sweeperListCl.visibility = View.GONE
}
if (refresh){
if (refresh) {
ToastUtils.showLong("已刷新")
}
}
@@ -268,7 +267,9 @@ class SweeperFragment : BaseSweeperTabFragment<SweeperFragment?, SweeperPresente
//整个大任务结束,则删除它相关的贴边数据缓存
lifecycleScope.launch(Dispatchers.IO) {
MyDataBase.getInstance().weltDataDao.deleteAllWeltData()
mPresenter?.clearRouteList()
}
setTaskProgress("0")
return
}
when (typeEnum.code) {
@@ -307,7 +308,7 @@ class SweeperFragment : BaseSweeperTabFragment<SweeperFragment?, SweeperPresente
TaskStatusEnum.START_SUBTASK.code -> { //子任务开始
setTaskBtn(true)
sweeper_current_task_view.setTaskStatus(2)
if (mSubTaskType==SubTaskTypeEnum.MANUAL_DRIVING_SUBTYPE){
if (mSubTaskType == SubTaskTypeEnum.MANUAL_DRIVING_SUBTYPE) {
sweeper_current_task_view.setCurrentData(mCurrentSubPosition)
}
}
@@ -315,16 +316,6 @@ class SweeperFragment : BaseSweeperTabFragment<SweeperFragment?, SweeperPresente
}
/**
* 子任务信息详情,包括轨迹文件
*/
fun setSubTakDetail(subTaskDetailBean: SweeperSubTaskDetailBean, subTaskTypeEnum: SubTaskTypeEnum) {
// if (subTaskTypeEnum.code == SubTaskTypeEnum.MANUAL_DRIVING_SUBTYPE.code) {//人工驾驶子任务
// this.mSubTaskDetailBean = subTaskDetailBean
// manualDriving(subTaskDetailBean)
// }
}
/**
* 主任务重置
*/
@@ -334,11 +325,12 @@ class SweeperFragment : BaseSweeperTabFragment<SweeperFragment?, SweeperPresente
mPresenter?.getMainTaskList(false)
//清除任务全览图的marker和路线
clearAllMarkerAndPolyline()
showOrHideOverMapViewFragment(false)
showAmapNaviToStationFragment(false)
setTaskProgress("0")
//整个大任务结束,则删除它相关的贴边数据缓存
lifecycleScope.launch(Dispatchers.IO) {
MyDataBase.getInstance().weltDataDao.deleteAllWeltData()
mPresenter?.clearRouteList()
}
}
}
@@ -352,7 +344,7 @@ class SweeperFragment : BaseSweeperTabFragment<SweeperFragment?, SweeperPresente
mSubTaskType = if (it[mCurrentSubPosition].taskType == SubTaskTypeEnum.AUTOPILOT_SUBTYPE.code)
SubTaskTypeEnum.AUTOPILOT_SUBTYPE else SubTaskTypeEnum.MANUAL_DRIVING_SUBTYPE
//设置当前子任务信息
presenter?.setSubtask(isFirstSubTask(), isLastSubTask(), it[mCurrentSubPosition].taskId,it[mCurrentSubPosition].taskType)
presenter?.setSubtask(isFirstSubTask(), isLastSubTask(), it[mCurrentSubPosition].taskId, it[mCurrentSubPosition].taskType)
}
/**
* 计算任务的进度
@@ -369,17 +361,12 @@ class SweeperFragment : BaseSweeperTabFragment<SweeperFragment?, SweeperPresente
current += it[index].mileage
}
}
val progress = "${format((current/sum)*100)}%"
val progress = "${((current / sum) * 100.0).roundToInt()}%"
setTaskProgress(progress)
}
}
}
fun format(value: Double): String? {
var bd = BigDecimal(value)
bd = bd.setScale(2, RoundingMode.HALF_UP)
return bd.toString()
}
/**
* 结束主任务
*/
@@ -472,49 +459,38 @@ class SweeperFragment : BaseSweeperTabFragment<SweeperFragment?, SweeperPresente
if (subList.size <= 0) {
return@launch
}
//添加贴边数据绘制
addStartAndEndMarker(
CoordinateCalculateRouteUtil.coordinateConverterWgsToGcj(
AbsMogoApplication.getApp(),
subList[0].startWgs84Lon,
subList[0].startWgs84Lat
),
CoordinateCalculateRouteUtil.coordinateConverterWgsToGcj(
AbsMogoApplication.getApp(),
subList[subList.size - 1].endWgs84Lon,
subList[subList.size - 1].endWgs84Lat
)
)
val dataList = ArrayList<WeltDataBean>()
val dataList = ArrayList<LatLng>()
for (index in subList.indices) {
val startPoint = CoordinateCalculateRouteUtil.coordinateConverterWgsToGcj(
AbsMogoApplication.getApp(),
subList[index].startWgs84Lon,
subList[index].startWgs84Lat
)
val startWeltData = WeltDataBean()
startWeltData.locLat = startPoint.latitude
startWeltData.locLon = startPoint.longitude
startWeltData.weltDistance = -9999.0
dataList.add(startWeltData)
val startLatLng = LatLng(startPoint.latitude, startPoint.longitude)
dataList.add(index,startLatLng)
val endPoint = CoordinateCalculateRouteUtil.coordinateConverterWgsToGcj(
AbsMogoApplication.getApp(),
subList[index].endWgs84Lon,
subList[index].endWgs84Lat
)
val endWeltData = WeltDataBean()
endWeltData.locLat = endPoint.latitude
endWeltData.locLon = endPoint.longitude
endWeltData.weltDistance = -9999.0
dataList.add(endWeltData)
val endLatLng = LatLng(endPoint.latitude, endPoint.longitude)
dataList.add(index+1,endLatLng)
}
setWeltDataToMap(dataList, false, "0")
setTaskListCoordinatesLatLng(dataList)
}
}
}
//模拟结束子任务
override fun debugEndSubTask() {
mPresenter?.onArriveTaskEnd(null)
//mPresenter?.onArriveTaskEnd(null)
super.debugEndSubTask()
}
/**
* 设置路线轨迹
*/
override fun setTaskRouteList(routeList: ArrayList<SweeperRoutePlanningUpdateReqBean.Result>) {
super.setTaskRouteList(routeList)
}
}

View File

@@ -1,29 +1,22 @@
package com.mogo.och.sweeper.fragment
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.lifecycleScope
import com.amap.api.maps.model.LatLng
import com.mogo.commons.mvp.BaseFragment
import com.mogo.och.sweeper.R
import com.mogo.och.sweeper.bean.SweeperRoutePlanningUpdateReqBean
import com.mogo.och.sweeper.callback.ISweeperTaskDataToFragmentCallback
import com.mogo.och.sweeper.callback.IWeltMapSwitchToSmallCallback
import com.mogo.och.sweeper.database.bean.WeltDataBean
import com.mogo.och.sweeper.event.WeltDataEvent
import kotlinx.android.synthetic.main.fragment_welt_map_overview.*
import kotlinx.android.synthetic.main.sweeper_welt_map_overview.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
/**
* 作业任务全览图
*/
class WeltMapOverViewFragment() : BaseFragment() {
class WeltMapOverViewFragment() : BaseFragment(), ISweeperTaskDataToFragmentCallback {
private var mIWeltMapSwitchToSmallCallBack: IWeltMapSwitchToSmallCallback? = null
private var mFragment: SweeperFragment? = null
override fun getLayoutId(): Int = R.layout.fragment_welt_map_overview
override fun getTagName(): String {
return "WeltMapOverViewFragment"
@@ -35,11 +28,10 @@ class WeltMapOverViewFragment() : BaseFragment() {
fun setWeltMapSwitchToSmallCallBack(iWeltMapSwitchToSmallCallback: IWeltMapSwitchToSmallCallback){
this.mIWeltMapSwitchToSmallCallBack=iWeltMapSwitchToSmallCallback
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
EventBus.getDefault().register(this)
return super.onCreateView(inflater, container, savedInstanceState)
fun setSweeperFragment(fragment: SweeperFragment){
this.mFragment=fragment
mFragment?.setTaskDataToFragmentCallback(this)
}
override fun initViews(savedInstanceState: Bundle?) {
super.initViews(savedInstanceState)
weltMapOverView.onCreateView(savedInstanceState)
@@ -48,17 +40,18 @@ class WeltMapOverViewFragment() : BaseFragment() {
}
val bundle = arguments
if (bundle != null) {
val latLngs = bundle.getSerializable("startAndEndPoint") as? ArrayList<LatLng>
val latLngs = bundle.getSerializable("subTaskCoordinates") as? ArrayList<LatLng>
val weltDataList = bundle.getSerializable("weltDataList") as? ArrayList<WeltDataBean>
val routeList = bundle.getSerializable("routeList") as? ArrayList<SweeperRoutePlanningUpdateReqBean.Result>
val progress = bundle.getString("progress")
routeList?.let {
weltMapOverView.setRouteList(it)
}
latLngs?.let {
if (it.size >= 2) {
addStartAndEndMarker(it[0], it[1])
}
setTaskListCoordinatesLatLng(it)
}
weltDataList?.let {
setWeltData(it,false,"0")
drawablePolyline()
setWeltData(it,"0.0")
}
progress?.let {
weltMapOverView.setProgress(progress)
@@ -73,14 +66,18 @@ class WeltMapOverViewFragment() : BaseFragment() {
mIWeltMapSwitchToSmallCallBack: IWeltMapSwitchToSmallCallback,
weltDataList: ArrayList<WeltDataBean>?,
latLngs: ArrayList<LatLng>?,
progress:String?
routeList: ArrayList<SweeperRoutePlanningUpdateReqBean.Result>?,
progress:String?,
sweeperFragment: SweeperFragment
): WeltMapOverViewFragment {
val args = Bundle()
args.putSerializable("weltDataList", weltDataList)
args.putSerializable("startAndEndPoint", latLngs)
args.putSerializable("subTaskCoordinates", latLngs)
args.putSerializable("routeList", routeList)
args.putString("progress", progress)
val fragment = WeltMapOverViewFragment()
fragment.setWeltMapSwitchToSmallCallBack(mIWeltMapSwitchToSmallCallBack)
fragment.setSweeperFragment(sweeperFragment)
fragment.arguments = args
return fragment
}
@@ -100,56 +97,23 @@ class WeltMapOverViewFragment() : BaseFragment() {
super.onDestroy()
weltMapOverView.onDestroy()
}
override fun onDestroyView() {
super.onDestroyView()
EventBus.getDefault().unregister(this)
override fun setTaskListCoordinatesLatLng(coordinatesLatLng: java.util.ArrayList<LatLng>) {
weltMapOverView.setTaskListCoordinatesLatLng(coordinatesLatLng)
}
@Subscribe(threadMode = ThreadMode.BACKGROUND)
fun changeWeltData(weltDataEvent: WeltDataEvent) {
if (weltDataEvent.type == 1) {
lifecycleScope.launch(Dispatchers.Main) {
weltDataEvent.markers?.let {
addStartAndEndMarker(it[0], it[1])
}
}
} else if (weltDataEvent.type == 2) {
lifecycleScope.launch(Dispatchers.Main) {
setWeltData(weltDataEvent.weltDataBeanList,true,weltDataEvent.distance)
drawablePolyline()
}
} else if (weltDataEvent.type == 3) {
lifecycleScope.launch(Dispatchers.Main) {
clearAllMarkerAndPolyline()
}
}else if (weltDataEvent.type == 4){
weltMapOverView.setProgress(weltDataEvent.progress)
}
}
/**
* 设置任务路线数据
*/
private fun setWeltData(weltDatas: MutableList<WeltDataBean>?,isWeltData:Boolean,distance:String) {
weltMapOverView.setWeltData(weltDatas,isWeltData,distance)
}
/**
* 绘制任务路线数据
*/
private fun drawablePolyline() {
weltMapOverView.drawablePolyline()
}
/**
* 添加起点和终点marker
*/
private fun addStartAndEndMarker(startPoint: LatLng, endPoint: LatLng) {
weltMapOverView.drawStartAndEndMarker(startPoint, endPoint)
}
private fun clearAllMarkerAndPolyline() {
override fun clearAllMarkerAndPolyline() {
weltMapOverView.clearAllMarkerAndPolyline()
}
override fun setProgress(progress: String) {
weltMapOverView.setProgress(progress)
}
override fun setRouteList(routeList: java.util.ArrayList<SweeperRoutePlanningUpdateReqBean.Result>) {
weltMapOverView.setRouteList(routeList)
}
override fun setWeltData(weltDatas: java.util.ArrayList<WeltDataBean>?, distance: String) {
weltMapOverView.setWeltData(weltDatas,true,distance)
}
}

View File

@@ -46,6 +46,7 @@ import com.mogo.och.sweeper.bean.SweeperSubTaskDetailBean;
import com.mogo.och.sweeper.callback.ISweeperADASStatusCallback;
import com.mogo.och.sweeper.callback.ISweeperControllerStatusCallback;
import com.mogo.och.sweeper.callback.ISweeperTaskCallback;
import com.mogo.och.sweeper.callback.ISweeperTaskRouteCallback;
import com.mogo.och.sweeper.constant.SubTaskTypeEnum;
import com.mogo.och.sweeper.constant.SweeperConst;
import com.mogo.och.sweeper.constant.TaskStatusEnum;
@@ -83,7 +84,7 @@ public class SweeperTaskModel {
private ISweeperControllerStatusCallback mControllerStatusCallback; //Model->PresenterVR mode等
private ISweeperADASStatusCallback mADASStatusCallback;
private ISweeperTaskCallback mSweeperTaskCallback;
List<SweeperRoutePlanningUpdateReqBean.Result> points = new ArrayList<>();//全路径信息
ArrayList<SweeperRoutePlanningUpdateReqBean.Result> points = new ArrayList<>();//全路径信息
//当前子任务详情信息包括轨迹文件信息
private SweeperSubTaskDetailBean mCurrentSubTaskDetail;
//子任务是否正在进行中
@@ -97,12 +98,17 @@ public class SweeperTaskModel {
//当前任务是否是第一个
private boolean mIsFirstSubtask = false;
//当前任务是否是第一个
private int mSubTaskType=0; //1自动驾驶 2.人工驾驶
private int mSubTaskType = 0; //1自动驾驶 2.人工驾驶
//0: 代表没有启动过 1代表是启动第一次当>=1 代表是重试 每次子任务结束/主任务结束清空置为0
private volatile int firstStartAutopilot = 0;
private int mLineId;//路线id
//自动驾驶状态
private int mAutopilotState = IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_DISABLE;
private String longitude;//经度
private String latitude;//纬度
public static SweeperTaskModel getInstance() {
if (sInstance == null) {
synchronized (SweeperTaskModel.class) {
@@ -190,27 +196,42 @@ public class SweeperTaskModel {
@Override
public void onAutopilotRotting(MessagePad.GlobalPathResp routeList) {
if (null != routeList && routeList.getWayPointsList().size() > 0) {
points.clear();
points.addAll(coordinateConverterWgsToGcjList(mContext, routeList.getWayPointsList()));
if (mCurrentSubTaskDetail.getLineId() != mLineId) {//判断是否同一条路线
mLineId = mCurrentSubTaskDetail.getLineId();
points.addAll(coordinateConverterWgsToGcjList(mContext, routeList.getWayPointsList()));
if (mSweeperTaskCallback != null) {
mSweeperTaskCallback.setRouteList(points);
}
}
}
}
};
public void setSubtask(boolean isFirstSubtask, boolean isLastSubtask, int subTaskId,int subTaskType) {
public void setSubtask(boolean isFirstSubtask, boolean isLastSubtask, int subTaskId, int subTaskType) {
this.mIsLastSubtask = isLastSubtask;
this.mIsFirstSubtask = isFirstSubtask;
this.mSubTaskId = subTaskId;
this.mSubTaskType=subTaskType;
this.mSubTaskType = subTaskType;
}
/**
* 清除路线缓存数据
*/
public void clearRouteList() {
points.clear();
mSubTaskType=0;
}
/**
* 保存自动驾驶状态
*
* @param autopilotState
*/
public void setAutopilotState(int autopilotState){
this.mAutopilotState=autopilotState;
public void setAutopilotState(int autopilotState) {
this.mAutopilotState = autopilotState;
}
public static List<SweeperRoutePlanningUpdateReqBean.Result> coordinateConverterWgsToGcjList(Context mContext,
List<MessagePad.Location> mogoLatLngList) {
List<SweeperRoutePlanningUpdateReqBean.Result> points = new ArrayList<>();
@@ -247,11 +268,11 @@ public class SweeperTaskModel {
@Override
public void onMsgReceived(OCHOperationalMessage obj) {
if (obj == null){
if (obj == null) {
CallerLogger.INSTANCE.d(M_SWEEPER + TAG, "onMsgReceived = null");
return;
}
CallerLogger.INSTANCE.d(M_SWEEPER + TAG, "onMsgReceived = "+obj.getMessage());
CallerLogger.INSTANCE.d(M_SWEEPER + TAG, "onMsgReceived = " + obj.getMessage());
OCHSocketMessageManager.INSTANCE.pushAppOperationalMsgBox(obj.getPushTimeStamp(),
obj.getMessage());
}
@@ -290,16 +311,39 @@ public class SweeperTaskModel {
if (mControllerStatusCallback != null) {
mControllerStatusCallback.onCarLocationChanged(gnssInfo);
}
if (mSubTaskType==2){//人工驾驶子任务需要手动跳过,不能自动结束
if (mSubTaskType == 2) {//人工驾驶子任务需要手动跳过,不能自动结束
addCoordinates(gnssInfo);
return;
}
//子任务完成的围栏判断 子任务正在执行中,还未到达子任务终点
if (mIsSubTaskWorking&&!isArriveSubTaskEndSite) {
if (mIsSubTaskWorking && !isArriveSubTaskEndSite) {
judgeArrivedStation(gnssInfo);
}
}
};
/**
* 根据当前定位收集人工驾驶子任务轨迹点
*
* @param mogoLatLng
*/
private void addCoordinates(MogoLocation mogoLatLng) {
String tempLongitude = NumberFormatUtil.cutOutNumber(mogoLatLng.getLongitude(), 5);
String tempLatitude = NumberFormatUtil.cutOutNumber(mogoLatLng.getLatitude(), 5);
//用于过滤车是否停在原地,经纬度相同的情况
if (!tempLongitude.equals(longitude) && !tempLatitude.equals(latitude)) {
latitude = NumberFormatUtil.cutOutNumber(mogoLatLng.getLatitude(), 5);
longitude = NumberFormatUtil.cutOutNumber(mogoLatLng.getLongitude(), 5);
SweeperRoutePlanningUpdateReqBean.Result result = new SweeperRoutePlanningUpdateReqBean.Result();
result.latitude = mogoLatLng.getLatitude();
result.longitude = mogoLatLng.getLongitude();
points.add(result);
if (mSweeperTaskCallback != null) {
mSweeperTaskCallback.setRouteList(points);
}
}
}
//根据围栏判断,是否到达子任务终点
private void judgeArrivedStation(MogoLocation location) {
double endSiteLon = mCurrentSubTaskDetail.getEndSiteLon();
@@ -312,7 +356,7 @@ public class SweeperTaskModel {
+ " to " + mCurrentSubTaskDetail.getEndSiteName());
Log.d(TAG, "行程日志-judgeArrivedStation() distance = " + distance
+ " to " + mCurrentSubTaskDetail.getEndSiteName());
isArriveSubTaskEndSite=true;
isArriveSubTaskEndSite = true;
//到达子任务终点 结束子任务
subTaskEnd(mIsFirstSubtask, mIsLastSubtask, mSubTaskId); //无自动驾驶到终点信息传null
return;
@@ -363,9 +407,11 @@ public class SweeperTaskModel {
public boolean getSubWorking() {
return mIsSubTaskWorking;
}
public void setWorking(Boolean isWorking){
this.mIsSubTaskWorking=isWorking;
public void setWorking(Boolean isWorking) {
this.mIsSubTaskWorking = isWorking;
}
/**
* 关闭美化模式
*/
@@ -393,10 +439,10 @@ public class SweeperTaskModel {
//MAP 280 每隔100ms左右返回一次到站 导致在到达中间站后再次滑动出发后会有时间差,收到一次到站,出现问题
//此处比对 自驾告诉的子任务终点坐标和本地应到子任务终点坐标, 一致时才表示子任务完成
if (data != null && data.getEndLocation() != null && mCurrentSubTaskDetail != null) {
Log.d(M_SWEEPER + TAG, "MAP到站通知"+mCurrentSubTaskDetail.getEndSiteName()+"经度:"
+data.getEndLocation().getLongitude()+"纬度:"+data.getEndLocation().getLongitude());
CallerLogger.INSTANCE.d(M_SWEEPER + TAG, "MAP到站通知"+mCurrentSubTaskDetail.getEndSiteName()+"经度:"
+data.getEndLocation().getLongitude()+"纬度:"+data.getEndLocation().getLatitude());
Log.d(M_SWEEPER + TAG, "MAP到站通知" + mCurrentSubTaskDetail.getEndSiteName() + "经度:"
+ data.getEndLocation().getLongitude() + "纬度:" + data.getEndLocation().getLongitude());
CallerLogger.INSTANCE.d(M_SWEEPER + TAG, "MAP到站通知" + mCurrentSubTaskDetail.getEndSiteName() + "经度:"
+ data.getEndLocation().getLongitude() + "纬度:" + data.getEndLocation().getLatitude());
String latitude = NumberFormatUtil.cutOutNumber(data.getEndLocation().getLatitude(), 5); //wgs
String longitude = NumberFormatUtil.cutOutNumber(data.getEndLocation().getLongitude(), 5);
String arriveLat = NumberFormatUtil.cutOutNumber(mCurrentSubTaskDetail.getEndSiteWgs64Lat(), 5);
@@ -406,13 +452,13 @@ public class SweeperTaskModel {
return;
}
}
if (mSubTaskType==2){//人工驾驶子任务需要手动跳过,不能自动结束
if (mSubTaskType == 2) {//人工驾驶子任务需要手动跳过,不能自动结束
return;
}
if (isArriveSubTaskEndSite) return;
CallerLogger.INSTANCE.d(M_SWEEPER + TAG, "行程日志-当前==subTaskId="
+ mSubTaskId);
isArriveSubTaskEndSite=true;
isArriveSubTaskEndSite = true;
//到达子任务终点 结束子任务
subTaskEnd(mIsFirstSubtask, mIsLastSubtask, mSubTaskId);
}
@@ -424,9 +470,11 @@ public class SweeperTaskModel {
SweeperAnalyticsManager.getInstance().triggerStartAutopilotEvent(isRestart, send,
mCurrentSubTaskDetail.getStartSiteName(), mCurrentSubTaskDetail.getEndSiteName(), mCurrentSubTaskDetail.getLineId());
}
public boolean isRestartAutopilot() {
return firstStartAutopilot > 1;
}
public void triggerUnableStartAPReasonEvent() {
if (mCurrentSubTaskDetail == null) {
return;
@@ -530,7 +578,7 @@ public class SweeperTaskModel {
CallerLogger.INSTANCE.d(M_SWEEPER + TAG, "getMainTaskList" + GsonUtil.jsonFromObject(data));
if (mSweeperTaskCallback != null && data != null && data.getCode() == 0) {
List<SweeperMainTaskBean> list = data.getData();
mSweeperTaskCallback.setMainTaskList(list,refresh);
mSweeperTaskCallback.setMainTaskList(list, refresh);
}
}
@@ -616,7 +664,7 @@ public class SweeperTaskModel {
/**
* 在自动驾驶状态
*/
if (isStartSubtask&&mAutopilotState==IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) {//是否需要自动开始执行任务
if (isStartSubtask && mAutopilotState == IMoGoAutopilotStatusListener.STATUS_AUTOPILOT_RUNNING) {//是否需要自动开始执行任务
subTaskStart(isFirst, isEnd, subTaskId, subTaskType);
}
}
@@ -657,7 +705,7 @@ public class SweeperTaskModel {
if (mSweeperTaskCallback != null && data != null) {
if (data.getData()) {
mIsSubTaskWorking = true;
isArriveSubTaskEndSite=false;
isArriveSubTaskEndSite = false;
mSweeperTaskCallback.updateSubTaskStatus(TaskStatusEnum.START_SUBTASK, false);
if (subTaskType == SubTaskTypeEnum.AUTOPILOT_SUBTYPE) {//如果是自动驾驶子任务子开启自驾
if (FunctionBuildConfig.isDemoMode) {//美化模式开启时
@@ -708,7 +756,7 @@ public class SweeperTaskModel {
if (data != null) {
if (data.getData()) {
mIsSubTaskWorking = false;
if (mSweeperTaskCallback!=null){
if (mSweeperTaskCallback != null) {
mSweeperTaskCallback.updateSubTaskStatus(TaskStatusEnum.END_SUBTASK, isEnd);
}
if (isEnd) {

View File

@@ -18,11 +18,13 @@ import com.mogo.och.common.module.manager.OCHAdasAbilityManager;
import com.mogo.och.common.module.utils.CoordinateCalculateRouteUtil;
import com.mogo.och.common.module.utils.NumberFormatUtil;
import com.mogo.och.sweeper.bean.SweeperMainTaskBean;
import com.mogo.och.sweeper.bean.SweeperRoutePlanningUpdateReqBean;
import com.mogo.och.sweeper.bean.SweeperSubTaskBean;
import com.mogo.och.sweeper.bean.SweeperSubTaskDetailBean;
import com.mogo.och.sweeper.callback.ISweeperADASStatusCallback;
import com.mogo.och.sweeper.callback.ISweeperControllerStatusCallback;
import com.mogo.och.sweeper.callback.ISweeperTaskCallback;
import com.mogo.och.sweeper.callback.ISweeperTaskRouteCallback;
import com.mogo.och.sweeper.constant.SubTaskTypeEnum;
import com.mogo.och.sweeper.constant.TaskStatusEnum;
import com.mogo.och.sweeper.database.MyDataBase;
@@ -57,7 +59,7 @@ import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_SWE
*/
public class SweeperPresenter extends Presenter<SweeperFragment>
implements IMoGoAutopilotStatusListener, ISweeperControllerStatusCallback, ISweeperADASStatusCallback,
IMoGoSweeperFutianCleanSystemListener, ISweeperTaskCallback {
IMoGoSweeperFutianCleanSystemListener, ISweeperTaskCallback, ISweeperTaskRouteCallback {
private static final String TAG = "SweeperPresenter";
//当前子任务id
@@ -181,7 +183,12 @@ public class SweeperPresenter extends Presenter<SweeperFragment>
public void startOpenAutopilot() {
}
/**
* 清除路线缓存数据
*/
public void clearRouteList(){
SweeperTaskModel.getInstance().clearRouteList();
}
public void startAutopilot() {
SweeperTaskModel.getInstance().startAutopilot();
}
@@ -435,10 +442,9 @@ public class SweeperPresenter extends Presenter<SweeperFragment>
@Override
public void setSubTakDetail(@NonNull SweeperSubTaskDetailBean subTaskDetailBean, SubTaskTypeEnum subTaskTypeEnum) {
mView.setSubTakDetail(subTaskDetailBean, subTaskTypeEnum);
}
//mock贴边数据
private void weltData(MogoLocation location){
@Override
public void setRouteList(@NonNull ArrayList<SweeperRoutePlanningUpdateReqBean.Result> routeList) {
//mView.setTaskRouteList(routeList);
}
}

View File

@@ -16,7 +16,9 @@ import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationGCJ02Liste
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02ListenerManager
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant
import com.mogo.eagle.core.utilcode.util.ThreadUtils
import com.mogo.och.sweeper.R
import com.mogo.och.sweeper.bean.SweeperRoutePlanningUpdateReqBean
import com.mogo.och.sweeper.database.bean.WeltDataBean
import com.mogo.och.sweeper.util.SweeperMapAssetStyleUtil
import kotlinx.android.synthetic.main.sweeper_welt_map_overview.view.*
@@ -25,12 +27,11 @@ import kotlinx.android.synthetic.main.sweeper_welt_map_overview.view.*
* 作业任务全览图
*/
class WeltMapOverView : ConstraintLayout, IMoGoChassisLocationGCJ02Listener {
private var mWeltData: MutableList<WeltDataBean> = mutableListOf() //任务数据集合
private var mCoordinatesLatLng: MutableList<LatLng> = mutableListOf() //任务坐标点
private var mTaskCoordinatesLatLng: MutableList<LatLng> = mutableListOf() //当前大任务的所有起终点集合
private var mCarMarker: Marker? = null
private var mAMap: AMap? = null
private var mPolyline: Polyline? = null
private var colorList: MutableList<Int> = mutableListOf()
private var mPolylines: MutableList<Polyline?> = mutableListOf()
private var mRoutePolylines: Polyline?=null
private val mLineMarkers: MutableList<Marker?> = mutableListOf()
private var mFirst: Boolean = false
@@ -102,40 +103,45 @@ class WeltMapOverView : ConstraintLayout, IMoGoChassisLocationGCJ02Listener {
/**
* 添加画线颜色值
*/
private fun addRouteColorList() {
for (i in mWeltData.indices) {
if (mWeltData[i].weltDistance == -9999.0) {//未经过
private fun getRouteColorList(weltData: MutableList<WeltDataBean>):MutableList<Int> {
val colorList= mutableListOf<Int>()
for (i in weltData.indices) {
if (weltData[i].weltDistance == -9999.0) {//未经过
colorList.add(Color.parseColor("#3BA1CC"))
} else if (mWeltData[i].weltDistance == -10000.0) {//非贴边
} else if (weltData[i].weltDistance == -10000.0) {//非贴边
colorList.add(Color.parseColor("#236299"))
} else if (mWeltData[i].weltDistance < 0) {
} else if (weltData[i].weltDistance < 0) {
colorList.add(Color.parseColor("#C22101"))
} else if (mWeltData[i].weltDistance >= 0 && mWeltData[i].weltDistance < 10) {
} else if (weltData[i].weltDistance >= 0 && weltData[i].weltDistance < 10) {
colorList.add(Color.parseColor("#4DFFA4"))
} else if (mWeltData[i].weltDistance >= 10 && mWeltData[i].weltDistance < 20) {
} else if (weltData[i].weltDistance >= 10 && weltData[i].weltDistance < 20) {
colorList.add(Color.parseColor("#FFDD4D"))
} else if (mWeltData[i].weltDistance >= 20) {
} else if (weltData[i].weltDistance >= 20) {
colorList.add(Color.parseColor("#FF912B"))
}
}
return colorList
}
override fun onChassisLocationGCJ02(mogoLocation: MogoLocation?) {
mogoLocation?.let { gnssInfo ->
val currentLatLng = LatLng(gnssInfo.latitude, gnssInfo.longitude)
//更新车辆位置
mCarMarker?.rotateAngle = (360 - gnssInfo.heading).toFloat()
mCarMarker?.position = currentLatLng
mCarMarker?.setToTop()
//圈定地图显示范围
val boundsBuilder = LatLngBounds.Builder()
if (mCoordinatesLatLng.size > 0) {
//存放经纬度
for (i in mCoordinatesLatLng.indices) {
boundsBuilder.include(mCoordinatesLatLng[i])
ThreadUtils.getSinglePool().run {
mogoLocation?.let { gnssInfo ->
val currentLatLng = LatLng(gnssInfo.latitude, gnssInfo.longitude)
//更新车辆位置
mCarMarker?.rotateAngle = (360 - gnssInfo.heading).toFloat()
mCarMarker?.position = currentLatLng
mCarMarker?.setToTop()
//圈定地图显示范围
val boundsBuilder = LatLngBounds.Builder()
if (mTaskCoordinatesLatLng.size > 0) {
//存放经纬度
for (i in mTaskCoordinatesLatLng.indices) {
boundsBuilder.include(mTaskCoordinatesLatLng[i])
}
}
boundsBuilder.include(currentLatLng)
mAMap?.moveCamera(CameraUpdateFactory.newLatLngBoundsRect(boundsBuilder.build(), 100, 100, 100, 100))
}
}
}
@@ -143,20 +149,24 @@ class WeltMapOverView : ConstraintLayout, IMoGoChassisLocationGCJ02Listener {
/**
* 根据贴边数据绘制任务路线
*/
fun drawablePolyline() {
mPolyline?.remove()
if (mAMap != null) {
addRouteColorList()
if (mWeltData.size >= 2 && mCoordinatesLatLng.size > 2) {
fun drawablePolyline(weltDatas: MutableList<WeltDataBean>?) {
weltDatas?.let {
val colorList=getRouteColorList(it)
val coordinatesLatLngs= mutableListOf<LatLng>()
for (i in it.indices) {
coordinatesLatLngs.add(LatLng(it[i].locLat,it[i].locLon))
}
if (coordinatesLatLngs.size > 2) {
//设置线段纹理
val polylineOptions = PolylineOptions()
polylineOptions.addAll(mCoordinatesLatLng)
polylineOptions.addAll(coordinatesLatLngs)
polylineOptions.width(14f) //线段宽度
polylineOptions.isUseTexture = false
polylineOptions.lineCapType(PolylineOptions.LineCapType.LineCapSquare)
polylineOptions.colorValues(colorList)
polylineOptions.visible(true)
// 绘制线
mPolyline = mAMap?.addPolyline(polylineOptions)
mPolylines.add(mAMap?.addPolyline(polylineOptions))
}
}
}
@@ -164,7 +174,7 @@ class WeltMapOverView : ConstraintLayout, IMoGoChassisLocationGCJ02Listener {
/**
* 绘制起点和终点的marker
*/
fun drawStartAndEndMarker(startPoint: LatLng, endPoint: LatLng) {
private fun drawStartAndEndMarker(startPoint: LatLng, endPoint: LatLng) {
val startMarker = mAMap?.addMarker(MarkerOptions().icon(BitmapDescriptorFactory.fromResource(R.drawable.sweeper_big_start_maker_icon)))
startMarker?.position = startPoint
mLineMarkers.add(startMarker)
@@ -177,11 +187,14 @@ class WeltMapOverView : ConstraintLayout, IMoGoChassisLocationGCJ02Listener {
* 清除所有标记和路线
*/
fun clearAllMarkerAndPolyline() {
mPolyline?.remove()
for (i in mLineMarkers.indices) {
mLineMarkers[i]?.isVisible = false
mLineMarkers[i]?.remove()
}
for (i in mPolylines.indices) {
mPolylines[i]?.remove()
}
mRoutePolylines?.remove()
mLineMarkers.clear()
//mFirst = false
//showOrHiddenLegendData(false)
@@ -190,22 +203,54 @@ class WeltMapOverView : ConstraintLayout, IMoGoChassisLocationGCJ02Listener {
/**
* 设置贴边数据
*/
fun setWeltData(weltData: MutableList<WeltDataBean>?, isWeltData: Boolean, distance: String?) {
if (weltData != null) {
this.mWeltData.addAll(weltData)
for (i in mWeltData.indices) {
mCoordinatesLatLng.add(LatLng(mWeltData[i].locLat, mWeltData[i].locLon))
fun setWeltData(weltDatas: MutableList<WeltDataBean>?, isWeltData: Boolean, distance: String?) {
drawablePolyline(weltDatas)
ThreadUtils.runOnUiThread {
distance?.let {
setDistance(it)
}
}
distance?.let {
setDistance(it)
}
//if (!mFirst && isWeltData) {
// mFirst = true
// showOrHiddenLegendData(true)
//}
}
/**
* 任务轨迹数据
*/
fun setRouteList(routeList: ArrayList<SweeperRoutePlanningUpdateReqBean.Result>) {
val routeCoordinatesLatLngs= mutableListOf<LatLng>()
for (i in routeList.indices) {
routeCoordinatesLatLngs.add(LatLng(routeList[i].latitude,routeList[i].longitude))
}
drawRouteListPolyline(routeCoordinatesLatLngs)
}
private fun drawRouteListPolyline(routeList: MutableList<LatLng>) {
mRoutePolylines?.remove()
val polylineOptions = PolylineOptions()
polylineOptions.width(14f) //线段宽度
polylineOptions.isUseTexture = false
polylineOptions.lineCapType(PolylineOptions.LineCapType.LineCapSquare)
polylineOptions.color(Color.parseColor("#3BA1CC"))
polylineOptions.addAll(routeList)
polylineOptions.visible(true)
mRoutePolylines=mAMap?.addPolyline(polylineOptions)
}
/**
* 设置当前大任务的所有子任务起终点集合
*/
fun setTaskListCoordinatesLatLng(coordinatesLatLng: MutableList<LatLng>) {
ThreadUtils.runOnUiThread {
this.mTaskCoordinatesLatLng = coordinatesLatLng
if (mTaskCoordinatesLatLng.size > 0) {
drawStartAndEndMarker(mTaskCoordinatesLatLng[0], mTaskCoordinatesLatLng[mTaskCoordinatesLatLng.size - 1])
}
}
}
/**
* 设置图例数据
*/
@@ -222,14 +267,22 @@ class WeltMapOverView : ConstraintLayout, IMoGoChassisLocationGCJ02Listener {
private fun setDistance(distance: String) {
taskWeltDistanceTv.text = "贴边:${distance}cm"
}
fun setProgress(progress:String?){
fun setProgress(progress: String?) {
progress?.let {
taskProgressTv.visibility=View.VISIBLE
taskWeltDistanceTv.visibility=View.VISIBLE
taskProgressTv.text=it
showOrHiddenLegendData(true)
if ("0" == progress) {
taskProgressTv.visibility = View.GONE
taskWeltDistanceTv.visibility = View.GONE
showOrHiddenLegendData(false)
} else {
taskProgressTv.visibility = View.VISIBLE
taskWeltDistanceTv.visibility = View.VISIBLE
taskProgressTv.text = it
showOrHiddenLegendData(true)
}
}
}
fun onCreateView(savedInstanceState: Bundle?) {
sweeperTextureMapView.onCreate(savedInstanceState)
}

View File

@@ -4,6 +4,7 @@ import android.content.Context
import android.graphics.Color
import android.os.Bundle
import android.util.AttributeSet
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
@@ -16,22 +17,23 @@ import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationGCJ02Liste
import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02ListenerManager
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.d
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant
import com.mogo.och.common.module.utils.CoordinateCalculateRouteUtil
import com.mogo.eagle.core.utilcode.util.ThreadUtils
import com.mogo.och.sweeper.R
import com.mogo.och.sweeper.bean.SweeperRoutePlanningUpdateReqBean
import com.mogo.och.sweeper.database.bean.WeltDataBean
import com.mogo.och.sweeper.util.SweeperMapAssetStyleUtil
import kotlinx.android.synthetic.main.sweeper_welt_small_map_view.view.*
/**
* 作业任务小地图
*/
class WeltSmallMapView : ConstraintLayout, IMoGoChassisLocationGCJ02Listener {
private var mWeltData: MutableList<WeltDataBean> = mutableListOf() //任务数据集合
private var mCoordinatesLatLng: MutableList<LatLng> = mutableListOf() //任务坐标点
private var mTaskCoordinatesLatLng: MutableList<LatLng> = mutableListOf() //当前大任务的所有起终点集合
private var mCarMarker: Marker? = null
private var mAMap: AMap? = null
private var mPolyline: Polyline? = null
private var colorList: MutableList<Int> = mutableListOf()
private var mPolylines: MutableList<Polyline?> = mutableListOf()
private var mRoutePolylines: Polyline?=null
private val mLineMarkers: MutableList<Marker?> = mutableListOf()
//清扫车任务地图
@@ -53,19 +55,22 @@ class WeltSmallMapView : ConstraintLayout, IMoGoChassisLocationGCJ02Listener {
}
override fun onChassisLocationGCJ02(mogoLocation: MogoLocation?) {
mogoLocation?.let {
val currentLatLng = LatLng(it.latitude, it.longitude)
drawCarMarker(mogoLocation)
//圈定地图显示范围
val boundsBuilder = LatLngBounds.Builder()
if (mCoordinatesLatLng.size > 0) {
//存放经纬度
for (i in mCoordinatesLatLng.indices) {
boundsBuilder.include(mCoordinatesLatLng[i])
d(SceneConstant.M_SWEEPER + TAG, "mogoLocation$mogoLocation")
ThreadUtils.getSinglePool().run {
mogoLocation?.let {
val currentLatLng = LatLng(it.latitude, it.longitude)
drawCarMarker(mogoLocation)
//圈定地图显示范围
val boundsBuilder = LatLngBounds.Builder()
if (mTaskCoordinatesLatLng.size > 0) {
//存放经纬度
for (i in mTaskCoordinatesLatLng.indices) {
boundsBuilder.include(mTaskCoordinatesLatLng[i])
}
}
boundsBuilder.include(currentLatLng)
mAMap!!.moveCamera(CameraUpdateFactory.newLatLngBoundsRect(boundsBuilder.build(), 100, 100, 100, 100))
}
boundsBuilder.include(currentLatLng)
mAMap!!.moveCamera(CameraUpdateFactory.newLatLngBoundsRect(boundsBuilder.build(), 100, 100, 100, 100))
}
}
@@ -126,50 +131,57 @@ class WeltSmallMapView : ConstraintLayout, IMoGoChassisLocationGCJ02Listener {
}
/**
* 添加画线颜色值
* 根据贴边数据绘制任务路线
*/
private fun addRouteColorList() {
for (i in mWeltData.indices) {
if (mWeltData[i].weltDistance == -9999.0) {//未经过
colorList.add(Color.parseColor("#3BA1CC"))
} else if (mWeltData[i].weltDistance == -10000.0) {//非贴边
colorList.add(Color.parseColor("#236299"))
} else if (mWeltData[i].weltDistance < 0) {
colorList.add(Color.parseColor("#C22101"))
} else if (mWeltData[i].weltDistance >= 0 && mWeltData[i].weltDistance < 10) {
colorList.add(Color.parseColor("#4DFFA4"))
} else if (mWeltData[i].weltDistance >= 10 && mWeltData[i].weltDistance < 20) {
colorList.add(Color.parseColor("#FFDD4D"))
} else if (mWeltData[i].weltDistance >= 20) {
colorList.add(Color.parseColor("#FF912B"))
private fun drawablePolyline(weltDatas: MutableList<WeltDataBean>?) {
weltDatas?.let {
val colorList = getRouteColorList(it)
val coordinatesLatLngs = mutableListOf<LatLng>()
for (i in it.indices) {
coordinatesLatLngs.add(LatLng(it[i].locLat,it[i].locLon))
}
if (coordinatesLatLngs.size > 2) {
//设置线段纹理
val polylineOptions = PolylineOptions()
polylineOptions.addAll(coordinatesLatLngs)
polylineOptions.width(30f) //线段宽度
polylineOptions.isUseTexture = false
polylineOptions.lineCapType(PolylineOptions.LineCapType.LineCapSquare)
polylineOptions.colorValues(colorList)
polylineOptions.visible(true)
// 绘制线
mPolylines.add(mAMap?.addPolyline(polylineOptions))
}
}
}
/**
* 根据贴边数据绘制任务路线
* 添加画线颜色值
*/
fun drawablePolyline() {
mPolyline?.remove()
if (mAMap != null) {
addRouteColorList()
if (mWeltData.size >= 2 && mCoordinatesLatLng.size > 2) {
val polylineOptions = PolylineOptions()
polylineOptions.addAll(mCoordinatesLatLng)
polylineOptions.width(14f) //线段宽度
polylineOptions.isUseTexture = false
polylineOptions.lineCapType(PolylineOptions.LineCapType.LineCapSquare)
polylineOptions.colorValues(colorList)
// 绘制线
mPolyline = mAMap?.addPolyline(polylineOptions)
private fun getRouteColorList(weltData: MutableList<WeltDataBean>): MutableList<Int> {
val colorList = mutableListOf<Int>()
for (i in weltData.indices) {
if (weltData[i].weltDistance == -9999.0) {//未经过
colorList.add(Color.parseColor("#3BA1CC"))
} else if (weltData[i].weltDistance == -10000.0) {//非贴边
colorList.add(Color.parseColor("#236299"))
} else if (weltData[i].weltDistance < 0) {
colorList.add(Color.parseColor("#C22101"))
} else if (weltData[i].weltDistance >= 0 && weltData[i].weltDistance < 10) {
colorList.add(Color.parseColor("#4DFFA4"))
} else if (weltData[i].weltDistance >= 10 && weltData[i].weltDistance < 20) {
colorList.add(Color.parseColor("#FFDD4D"))
} else if (weltData[i].weltDistance >= 20) {
colorList.add(Color.parseColor("#FF912B"))
}
}
return colorList
}
/**
* 添加起点和终点的marker
*/
fun addStartAndEndMarker(startPoint: LatLng, endPoint: LatLng) {
private fun addStartAndEndMarker(startPoint: LatLng, endPoint: LatLng) {
for (i in mLineMarkers.indices) {
mLineMarkers[i]?.isVisible = false
mLineMarkers[i]?.remove()
@@ -183,16 +195,33 @@ class WeltSmallMapView : ConstraintLayout, IMoGoChassisLocationGCJ02Listener {
mLineMarkers.add(endMarker)
}
/**
* 设置当前大任务的所有子任务起终点集合
*/
fun setTaskListCoordinatesLatLng(coordinatesLatLng: MutableList<LatLng>) {
this.mTaskCoordinatesLatLng = coordinatesLatLng
if (mTaskCoordinatesLatLng.size > 0) {
d(
SceneConstant.M_SWEEPER + TAG,
"startPoint${mTaskCoordinatesLatLng[0]} endPoint${mTaskCoordinatesLatLng[mTaskCoordinatesLatLng.size - 1]}"
)
addStartAndEndMarker(mTaskCoordinatesLatLng[0], mTaskCoordinatesLatLng[mTaskCoordinatesLatLng.size - 1])
}
}
/**
* 清除所有标记和路线
*/
fun clearAllMarkerAndPolyline() {
mPolyline?.remove()
for (i in mLineMarkers.indices) {
mLineMarkers[i]?.isVisible = false
mLineMarkers[i]?.remove()
}
for (i in mPolylines.indices) {
mPolylines[i]?.remove()
}
mLineMarkers.clear()
mRoutePolylines?.remove()
//mFirst = false
//showOrHiddenWelt(false)
}
@@ -210,25 +239,60 @@ class WeltSmallMapView : ConstraintLayout, IMoGoChassisLocationGCJ02Listener {
/**
* 设置贴边数据
*/
fun setWeltData(weltData: MutableList<WeltDataBean>, isWeltData: Boolean, distance: String) {
this.mWeltData = weltData
for (i in mWeltData.indices) {
mCoordinatesLatLng.add(CoordinateCalculateRouteUtil.coordinateConverterWgsToGcj(context, mWeltData[i].locLon, mWeltData[i].locLat))
fun setWeltData(weltDatas: MutableList<WeltDataBean>, isWeltData: Boolean, distance: String) {
drawablePolyline(weltDatas)
ThreadUtils.runOnUiThread {
setWeltDistance(distance)
}
taskWeltDistanceTv.text = "贴边:${distance}cm"
//if (!mFirst&&isWeltData) {
// showOrHiddenWelt(true)
// mFirst = true
//}
}
/**
* 设置贴边距离
*/
private fun setWeltDistance(distance: String) {
taskWeltDistanceTv.text = "贴边:${distance}cm"
}
/**
* 设置任务轨迹数据
*/
fun setRouteList(routeList: ArrayList<SweeperRoutePlanningUpdateReqBean.Result>) {
val routeCoordinatesLatLngs = mutableListOf<LatLng>()
for (i in routeList.indices) {
routeCoordinatesLatLngs.add(LatLng(routeList[i].latitude, routeList[i].longitude))
}
drawRouteListPolyline(routeCoordinatesLatLngs)
}
private fun drawRouteListPolyline(routeList: MutableList<LatLng>) {
mRoutePolylines?.remove()
val polylineOptions = PolylineOptions()
polylineOptions.addAll(routeList)
polylineOptions.width(14f) //线段宽度
polylineOptions.isUseTexture = false
polylineOptions.lineCapType(PolylineOptions.LineCapType.LineCapSquare)
polylineOptions.color(Color.parseColor("#3BA1CC"))
polylineOptions.visible(true)
mRoutePolylines=mAMap?.addPolyline(polylineOptions)
}
/**
* 设置任务进度
*/
fun setTaskProgress(progress: String?) {
taskWeltDistanceTv.visibility = View.VISIBLE
taskProgressTv.visibility = View.VISIBLE
taskProgressTv.text = progress
if (progress == "0") {
taskWeltDistanceTv.visibility = View.GONE
taskProgressTv.visibility = View.GONE
} else {
taskWeltDistanceTv.visibility = View.VISIBLE
taskProgressTv.visibility = View.VISIBLE
taskProgressTv.text = progress
}
}
fun onCreateView(savedInstanceState: Bundle?) {

View File

@@ -41,7 +41,7 @@
android:id="@+id/taskWeltDistanceTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="贴边:8cm"
android:text="贴边:0.0cm"
app:layout_constraintTop_toTopOf="parent"
android:background="#3d98c7"
android:textColor="@color/white"