diff --git a/OCH/mogo-och-common-module/src/debug/AndroidManifest.xml b/OCH/mogo-och-common-module/src/debug/AndroidManifest.xml new file mode 100644 index 0000000000..7d64112bb0 --- /dev/null +++ b/OCH/mogo-och-common-module/src/debug/AndroidManifest.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/OCH/mogo-och-common-module/src/debug/java/com/mogo/och/common/module/debug/BizBroadcastReceiver.kt b/OCH/mogo-och-common-module/src/debug/java/com/mogo/och/common/module/debug/BizBroadcastReceiver.kt new file mode 100644 index 0000000000..b33df5e396 --- /dev/null +++ b/OCH/mogo-och-common-module/src/debug/java/com/mogo/och/common/module/debug/BizBroadcastReceiver.kt @@ -0,0 +1,38 @@ +package com.mogo.och.common.module.debug + +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger +import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant + +class BizBroadcastReceiver: BroadcastReceiver() { + + private var mContext: Context? = null + + companion object { + private const val TAG = "BizBroadcastReceiver" + // 类型 + private const val type = "type" + // 数据源 + private const val sourceFile = "path" + // 数据频率 默认1s一次 -1 发送一次 + private const val frequencyKey = "fre" + } + + override fun onReceive(context: Context, intent: Intent) { + try { + mContext = context + val type = intent.getStringExtra(type) + val frequency = intent.getIntExtra(frequencyKey,1) + val sourceFilePath = intent.getStringExtra(sourceFile) + CallerLogger.d("${SceneConstant.M_OCHCOMMON}${TAG}", + "类型:${type} 频率:${frequency} 命令所在文件:${sourceFilePath}" + ) + DebugDataDispatch.disPathc(type,frequency,sourceFilePath) + } catch (e: Exception) { + e.printStackTrace() + } + } + +} \ No newline at end of file diff --git a/OCH/mogo-och-common-module/src/debug/java/com/mogo/och/common/module/debug/DebugDataDispatch.kt b/OCH/mogo-och-common-module/src/debug/java/com/mogo/och/common/module/debug/DebugDataDispatch.kt new file mode 100644 index 0000000000..ed7619f7b4 --- /dev/null +++ b/OCH/mogo-och-common-module/src/debug/java/com/mogo/och/common/module/debug/DebugDataDispatch.kt @@ -0,0 +1,125 @@ +package com.mogo.och.common.module.debug + +import android.os.Environment +import com.amap.api.maps.model.LatLng +import com.google.gson.reflect.TypeToken +import com.mogo.eagle.core.data.enums.DataSourceType +import com.mogo.eagle.core.data.map.MogoLocation +import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02ListenerManager +import com.mogo.eagle.core.function.call.autopilot.CallerPlanningRottingListenerManager +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.GsonUtils +import com.mogo.eagle.core.utilcode.util.ThreadUtils +import com.mogo.och.common.module.debug.location.MogoLocationExit +import com.mogo.och.common.module.utils.CoordinateCalculateRouteUtil +import mogo.telematics.pad.MessagePad +import java.io.BufferedReader +import java.io.File +import java.io.FileInputStream +import java.io.IOException +import java.io.InputStreamReader + +object DebugDataDispatch { + + const val TAG = "DebugDataDispatch" + + const val globalPathMock = "globalPath" + const val locationMock = "location" + + val ROOT_PATH = + Environment.getExternalStorageDirectory().absolutePath + File.separator + "MLog" + File.separator + "APPLog" + File.separator //程序外部存储跟目录 + + + fun disPathc(type: String?, frequency: Int, sourceFilePath: String?) { + when (type) { + globalPathMock -> { + sourceFilePath?.let { + loadRawPoints(ROOT_PATH+it) + } + } + locationMock -> { + sourceFilePath?.let { + getLocaitonByLog(ROOT_PATH+it) + } + } + else -> {} + } + } + + fun getLocaitonByLog(path:String) { + ThreadUtils.getIoPool().execute { + val inputStream = FileInputStream(path) + val reader = BufferedReader(InputStreamReader(inputStream)) + var line: String? = "" + try { + while (reader.readLine().also { line = it } != null) { + val list = GsonUtils.fromJson( + line.toString(), + object : TypeToken() {}.type + ) + val mogoLocation = MogoLocation() + mogoLocation.latitude = list.msg.GnssInfo.latitude + mogoLocation.longitude = list.msg.GnssInfo.longitude + mogoLocation.heading = list.msg.GnssInfo.heading + mogoLocation.gnssSpeed = list.msg.GnssInfo.gnssSpeed.toFloat() + CallerChassisLocationGCJ02ListenerManager.invokeChassisLocationGCJ02( + mogoLocation, + DataSourceType.OBU + ) + Thread.sleep(100) + } + } catch (e: IOException) { + e.printStackTrace() + } + } + } + + fun loadRawPoints(path:String) { + val inputStream = FileInputStream(path) + val reader = BufferedReader(InputStreamReader(inputStream)) + val jsonStr = StringBuilder() + var line: String? = "" + try { + while (reader.readLine().also { line = it } != null) { + jsonStr.append(line) + } + } catch (e: IOException) { + e.printStackTrace() + } + val list = GsonUtils.fromJson>( + jsonStr.toString(), + object : TypeToken?>() {}.type + ) + val newBuilder = MessagePad.GlobalPathResp.newBuilder() + + for (latLng in list) { + val locationBuilder = MessagePad.Location.newBuilder() + locationBuilder.latitude = latLng.latitude + locationBuilder.longitude = latLng.longitude + newBuilder.addWayPoints(locationBuilder) + } + + val mogoLocation = MogoLocation() + + mogoLocation.latitude = list[0].latitude + mogoLocation.longitude = list[0].longitude + + val mogoSecondLocation = MogoLocation() + mogoSecondLocation.latitude = list[1].latitude + mogoSecondLocation.longitude = list[1].longitude + val angle = CoordinateCalculateRouteUtil.getHeadingAngle( + mogoLocation, + mogoSecondLocation + ) + mogoLocation.heading = angle + + CallerChassisLocationGCJ02ListenerManager.invokeChassisLocationGCJ02( + mogoLocation, + DataSourceType.OBU + ) + CallerLogger.d(SceneConstant.M_OCHCOMMON + TAG,"轨迹点个数:${list.size}") + // 发送轨迹 + CallerPlanningRottingListenerManager.invokeAutopilotRotting(newBuilder.build()) + } +} \ No newline at end of file diff --git a/OCH/mogo-och-common-module/src/debug/java/com/mogo/och/common/module/debug/location/MogoLocationExit.kt b/OCH/mogo-och-common-module/src/debug/java/com/mogo/och/common/module/debug/location/MogoLocationExit.kt new file mode 100644 index 0000000000..838e172b40 --- /dev/null +++ b/OCH/mogo-och-common-module/src/debug/java/com/mogo/och/common/module/debug/location/MogoLocationExit.kt @@ -0,0 +1,30 @@ +package com.mogo.och.common.module.debug.location + +data class MogoLocationExit( + val localTime: Long, + val msg: Msg +) +data class Msg( + val GnssInfo: GnssInfo, + val Header: Header, + val stringDate0: String +) + +data class Header( + val msgID: Int, + val msgType: String, + val sourceTimestamp: Double, + val timestamp: Double +) + +data class GnssInfo( + val acceleration: Double, + val altitude: Double, + val gnssSpeed: Double, + val heading: Double, + val latitude: Double, + val longitude: Double, + val satelliteTime: Double, + val systemTime: Double, + val yawRate: Double +) \ No newline at end of file diff --git a/OCH/mogo-och-common-module/src/main/java/com/mogo/och/common/module/manager/trajectorymamager/TrajectoryAndDistanceManager.kt b/OCH/mogo-och-common-module/src/main/java/com/mogo/och/common/module/manager/trajectorymamager/TrajectoryAndDistanceManager.kt index 83dea72860..0d3931b481 100644 --- a/OCH/mogo-och-common-module/src/main/java/com/mogo/och/common/module/manager/trajectorymamager/TrajectoryAndDistanceManager.kt +++ b/OCH/mogo-och-common-module/src/main/java/com/mogo/och/common/module/manager/trajectorymamager/TrajectoryAndDistanceManager.kt @@ -139,6 +139,9 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{ endCalculateDistanceLoop() return } + if(it.latitude==0.0&&it.longitude==0.0){ + return + } calculateRouteSumLength(it) } } @@ -180,7 +183,7 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{ this.startStationInfo.distance = startStationInfo.third preCarLocationIndexInTrajectory = startStationInfo.first val calculateData = "距离起始站点最近的点:${startStationInfo.first} 点在站的后面:${startStationInfo.second} 距离点的距离:${startStationInfo.third}" - val locationInfo = "定位信息:${location.latitude},${location.longitude}" + val locationInfo = "定位信息:${location.latitude},${location.longitude},${location.heading}" writeLog(calculateData,locationInfo) } @@ -198,7 +201,7 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{ this.endStationInfo.index = endStationInfo.first this.endStationInfo.distance = endStationInfo.third val calculateData = "距离结束站点最近的点:${endStationInfo.first} 点在站的后面:${endStationInfo.second} 距离点的距离:${endStationInfo.third}" - val locationInfo = "定位信息:${location.latitude},${location.longitude}" + val locationInfo = "定位信息:${location.latitude},${location.longitude},${location.heading}" writeLog(calculateData, locationInfo) } @@ -214,7 +217,7 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{ ) } val calculateData = "距离结束站点最近的点:${carLocationInfo.first} 点在站的后面:${carLocationInfo.second} 距离点的距离:${carLocationInfo.third}" - val locationInfo = "定位信息:${location.latitude},${location.longitude}" + val locationInfo = "定位信息:${location.latitude},${location.longitude},${location.heading}" writeLog(calculateData, locationInfo) if(carLocationInfo.second==null||carLocationInfo.third>1_000){ preCarLocationIndexInTrajectory = 0 diff --git a/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/callback/IOCHTaxiAutopilotPlanningCallback.java b/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/callback/IOCHTaxiAutopilotPlanningCallback.java index bdd1d074cc..481bb3c470 100644 --- a/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/callback/IOCHTaxiAutopilotPlanningCallback.java +++ b/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/callback/IOCHTaxiAutopilotPlanningCallback.java @@ -2,6 +2,7 @@ package com.mogo.och.taxi.callback; import com.amap.api.maps.model.LatLng; +import com.mogo.eagle.core.data.map.MogoLocation; import java.util.List; @@ -10,6 +11,6 @@ import java.util.List; * @date: 2021/11/1 */ public interface IOCHTaxiAutopilotPlanningCallback { - void setLineMarker(List models); - void routeResult(List models, int haveArrivedIndex); + void setLineMarker(LatLng startStation,LatLng endStation); + void routeResult(List routeArrivied,List routeArriving, MogoLocation location); } \ No newline at end of file diff --git a/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/model/TaxiModel.java b/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/model/TaxiModel.java index c754678d1e..efebd2d20b 100644 --- a/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/model/TaxiModel.java +++ b/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/model/TaxiModel.java @@ -49,6 +49,8 @@ import com.mogo.och.common.module.biz.provider.LoginService; import com.mogo.och.common.module.callback.OchAdasStartFailureCallback; import com.mogo.och.common.module.manager.AbnormalFactorsLoopManager; import com.mogo.och.common.module.manager.OCHAdasAbilityManager; +import com.mogo.och.common.module.manager.trajectorymamager.IDistanceListener; +import com.mogo.och.common.module.manager.trajectorymamager.ITrajectoryListener; import com.mogo.och.common.module.manager.trajectorymamager.TrajectoryAndDistanceManager; import com.mogo.och.common.module.map.AmapNaviToDestinationModel; import com.mogo.och.common.module.utils.CoordinateCalculateRouteUtil; @@ -237,6 +239,9 @@ public class TaxiModel { AbnormalFactorsLoopManager.INSTANCE.startLoopAbnormalFactors(mContext); + TrajectoryAndDistanceManager.INSTANCE.addDistanceListener(TAG,distanceListener); + TrajectoryAndDistanceManager.INSTANCE.addTrajectoryListener(TAG,trajectoryListener); + } private final IMogoOnMessageListener mMogoOnMessageListener = @@ -1277,11 +1282,25 @@ public class TaxiModel { /** * 设置路径规划起终点 * - * @param latLngModels */ - public void setRouteLineMarker(List latLngModels) { + public void setRouteLineMarker() { + OrderQueryRespBean.Result currentOCHOrder = getCurrentOCHOrder(); + if(currentOCHOrder!=null) { + if (currentOCHOrder.startSiteGcjPoint == null || currentOCHOrder.startSiteGcjPoint.isEmpty() || currentOCHOrder.startSiteGcjPoint.size() < 2|| + currentOCHOrder.endSiteGcjPoint == null || currentOCHOrder.endSiteGcjPoint.isEmpty() || currentOCHOrder.endSiteGcjPoint.size() < 2) { + cleanLineMarker(); + return; + } + LatLng startStation = new LatLng(currentOCHOrder.startSiteGcjPoint.get(1),currentOCHOrder.startSiteGcjPoint.get(0)); + LatLng endStation = new LatLng(currentOCHOrder.endSiteGcjPoint.get(1),currentOCHOrder.endSiteGcjPoint.get(0)); + if (mAutopilotPlanningCallback != null) { + mAutopilotPlanningCallback.setLineMarker(startStation,endStation); + } + } + } + public void cleanLineMarker(){ if (mAutopilotPlanningCallback != null) { - mAutopilotPlanningCallback.setLineMarker(latLngModels); + mAutopilotPlanningCallback.setLineMarker(null,null); } } @@ -1373,44 +1392,47 @@ public class TaxiModel { * 实时计算当前剩余里程和时间 */ public void dynamicCalculateRouteInfo() { - if (mLocation == null) { - return; +// if (mLocation == null) { +// return; +// } +// if (mRoutePoints.size() > 0 && mLocation != null) { +// Map> lastPointsMap = CoordinateCalculateRouteUtil +// .getRemainPointListByCompareNew(mPreRouteIndex, mRoutePoints, mLocation); +// +// for (int index : lastPointsMap.keySet()) { +// mPreRouteIndex = index; +// break; +// } +// for (List lastPoints : lastPointsMap.values()) { +// float lastSumLength = 0; +// if (lastPoints.size() == 1) { //只是最后一个点,计算当前位置和最后一个点的距离 +// lastSumLength = CoordinateUtils.calculateLineDistance( +// lastPoints.get(0).getLongitude(), lastPoints.get(0).getLatitude(), +// mLocation.getLongitude(), mLocation.getLatitude()); +// } else { +// lastSumLength = CoordinateCalculateRouteUtil.calculateRouteSumLength(lastPoints); +// } +// updateDistance(lastSumLength); +// break; +// } +// routeAndWipe(); +// } + } + + private void updateDistance(float lastSumLength){ + double lastTime = lastSumLength / TaxiConst.TAXI_AVERAGE_SPEED * 3.6; //秒 + CallerLogger.INSTANCE.d(M_TAXI + "dynamicCalculateRouteInfo" + , "---lastSumLength: " + lastSumLength + "----lastTime : " + lastTime + + " thread = " + Thread.currentThread().getName()); + + if (mCurrentOCHOrder != null) { + mCurrentOCHOrder.decreaseTravelDistance(lastSumLength); } - if (mRoutePoints.size() > 0 && mLocation != null) { - Map> lastPointsMap = CoordinateCalculateRouteUtil - .getRemainPointListByCompareNew(mPreRouteIndex, mRoutePoints, mLocation); - - for (int index : lastPointsMap.keySet()) { - mPreRouteIndex = index; - break; - } - for (List lastPoints : lastPointsMap.values()) { - float lastSumLength = 0; - if (lastPoints.size() == 1) { //只是最后一个点,计算当前位置和最后一个点的距离 - lastSumLength = CoordinateUtils.calculateLineDistance( - lastPoints.get(0).getLongitude(), lastPoints.get(0).getLatitude(), - mLocation.getLongitude(), mLocation.getLatitude()); - } else { - lastSumLength = CoordinateCalculateRouteUtil.calculateRouteSumLength(lastPoints); - } - - double lastTime = lastSumLength / TaxiConst.TAXI_AVERAGE_SPEED * 3.6; //秒 - CallerLogger.INSTANCE.d(M_TAXI + "dynamicCalculateRouteInfo" - , "---lastSumLength: " + lastSumLength + "----lastTime : " + lastTime - + " thread = " + Thread.currentThread().getName()); - - if (mCurrentOCHOrder != null) { - mCurrentOCHOrder.decreaseTravelDistance(lastSumLength); - } - if (mOrderStatusCallback != null) { - mOrderStatusCallback.onCurrentOrderDistToEndChanged((long) lastSumLength, (long) lastTime); - } - - reportOrderRemain((long) lastSumLength, (long) lastTime); - break; - } - routeAndWipe(); + if (mOrderStatusCallback != null) { + mOrderStatusCallback.onCurrentOrderDistToEndChanged((long) lastSumLength, (long) lastTime); } + + reportOrderRemain((long) lastSumLength, (long) lastTime); } private void routeAndWipe() { @@ -1422,13 +1444,43 @@ public class TaxiModel { mLocation.getLatitude()); List routePoints = CoordinateCalculateRouteUtil .coordinateConverterLocationToLatLng(mContext, mRoutePoints); - if (mAutopilotPlanningCallback != null) { - mAutopilotPlanningCallback.routeResult(routePoints, haveArrivedIndex); + List routeArrivied = new ArrayList<>(); + List routeArriving = new ArrayList<>(); + for (int i = 0; i < routePoints.size(); i++){ + if (i <= haveArrivedIndex){ + routeArrivied.add(routePoints.get(i)); + }else { + routeArriving.add(routePoints.get(i)); + } } - setRouteLineMarker(routePoints); + if (mAutopilotPlanningCallback != null) { + mAutopilotPlanningCallback.routeResult(routeArrivied,routeArriving, mLocation); + } + setRouteLineMarker(); } } + private final IDistanceListener distanceListener = this::updateDistance; + + private final ITrajectoryListener trajectoryListener = (routeArrivied, routeArriving, location) -> { + if (mAutopilotPlanningCallback != null) { + List routeArriviedTemp = new ArrayList<>(); + List routeArrivingTemp = new ArrayList<>(); + LatLng temp; + for (MogoLocation mogoLocation : routeArrivied) { + temp = new LatLng(mogoLocation.getLatitude(),mogoLocation.getLongitude()); + routeArriviedTemp.add(temp); + } + for (MogoLocation mogoLocation : routeArriving) { + temp = new LatLng(mogoLocation.getLatitude(),mogoLocation.getLongitude()); + routeArrivingTemp.add(temp); + } + mAutopilotPlanningCallback.routeResult(routeArriviedTemp, routeArrivingTemp,location); + setRouteLineMarker(); + } + }; + + /** * 查询当前订单的全局路径 (当自动驾驶开启后,订单前往乘客上车点,杀掉应用再次进来时候) */ diff --git a/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/presenter/NaviPresenter.java b/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/presenter/NaviPresenter.java index 1c98be1ad8..112ed99f50 100644 --- a/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/presenter/NaviPresenter.java +++ b/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/presenter/NaviPresenter.java @@ -10,6 +10,7 @@ import androidx.lifecycle.LifecycleOwner; import com.amap.api.maps.model.LatLng; import com.mogo.commons.AbsMogoApplication; import com.mogo.commons.mvp.Presenter; +import com.mogo.eagle.core.data.map.MogoLocation; import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger; import com.mogo.eagle.core.utilcode.util.UiThreadHandler; import com.mogo.och.taxi.callback.IOCHTaxiAutopilotPlanningCallback; @@ -65,12 +66,12 @@ public class NaviPresenter extends Presenter implements } @Override - public void setLineMarker(List models) { - runOnUIThread(() -> mView.setLineMarker(models)); + public void setLineMarker(LatLng startStation, LatLng endStation) { + runOnUIThread(() -> mView.setLineMarker(startStation,endStation)); } @Override - public void routeResult(List models, int haveArrivedIndex) { - mView.routeResult(models,haveArrivedIndex); + public void routeResult(List routeArrivied, List routeArriving, MogoLocation location) { + mView.routeResult(routeArrivied,routeArriving,location); } } diff --git a/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/presenter/TaxiPresenter.java b/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/presenter/TaxiPresenter.java index 3b08eb1527..d53d3e16f3 100644 --- a/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/presenter/TaxiPresenter.java +++ b/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/presenter/TaxiPresenter.java @@ -257,7 +257,7 @@ public class TaxiPresenter extends Presenter implements ITaxiADASS TaxiOrderStatusEnum.Cancel.getCode() == order.orderStatus || TaxiOrderStatusEnum.JourneyCompleted.getCode() == order.orderStatus){ TaxiModel.getInstance().startOrStopCalculateRouteInfo(false); - TaxiModel.getInstance().setRouteLineMarker(null); + TaxiModel.getInstance().cleanLineMarker(); TaxiModel.getInstance().cleanStation(); runOnUIThread(() -> { if(TaxiOrderStatusEnum.ArriveAtEnd.getCode() == order.orderStatus){ diff --git a/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/ui/TaxiMapDirectionView.java b/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/ui/TaxiMapDirectionView.java index caa65dee96..69b7e40b4e 100644 --- a/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/ui/TaxiMapDirectionView.java +++ b/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/ui/TaxiMapDirectionView.java @@ -15,7 +15,6 @@ import androidx.annotation.Nullable; import com.amap.api.maps.AMap; import com.amap.api.maps.CameraUpdate; import com.amap.api.maps.CameraUpdateFactory; -import com.amap.api.maps.CoordinateConverter; import com.amap.api.maps.TextureMapView; import com.amap.api.maps.UiSettings; import com.amap.api.maps.model.BitmapDescriptor; @@ -28,7 +27,6 @@ import com.amap.api.maps.model.Marker; import com.amap.api.maps.model.MarkerOptions; import com.amap.api.maps.model.Polyline; import com.amap.api.maps.model.PolylineOptions; -import com.mogo.eagle.core.data.map.MogoLatLng; import com.mogo.eagle.core.data.map.MogoLocation; import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationGCJ02Listener; import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02ListenerManager; @@ -55,12 +53,14 @@ public class TaxiMapDirectionView private Marker mStartMarker; private Marker mEndMarker; - private int zoomLevel = 13; - private List mCoordinatesLatLng = new ArrayList<>(); + private final int zoomLevel = 13; + private final List routeArrivied = new ArrayList<>(); + private final List routeArriving = new ArrayList<>(); + private MogoLocation location; + + private LatLng startStation; + private LatLng endStation; private Polyline mPolyline; - private CameraUpdate mCameraUpdate; - private Context mContext; - private int mHaveArrivedIndex; List textureList = new ArrayList<>(); List texIndexList = new ArrayList<>(); @@ -89,16 +89,14 @@ public class TaxiMapDirectionView private void initView(Context context) { CallerLogger.INSTANCE.d(M_TAXI + TAG, "initView"); - mContext = context; - View smpView = LayoutInflater.from(context).inflate(R.layout.taxi_map_view, this); - mAMapNaviView = (TextureMapView) smpView.findViewById(R.id.taxi_amap_view); + mAMapNaviView = smpView.findViewById(R.id.taxi_amap_view); initAMapView(); // 注册定位监听 - CallerChassisLocationGCJ02ListenerManager.INSTANCE.addListener(TAG, 10,this); + CallerChassisLocationGCJ02ListenerManager.INSTANCE.addListener(TAG, 10, this); } @Override @@ -109,7 +107,7 @@ public class TaxiMapDirectionView } private void initAMapView() { - mCameraUpdate = CameraUpdateFactory.zoomTo(zoomLevel); + CameraUpdate mCameraUpdate = CameraUpdateFactory.zoomTo(zoomLevel); mAMap = mAMapNaviView.getMap(); // 设置导航地图模式,aMap是地图控制器对象。 mAMap.setMapType(AMap.MAP_TYPE_NIGHT); @@ -134,8 +132,8 @@ public class TaxiMapDirectionView // 加载自定义样式 CustomMapStyleOptions customMapStyleOptions = new CustomMapStyleOptions() .setEnable(true) - .setStyleData(TaxiMapAssetStyleUtil.getAssetsStyle(getContext(),"map_style.data")) - .setStyleExtraData(TaxiMapAssetStyleUtil.getAssetsExtraStyle(getContext(),"map_style_extra.data")); + .setStyleData(TaxiMapAssetStyleUtil.getAssetsStyle(getContext(), "map_style.data")) + .setStyleExtraData(TaxiMapAssetStyleUtil.getAssetsExtraStyle(getContext(), "map_style_extra.data")); // 设置自定义样式 mAMap.setCustomMapStyle(customMapStyleOptions); @@ -156,8 +154,8 @@ public class TaxiMapDirectionView // 加载自定义样式 CustomMapStyleOptions customMapStyleOptions = new CustomMapStyleOptions() .setEnable(true) - .setStyleData(TaxiMapAssetStyleUtil.getAssetsStyle(getContext(),"map_style.data")) - .setStyleExtraData(TaxiMapAssetStyleUtil.getAssetsExtraStyle(getContext(),"map_style_extra.data")); + .setStyleData(TaxiMapAssetStyleUtil.getAssetsStyle(getContext(), "map_style.data")) + .setStyleExtraData(TaxiMapAssetStyleUtil.getAssetsExtraStyle(getContext(), "map_style_extra.data")); // 设置自定义样式 mAMap.setCustomMapStyle(customMapStyleOptions); mAMapNaviView.getMap().setPointToCenter(mAMapNaviView.getWidth() / 2, mAMapNaviView.getHeight() / 2); @@ -176,21 +174,21 @@ public class TaxiMapDirectionView @Override public void onChassisLocationGCJ02(@Nullable MogoLocation gnssInfo) { - if (gnssInfo == null){ + if (gnssInfo == null) { return; } try { LatLng currentLatLng = new LatLng(gnssInfo.getLatitude(), gnssInfo.getLongitude()); - if (mCoordinatesLatLng.size() > 1) { + if (mPolyline!=null&&mPolyline.getPoints().size() > 1) { + List points = mPolyline.getPoints(); //圈定地图显示范围 - LatLng endLatLng = mCoordinatesLatLng.get(mCoordinatesLatLng.size() - 1); + LatLng endLatLng = points.get(points.size() - 1); //存放经纬度 LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder(); boundsBuilder.include(currentLatLng); boundsBuilder.include(endLatLng); //第二个参数为四周留空宽度 - mAMap.moveCamera(CameraUpdateFactory.newLatLngBoundsRect(boundsBuilder.build(), 100,100,100,100)); -// CallerLogger.INSTANCE.d(M_TAXI_P + TAG, "onCarLocationChanged2--moveCamera :" + location.getLatitude()+", "+location.getLongitude()); + mAMap.moveCamera(CameraUpdateFactory.newLatLngBoundsRect(boundsBuilder.build(), 100, 100, 100, 100)); } else { //设置希望展示的地图缩放级别 @@ -200,40 +198,30 @@ public class TaxiMapDirectionView } //更新车辆位置 if (mCarMarker != null) { -// CallerLogger.INSTANCE.d(M_TAXI_P + TAG, "location.getBearing() = " + location.getBearing()); mCarMarker.setRotateAngle((float) (360 - gnssInfo.getHeading())); mCarMarker.setPosition(currentLatLng); -// CallerLogger.INSTANCE.d(M_TAXI_P + TAG, "onCarLocationChanged2--loacation :" + location.getLatitude()+", "+location.getLongitude()); mCarMarker.setToTop(); } - }catch (Exception e){ - + } catch (Exception e) { + e.printStackTrace(); } } @Override public void setLineMarker() { -// if (mStartMarker != null) { -// mStartMarker.setVisible(false); -// } -// if (mEndMarker != null) { -// mEndMarker.setVisible(false); -// } if (mStartMarker != null && mEndMarker != null && mStartMarker.isVisible() && mEndMarker.isVisible()) { return; } - if (mCoordinatesLatLng.size() > 2) { + if (startStation != null && endStation != null) { // 设置开始结束Marker位置 - LatLng startLatLng = mCoordinatesLatLng.get(0); - LatLng endLatLng = mCoordinatesLatLng.get(mCoordinatesLatLng.size() - 1); if (mStartMarker != null) { - mStartMarker.setPosition(startLatLng); + mStartMarker.setPosition(startStation); mStartMarker.setVisible(true); } if (mEndMarker != null) { - mEndMarker.setPosition(endLatLng); + mEndMarker.setPosition(endStation); mEndMarker.setVisible(true); } } @@ -241,62 +229,43 @@ public class TaxiMapDirectionView @Override public void drawablePolyline() { - if (mPolyline != null) { - mPolyline.remove(); + if(routeArrivied.isEmpty()&&routeArriving.isEmpty()){ + CallerLogger.INSTANCE.d(M_TAXI + TAG, "没有点"); + return; } - if (mAMap != null) { - - addRouteColorList(); - - if (mCoordinatesLatLng.size() > 2) { - //设置线段纹理 - PolylineOptions polylineOptions = new PolylineOptions(); - polylineOptions.addAll(mCoordinatesLatLng); - polylineOptions.setUseTexture(true); - polylineOptions.width(15); - polylineOptions.lineCapType(PolylineOptions.LineCapType.LineCapRound); - polylineOptions.setCustomTextureList(textureList); - polylineOptions.setCustomTextureIndex(texIndexList); - - // 绘制线 - mPolyline = mAMap.addPolyline(polylineOptions); - - } - } - } - - /** - * 添加画线颜色值 - */ - private void addRouteColorList() { - textureList.clear(); texIndexList.clear(); - for (int i = 0; i < mCoordinatesLatLng.size(); i++){ - if (i <= mHaveArrivedIndex){ - textureList.add(mArrivedRes); - }else { - textureList.add(mUnArrivedRes); + ArrayList allPoints = new ArrayList<>(routeArrivied); + for (int i = 0; i < routeArrivied.size(); i++) { + if(routeArrivied.size()>1&&i CoordinateConverterFrom84ForList(Context mContext, List mogoLatLngList) { - List list = new ArrayList<>(); - for (MogoLatLng m : mogoLatLngList) { - LatLng mogoLatLng = CoordinateConverterFrom84(mContext, m); - list.add(mogoLatLng); + texIndexList.add(0); + allPoints.add(new LatLng(location.getLatitude(),location.getLongitude())); + allPoints.addAll(routeArriving); + for (LatLng ignored : routeArrivied) { + texIndexList.add(1); + } + + if (mPolyline != null) { + mPolyline.setPoints(allPoints); + mPolyline.getOptions().setCustomTextureIndex(texIndexList); + return; + } + textureList.add(mArrivedRes); + textureList.add(mUnArrivedRes); + if (mAMap != null) { + //设置线段纹理 + PolylineOptions polylineOptions = new PolylineOptions(); + polylineOptions.addAll(allPoints); + polylineOptions.setUseTexture(true); + polylineOptions.width(15); + polylineOptions.lineCapType(PolylineOptions.LineCapType.LineCapRound); + polylineOptions.setCustomTextureList(textureList); + polylineOptions.setCustomTextureIndex(texIndexList); + // 绘制线 + mPolyline = mAMap.addPolyline(polylineOptions); } - return list; } @Override @@ -312,19 +281,6 @@ public class TaxiMapDirectionView } } - public void resetPolyLine() { - mCoordinatesLatLng.clear(); - if (mPolyline != null) { - mPolyline.remove(); - } - if (mStartMarker != null) { - mStartMarker.setVisible(false); - } - if (mEndMarker != null) { - mEndMarker.setVisible(false); - } - } - public void onCreateView(Bundle savedInstanceState) { if (mAMapNaviView != null) { mAMapNaviView.onCreate(savedInstanceState); @@ -349,21 +305,17 @@ public class TaxiMapDirectionView } } - public void convert(List coordinates) { - mCoordinatesLatLng.clear(); - List latLngs = CoordinateConverterFrom84ForList(mContext, coordinates); - mCoordinatesLatLng.addAll(latLngs); + public void setStartMarkAndEndMark(LatLng startStation, LatLng endStation) { + this.startStation = startStation; + this.endStation = endStation; } - public void setCoordinatesLatLng(List latLngs){ - mCoordinatesLatLng.clear(); - mCoordinatesLatLng.addAll(latLngs); - } - - public void setCoordinatesLatLng(List latLngs, int haveArrivedIndex){ - mCoordinatesLatLng.clear(); - mCoordinatesLatLng.addAll(latLngs); - mHaveArrivedIndex = haveArrivedIndex; + public void setCoordinatesLatLng(List routeArrivied, List routeArriving, MogoLocation location) { + this.routeArrivied.clear(); + this.routeArrivied.addAll(routeArrivied); + this.routeArriving.clear(); + this.routeArriving.addAll(routeArriving); + this.location = location; } @Override diff --git a/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/ui/TaxiRottingNaviFragment.java b/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/ui/TaxiRottingNaviFragment.java index d237e395cd..003c211eaa 100644 --- a/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/ui/TaxiRottingNaviFragment.java +++ b/OCH/mogo-och-taxi/src/main/java/com/mogo/och/taxi/ui/TaxiRottingNaviFragment.java @@ -6,6 +6,7 @@ import androidx.annotation.NonNull; import com.amap.api.maps.model.LatLng; import com.mogo.commons.mvp.MvpFragment; +import com.mogo.eagle.core.data.map.MogoLocation; import com.mogo.eagle.core.utilcode.util.UiThreadHandler; import com.mogo.och.taxi.R; import com.mogo.och.taxi.presenter.NaviPresenter; @@ -79,49 +80,34 @@ public class TaxiRottingNaviFragment extends MvpFragment latLngList, int haveArrivedIndex){ - if (latLngList.size() > 0) { - drawablePolylineByRoute(latLngList,haveArrivedIndex); + public void routeResult(List routeArrivied, List routeArriving, MogoLocation location){ + if ((routeArrivied.size()+routeArriving.size()) > 0) { + drawablePolylineByRoute(routeArrivied,routeArriving,location); } else { clearPolyline(); } } - public void setLineMarker(List latLngList){ - if (null != latLngList && latLngList.size() > 0) { + public void setLineMarker(LatLng startStation, LatLng endStation){ + if (startStation!=null&&endStation!=null) { if (mMapDirectionView != null) { - mMapDirectionView.setCoordinatesLatLng(latLngList); - UiThreadHandler.post(new Runnable() { - @Override - public void run() { - mMapDirectionView.setLineMarker(); - } - }); + mMapDirectionView.setStartMarkAndEndMark(startStation,endStation); + UiThreadHandler.post(() -> mMapDirectionView.setLineMarker()); } } else { clearPolyline(); } } - public void drawablePolylineByRoute(List mCoordinatesLatLng,int haveArrivedIndex){ + public void drawablePolylineByRoute(List routeArrivied, List routeArriving, MogoLocation location){ if (mMapDirectionView != null){ - mMapDirectionView.setCoordinatesLatLng(mCoordinatesLatLng,haveArrivedIndex); - UiThreadHandler.post(new Runnable() { - @Override - public void run() { - mMapDirectionView.drawablePolyline(); - } - }); + mMapDirectionView.setCoordinatesLatLng(routeArrivied,routeArriving,location); + UiThreadHandler.post(() -> mMapDirectionView.drawablePolyline()); } } private void clearPolyline() { if (mMapDirectionView != null) { - UiThreadHandler.post(new Runnable() { - @Override - public void run() { - mMapDirectionView.clearPolyline(); - } - }); + UiThreadHandler.post(() -> mMapDirectionView.clearPolyline()); } } }