From 77ff6fdb2fc9766d1d1f613a88891a3ba7b5d0f1 Mon Sep 17 00:00:00 2001 From: yangyakun Date: Mon, 26 Jun 2023 18:31:19 +0800 Subject: [PATCH] =?UTF-8?q?[feature]=20[bus=20=E8=BD=A8=E8=BF=B9=E8=AE=A1?= =?UTF-8?q?=E7=AE=97]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...BusPassengerAutopilotPlanningCallback.java | 3 +- .../passenger/model/BusPassengerModel.java | 196 ++++++---- .../presenter/BaseBusPassengerPresenter.java | 6 +- .../ui/BusPassengerMapDirectionView.java | 358 ------------------ .../ui/BusPassengerMapDirectionView.kt | 328 ++++++++++++++++ .../ui/BusPassengerRouteFragment.java | 17 +- .../passenger/utils/BPRouteDataTestUtils.java | 2 +- .../com/mogo/och/bus/model/OrderModel.java | 38 +- .../TrajectoryAndDistanceManager.kt | 33 +- .../passenger/model/TaxiPassengerModel.java | 4 +- .../com/mogo/och/taxi/model/TaxiModel.java | 4 +- 11 files changed, 525 insertions(+), 464 deletions(-) delete mode 100644 OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/ui/BusPassengerMapDirectionView.java create mode 100644 OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/ui/BusPassengerMapDirectionView.kt diff --git a/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/callback/IBusPassengerAutopilotPlanningCallback.java b/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/callback/IBusPassengerAutopilotPlanningCallback.java index 28e451dced..7f07057f98 100644 --- a/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/callback/IBusPassengerAutopilotPlanningCallback.java +++ b/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/callback/IBusPassengerAutopilotPlanningCallback.java @@ -1,6 +1,7 @@ package com.mogo.och.bus.passenger.callback; import com.amap.api.maps.model.LatLng; +import com.mogo.eagle.core.data.map.MogoLocation; import java.util.List; @@ -8,7 +9,7 @@ import java.util.List; * Created on 2022/3/31 */ public interface IBusPassengerAutopilotPlanningCallback { - void routeResult(List models,int haveArrivedIndex); + void routeResult(List routeArrivied, List routeArriving, MogoLocation location); void routePlanningToNextStationChanged(long meters, long timeInSecond); void updateTotalDistance(); } diff --git a/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/model/BusPassengerModel.java b/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/model/BusPassengerModel.java index 7541b3ff1b..d14a090063 100644 --- a/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/model/BusPassengerModel.java +++ b/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/model/BusPassengerModel.java @@ -39,7 +39,6 @@ import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger; import com.mogo.eagle.core.utilcode.mogo.logger.Logger; import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant; import com.mogo.eagle.core.utilcode.mogo.storage.SharedPrefsMgr; -import com.mogo.eagle.core.utilcode.util.CoordinateUtils; import com.mogo.eagle.core.utilcode.util.GsonUtils; import com.mogo.eagle.core.utilcode.util.NetworkUtils; import com.mogo.eagle.core.utilcode.util.ToastUtils; @@ -63,6 +62,9 @@ import com.mogo.och.common.module.biz.common.socketmessage.OCHSocketMessageManag import com.mogo.och.common.module.biz.constant.OchCommonConst; import com.mogo.och.common.module.biz.network.OchCommonServiceCallback; import com.mogo.och.common.module.manager.AbnormalFactorsLoopManager; +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.utils.CoordinateCalculateRouteUtil; import com.mogo.och.common.module.utils.DateTimeUtil; import com.mogo.och.common.module.utils.PinYinUtil; @@ -244,13 +246,17 @@ public class BusPassengerModel { } mNextStationIndex = i + 1; + BusPassengerStation startStation = mStations.get(i); + BusPassengerStation endStation = mStations.get(mNextStationIndex); + + setTrajectoryStation(startStation,endStation,result.getLineId()); + updateAutopilotControlParameters(result, i); return; } else if (station.getDrivingStatus() == STATION_STATUS_STOPPED && !station.isLeaving()) { //到站 - if (i == 0) { - startOrStopRouteAndWipe(false); + if(i==stations.size()-1){ + cleanStation(); } - mPreRouteIndex = 0; startOrStopCalculateRouteInfo(false); mRouteLineInfoCallback.updateStationsInfo(stations, i, true); clearAutopilotControlParameters(); @@ -359,6 +365,10 @@ public class BusPassengerModel { CallerTelematicListenerManager.INSTANCE.addListener(TAG, mReceivedMsgListener); AbnormalFactorsLoopManager.INSTANCE.startLoopAbnormalFactors(mContext); + + TrajectoryAndDistanceManager.INSTANCE.addDistanceListener(TAG,distanceListener); + + TrajectoryAndDistanceManager.INSTANCE.addTrajectoryListener(TAG,trajectoryListener); } private void releaseListeners() { @@ -377,6 +387,29 @@ public class BusPassengerModel { AbnormalFactorsLoopManager.INSTANCE.stopLoopAbnormalFactors(); } + private final IDistanceListener distanceListener = distance -> { + double lastTime = distance / getAverageSpeed() * 3.6; //秒 + CallerLogger.INSTANCE.d(M_BUS_P + TAG, "轨迹排查==lastSumLength = " + distance); + if (mAutopilotPlanningCallback != null) { + mAutopilotPlanningCallback.routePlanningToNextStationChanged((long) distance, (long) lastTime); + } + }; + 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); + } + }; private final IReceivedMsgListener mReceivedMsgListener = new IReceivedMsgListener() { @Override public void onReceivedServerSn(@Nullable String sn) { @@ -509,7 +542,7 @@ public class BusPassengerModel { List routePoints = routeList.getWayPointsList(); if (null != routePoints && routePoints.size() > 0) { updateRoutePoints(routePoints); - startToRouteAndWipe(); + //startToRouteAndWipe(); } }; @@ -560,48 +593,48 @@ public class BusPassengerModel { } public void dynamicCalculateRouteInfo() { - //计算当前位置和下一站的剩余点集合 - //计算剩余点总里程和时间 - if (mTwoStationsRouts.size() == 0) { - calculateTwoStationsRoute(); - } - if (mTwoStationsRouts.size() > 0 && mLocation != null) { - Map> lastPointsMap = CoordinateCalculateRouteUtil - .getRemainPointListByCompareNew(mPreRouteIndex, mTwoStationsRouts, mLocation); - if(lastPointsMap==null){ - return; - } - for (int index : lastPointsMap.keySet()) { - mPreRouteIndex = index; - break; - } - - for (List lastPoints : lastPointsMap.values()) { - CallerLogger.INSTANCE.d(M_BUS_P + TAG, "轨迹排查==lastPoints.size() = " + lastPoints.size()); - float lastSumLength = 0; - if (lastPoints.size() == 1) { //只是最后一个点,计算当前位置和最后一个点的距离 - if (mNextStationIndex <= mStations.size() - 1 && mNextStationIndex >= 0) { - BusPassengerStation stationNext = mStations.get(mNextStationIndex); - lastSumLength = CoordinateUtils.calculateLineDistance( - stationNext.getGcjLon(), stationNext.getGcjLat(), - mLocation.getLongitude(), mLocation.getLatitude()); - } else { - lastSumLength = CoordinateUtils.calculateLineDistance( - lastPoints.get(0).getLongitude(), lastPoints.get(0).getLatitude(), - mLocation.getLongitude(), mLocation.getLatitude()); - } - - } else { - lastSumLength = CoordinateCalculateRouteUtil.calculateRouteSumLength(lastPoints); - } - - double lastTime = lastSumLength / getAverageSpeed() * 3.6; //秒 - CallerLogger.INSTANCE.d(M_BUS_P + TAG, "轨迹排查==lastSumLength = " + lastSumLength); - if (mAutopilotPlanningCallback != null) { - mAutopilotPlanningCallback.routePlanningToNextStationChanged((long) lastSumLength, (long) lastTime); - } - } - } +// //计算当前位置和下一站的剩余点集合 +// //计算剩余点总里程和时间 +// if (mTwoStationsRouts.size() == 0) { +// calculateTwoStationsRoute(); +// } +// if (mTwoStationsRouts.size() > 0 && mLocation != null) { +// Map> lastPointsMap = CoordinateCalculateRouteUtil +// .getRemainPointListByCompareNew(mPreRouteIndex, mTwoStationsRouts, mLocation); +// if(lastPointsMap==null){ +// return; +// } +// for (int index : lastPointsMap.keySet()) { +// mPreRouteIndex = index; +// break; +// } +// +// for (List lastPoints : lastPointsMap.values()) { +// CallerLogger.INSTANCE.d(M_BUS_P + TAG, "轨迹排查==lastPoints.size() = " + lastPoints.size()); +// float lastSumLength = 0; +// if (lastPoints.size() == 1) { //只是最后一个点,计算当前位置和最后一个点的距离 +// if (mNextStationIndex <= mStations.size() - 1 && mNextStationIndex >= 0) { +// BusPassengerStation stationNext = mStations.get(mNextStationIndex); +// lastSumLength = CoordinateUtils.calculateLineDistance( +// stationNext.getGcjLon(), stationNext.getGcjLat(), +// mLocation.getLongitude(), mLocation.getLatitude()); +// } else { +// lastSumLength = CoordinateUtils.calculateLineDistance( +// lastPoints.get(0).getLongitude(), lastPoints.get(0).getLatitude(), +// mLocation.getLongitude(), mLocation.getLatitude()); +// } +// +// } else { +// lastSumLength = CoordinateCalculateRouteUtil.calculateRouteSumLength(lastPoints); +// } +// +// double lastTime = lastSumLength / getAverageSpeed() * 3.6; //秒 +// CallerLogger.INSTANCE.d(M_BUS_P + TAG, "轨迹排查==lastSumLength = " + lastSumLength); +// if (mAutopilotPlanningCallback != null) { +// mAutopilotPlanningCallback.routePlanningToNextStationChanged((long) lastSumLength, (long) lastTime); +// } +// } +// } } public int getAverageSpeed() { @@ -613,40 +646,40 @@ public class BusPassengerModel { startOrStopCalculateRouteInfo(true); } - public void startToRouteAndWipe() { - startOrStopRouteAndWipe(true); - } +// public void startToRouteAndWipe() { +// startOrStopRouteAndWipe(true); +// } /** * 实时轨迹擦除 * - * @param isStart +// * @param isStart */ - public void startOrStopRouteAndWipe(boolean isStart) { - if (isStart) { - BusPassengerModelLoopManager.getInstance().startOrStopRouteAndWipe(); - } else { - mWipePreIndex = 0; - BusPassengerModelLoopManager.getInstance().stopOrStopRouteAndWipe(); - } - } +// public void startOrStopRouteAndWipe(boolean isStart) { +// if (isStart) { +// BusPassengerModelLoopManager.getInstance().startOrStopRouteAndWipe(); +// } else { +// mWipePreIndex = 0; +// BusPassengerModelLoopManager.getInstance().stopOrStopRouteAndWipe(); +// } +// } public void loopRouteAndWipe() { - if (mRoutePoints != null && mRoutePoints.size() > 0 && mLocation != null) { - int haveArrivedIndex = CoordinateCalculateRouteUtil - .getArrivedPointIndexNew(mWipePreIndex, - mRoutePoints, - mLocation); - - mWipePreIndex = haveArrivedIndex; - - CallerLogger.INSTANCE.d(M_BUS_P + TAG, "thread = " + Thread.currentThread().getName() + " haveArrivedIndex== " + haveArrivedIndex); - if (mAutopilotPlanningCallback != null) { - List routePoints = CoordinateCalculateRouteUtil - .coordinateConverterLocationToLatLng(mContext, mRoutePoints); - mAutopilotPlanningCallback.routeResult(routePoints, haveArrivedIndex); - } - } +// if (mRoutePoints != null && mRoutePoints.size() > 0 && mLocation != null) { +// int haveArrivedIndex = CoordinateCalculateRouteUtil +// .getArrivedPointIndexNew(mWipePreIndex, +// mRoutePoints, +// mLocation); +// +// mWipePreIndex = haveArrivedIndex; +// +// CallerLogger.INSTANCE.d(M_BUS_P + TAG, "thread = " + Thread.currentThread().getName() + " haveArrivedIndex== " + haveArrivedIndex); +// if (mAutopilotPlanningCallback != null) { +// List routePoints = CoordinateCalculateRouteUtil +// .coordinateConverterLocationToLatLng(mContext, mRoutePoints); +// mAutopilotPlanningCallback.routeResult(routePoints, haveArrivedIndex); +// } +// } } /** @@ -673,4 +706,19 @@ public class BusPassengerModel { } } + + public void setTrajectoryStation(BusPassengerStation startStationInfo, BusPassengerStation endStationInfo, int lineId){ + MogoLocation startStation = new MogoLocation(); + startStation.setLongitude(startStationInfo.getGcjLon()); + startStation.setLatitude(startStationInfo.getGcjLat()); + MogoLocation endStation = new MogoLocation(); + endStation.setLongitude(endStationInfo.getGcjLon()); + endStation.setLatitude(endStationInfo.getGcjLat()); + TrajectoryAndDistanceManager.INSTANCE.setStationPoint(startStation,endStation, (long) lineId); + } + + public void cleanStation(){ + TrajectoryAndDistanceManager.INSTANCE.setStationPoint(null,null,-1L); + } + } diff --git a/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/presenter/BaseBusPassengerPresenter.java b/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/presenter/BaseBusPassengerPresenter.java index 20bfc21db5..c41a9daa46 100644 --- a/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/presenter/BaseBusPassengerPresenter.java +++ b/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/presenter/BaseBusPassengerPresenter.java @@ -152,10 +152,8 @@ public class BaseBusPassengerPresenter extends Presenter models, int haveArrivedIndex) { - CallerLogger.INSTANCE.d(M_BUS_P + TAG, "routeResult:" + models.size() - + " haveArrivedIndex = "+haveArrivedIndex); - runOnUIThread(() ->mView.routeResult(models,haveArrivedIndex)); + public void routeResult(List routeArrivied,List routeArriving,MogoLocation location) { + runOnUIThread(() ->mView.routeResult(routeArrivied,routeArriving,location)); } @Override diff --git a/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/ui/BusPassengerMapDirectionView.java b/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/ui/BusPassengerMapDirectionView.java deleted file mode 100644 index 570fddb51a..0000000000 --- a/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/ui/BusPassengerMapDirectionView.java +++ /dev/null @@ -1,358 +0,0 @@ -package com.mogo.och.bus.passenger.ui; - -import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_BUS_P; - -import android.content.Context; -import android.os.Bundle; -import android.util.AttributeSet; -import android.view.LayoutInflater; -import android.view.MotionEvent; -import android.view.View; -import android.widget.RelativeLayout; - -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.TextureMapView; -import com.amap.api.maps.UiSettings; -import com.amap.api.maps.model.BitmapDescriptor; -import com.amap.api.maps.model.BitmapDescriptorFactory; -import com.amap.api.maps.model.CameraPosition; -import com.amap.api.maps.model.CustomMapStyleOptions; -import com.amap.api.maps.model.LatLng; -import com.amap.api.maps.model.LatLngBounds; -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.MogoLocation; -import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationGCJ02Listener; -import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationGCJ02ListenerManager; -import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger; -import com.mogo.och.bus.passenger.R; -import com.mogo.och.bus.passenger.utils.BusPassengerMapAssetStyleUtil; - -import java.util.ArrayList; -import java.util.List; - -/** - * 乘客屏小地图 - */ -public class BusPassengerMapDirectionView - extends RelativeLayout - implements IMoGoChassisLocationGCJ02Listener, - IBusPassengerMapDirectionView, - AMap.OnCameraChangeListener { - - //小地图名称 - public static final String TAG = "TPMapDirectionView"; - - private TextureMapView mAMapNaviView; - private AMap mAMap; - private Marker mCarMarker; - - private List mCoordinatesLatLng = new ArrayList<>(); //轨迹坐标数据 - private List mLineStationLatLng = new ArrayList<>();//站点坐标数据 - private Polyline mPolyline; - - List textureList = new ArrayList<>(); - List texIndexList = new ArrayList<>(); - private int mHaveArrivedIndex = 0; - - private List mLineMarkers = new ArrayList<>(); - - private BitmapDescriptor mArrivedRes; - private BitmapDescriptor mUnArrivedRes; - - public BusPassengerMapDirectionView(Context context) { - this(context, null); - } - - public BusPassengerMapDirectionView(Context context, @Nullable AttributeSet attrs) { - this(context, attrs, 0); - } - - public BusPassengerMapDirectionView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - try { - initView(context); - } catch (Exception e) { - e.printStackTrace(); - } - } - - private void initView(Context context) { - CallerLogger.INSTANCE.d(M_BUS_P + TAG, "initView"); - - - View smpView = LayoutInflater.from(context).inflate(R.layout.bus_p_map_view, this); - - mAMapNaviView = (TextureMapView) smpView.findViewById(R.id.bus_p_line_amap_view); - - initAMapView(); - - // 注册定位监听 - CallerChassisLocationGCJ02ListenerManager.INSTANCE.addListener(TAG, 10,this); - } - - @Override - protected void onDetachedFromWindow() { - super.onDetachedFromWindow(); - // 注册定位监听 - CallerChassisLocationGCJ02ListenerManager.INSTANCE.removeListener(TAG); - } - - private void initAMapView() { -// mCameraUpdate = CameraUpdateFactory.zoomTo(zoomLevel); - mAMap = mAMapNaviView.getMap(); - // 设置导航地图模式,aMap是地图控制器对象。 - mAMap.setMapType(AMap.MAP_TYPE_NIGHT); - - // 关闭显示实时路况图层,aMap是地图控制器对象。 - mAMap.setTrafficEnabled(false); - - // 设置 锚点 图标 - mCarMarker = mAMap.addMarker(new MarkerOptions() - .icon(BitmapDescriptorFactory.fromResource(R.drawable.bus_p_map_car)) - .anchor(0.5f, 0.5f)); - - mArrivedRes = BitmapDescriptorFactory.fromResource(R.drawable.bus_p_map_arrow_arrived); - mUnArrivedRes = BitmapDescriptorFactory.fromResource(R.drawable.bus_p_map_arrow_un_arrive); - - // 加载自定义样式 - CustomMapStyleOptions customMapStyleOptions = new CustomMapStyleOptions() - .setEnable(true) - .setStyleData(BusPassengerMapAssetStyleUtil.getAssetsStyle(getContext(), "map_style.data")) - .setStyleExtraData(BusPassengerMapAssetStyleUtil.getAssetsExtraStyle(getContext(), "map_style_extra.data")); - // 设置自定义样式 - mAMap.setCustomMapStyle(customMapStyleOptions); - - //设置希望展示的地图缩放级别 -// mAMap.moveCamera(mCameraUpdate); - - // 设置地图的样式 - UiSettings uiSettings = mAMap.getUiSettings(); - uiSettings.setZoomControlsEnabled(false);// 地图缩放级别的交换按钮 - uiSettings.setAllGesturesEnabled(false);// 所有手势 - uiSettings.setMyLocationButtonEnabled(false); // 显示默认的定位按钮 - uiSettings.setLogoBottomMargin(-150); //设置Logo下边界距离屏幕底部的边距,设置为负值即可 - - mAMap.setOnMapLoadedListener(new AMap.OnMapLoadedListener() { - @Override - public void onMapLoaded() { - CallerLogger.INSTANCE.d(M_BUS_P + TAG, "smp---onMapLoaded"); - // 加载自定义样式 - CustomMapStyleOptions customMapStyleOptions = new CustomMapStyleOptions() - .setEnable(true) - .setStyleData(BusPassengerMapAssetStyleUtil.getAssetsStyle(getContext(), "map_style.data")) - .setStyleExtraData(BusPassengerMapAssetStyleUtil.getAssetsExtraStyle(getContext(), "map_style_extra.data")); - // 设置自定义样式 - mAMap.setCustomMapStyle(customMapStyleOptions); - mAMapNaviView.getMap().setPointToCenter(mAMapNaviView.getWidth() / 2, mAMapNaviView.getHeight() / 2); - } - }); - - //设置地图状态的监听接口 - mAMap.setOnCameraChangeListener(this); - } - - - @Override - public boolean onInterceptTouchEvent(MotionEvent ev) { - return true; - } - - @Override - public void onChassisLocationGCJ02(@Nullable MogoLocation gnssInfo) { - if (gnssInfo == null) { - return; - } -// CallerLogger.INSTANCE.d(M_BUS_P + TAG, "onCarLocationChanged2 :" + location.getLatitude() + ":" + location.getLongitude()); - LatLng currentLatLng = new LatLng(gnssInfo.getLatitude(), gnssInfo.getLongitude()); - - //更新车辆位置 - if (mCarMarker != null) { -// CallerLogger.INSTANCE.d(M_BUS_P + TAG, "location.getBearing() = " + location.getBearing()); - mCarMarker.setRotateAngle((float) (360 - gnssInfo.getHeading())); - mCarMarker.setPosition(currentLatLng); - mCarMarker.setToTop(); - } - - try { - - //圈定地图显示范围 - LatLngBounds.Builder boundsBuilder = new LatLngBounds.Builder(); - - if (mCoordinatesLatLng.size() > 0){ - //存放经纬度 - for (int i = 0; i < mCoordinatesLatLng.size(); i++) { - boundsBuilder.include(mCoordinatesLatLng.get(i)); - } - //第二个参数为四周留空宽度 - }else if (mLineStationLatLng.size() > 0){ - for (int i = 0; i< mLineStationLatLng.size();i++){ - boundsBuilder.include(mLineStationLatLng.get(i)); - } - } - - boundsBuilder.include(currentLatLng); - mAMap.moveCamera(CameraUpdateFactory.newLatLngBoundsRect(boundsBuilder.build(),100,100,100,100)); - - }catch (Exception e){ - - } - } - - - @Override - public void drawablePolyline() { - if (mPolyline != null) { - mPolyline.remove(); - } - if (mAMap != null) { - - addRouteColorList(); - CallerLogger.INSTANCE.d(M_BUS_P + TAG, "mLinePointsLatLng.size() = " +mLineStationLatLng.size() - +" mCoordinatesLatLng.size()= " + mCoordinatesLatLng.size()); - if (mLineStationLatLng.size() >= 2 && mCoordinatesLatLng.size() > 2) { - //设置线段纹理 - PolylineOptions polylineOptions = new PolylineOptions(); - polylineOptions.addAll(mCoordinatesLatLng); - polylineOptions.width(14); //线段宽度 - polylineOptions.setUseTexture(true); - polylineOptions.lineCapType(PolylineOptions.LineCapType.LineCapRound); - polylineOptions.setCustomTextureList(textureList); - polylineOptions.setCustomTextureIndex(texIndexList); -// polylineOptions.colorValues(colorList); -// polylineOptions.setCustomTexture(BitmapDescriptorFactory.fromResource(R.drawable.taxi_p_map_arrow)); - - // 绘制线 - 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); - } - texIndexList.add(i); - } - } - - @Override - public void clearPolyline() { - if (mPolyline != null) { - mPolyline.remove(); - } - } - - @Override - public void setLineMarker() { - - } - - public void clearCoordinatesLatLng(){ - textureList.clear(); - texIndexList.clear(); - mCoordinatesLatLng.clear(); - mLineStationLatLng.clear(); - CallerLogger.INSTANCE.d(M_BUS_P + TAG, " mCoordinatesLatLng.clear " ); - } - - public void onCreateView(Bundle savedInstanceState) { - if (mAMapNaviView != null) { - mAMapNaviView.onCreate(savedInstanceState); - } - } - - public void onResume() { - if (mAMapNaviView != null) { - mAMapNaviView.onResume(); - } - } - - public void onPause() { - if (mAMapNaviView != null) { - mAMapNaviView.onPause(); - } - } - - public void onDestroy() { - if (mAMapNaviView != null) { - mAMapNaviView.onDestroy(); - } - } - - public void setCoordinatesLatLng(List latLngs,int haveArrivedIndex) { - mCoordinatesLatLng.clear(); - mCoordinatesLatLng.addAll(latLngs); - mHaveArrivedIndex = haveArrivedIndex; - } - - public void clearLineMarkers(){ - for (int i =0; i< mLineMarkers.size();i++){ - mLineMarkers.get(i).setVisible(false); - mLineMarkers.get(i).remove(); - } - mLineMarkers.clear(); - } - - public void setLinePointMarkerAndDraw(List mLineStationsList, int currentIndex) { - clearLineMarkers(); - mLineStationLatLng.clear(); - mLineStationLatLng.addAll(mLineStationsList); - - if (mLineStationsList.size() > 0){ - // 起点marker, 终点marker, 过站marker, 未过站marker - - int size = mLineStationsList.size(); - - Marker mStartMarker = mAMap.addMarker(new MarkerOptions() - .icon(BitmapDescriptorFactory.fromResource(R.drawable.bus_p_map_start_point))); - Marker mEndMarker = mAMap.addMarker(new MarkerOptions() - .icon(BitmapDescriptorFactory.fromResource(R.drawable.bus_p_map_end_point))); - - mStartMarker.setPosition(mLineStationsList.get(0)); - mLineMarkers.add(0,mStartMarker); - - for (int i = 0; i < mLineStationsList.size(); i++) { - if (currentIndex <= i && i < size-1 && i > 0){ //未到达 - Marker unArrivedMarker = mAMap.addMarker(new MarkerOptions() - .icon(BitmapDescriptorFactory.fromResource(R.drawable.bus_p_map_unarrived_point))); - unArrivedMarker.setPosition(mLineStationsList.get(i)); - mLineMarkers.add(i,unArrivedMarker); - }else if (i < currentIndex && i > 0){ - Marker arrivedMarker = mAMap.addMarker(new MarkerOptions() - .icon(BitmapDescriptorFactory.fromResource(R.drawable.bus_p_map_arrived_point))); - arrivedMarker.setPosition(mLineStationsList.get(i)); - mLineMarkers.add(i,arrivedMarker); - } - } - - mEndMarker.setPosition(mLineStationsList.get(size-1)); - mLineMarkers.add(size-1,mEndMarker); - } - } - - @Override - public void onCameraChange(CameraPosition cameraPosition) { -// mIBusPassengerMapViewCallback.onCameraChange(cameraPosition.bearing); - } - - @Override - public void onCameraChangeFinish(CameraPosition cameraPosition) { - - } -} diff --git a/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/ui/BusPassengerMapDirectionView.kt b/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/ui/BusPassengerMapDirectionView.kt new file mode 100644 index 0000000000..d8cbb83458 --- /dev/null +++ b/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/ui/BusPassengerMapDirectionView.kt @@ -0,0 +1,328 @@ +package com.mogo.och.bus.passenger.ui + +import android.content.Context +import android.os.Bundle +import android.util.AttributeSet +import android.view.LayoutInflater +import android.view.MotionEvent +import android.view.View +import android.widget.RelativeLayout +import com.amap.api.maps.AMap +import com.amap.api.maps.CameraUpdateFactory +import com.amap.api.maps.TextureMapView +import com.amap.api.maps.model.BitmapDescriptor +import com.amap.api.maps.model.BitmapDescriptorFactory +import com.amap.api.maps.model.CameraPosition +import com.amap.api.maps.model.CustomMapStyleOptions +import com.amap.api.maps.model.LatLng +import com.amap.api.maps.model.LatLngBounds +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.MogoLocation +import com.mogo.eagle.core.function.api.autopilot.IMoGoChassisLocationGCJ02Listener +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.eagle.core.utilcode.mogo.logger.scene.SceneConstant.Companion.M_BUS_P +import com.mogo.och.bus.passenger.R +import com.mogo.och.bus.passenger.utils.BusPassengerMapAssetStyleUtil + +/** + * 乘客屏小地图 + */ +class BusPassengerMapDirectionView @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 +) : RelativeLayout(context, attrs, defStyleAttr), IMoGoChassisLocationGCJ02Listener, + IBusPassengerMapDirectionView, AMap.OnCameraChangeListener { + + companion object { + //小地图名称 + const val TAG = "TPMapDirectionView" + } + + private lateinit var mAMapNaviView: TextureMapView + private lateinit var mAMap: AMap + private var mPolyline: Polyline? = null + private val mLineMarkers: MutableList = ArrayList() + private lateinit var mCarMarker: Marker + + private val mLineStationLatLng: MutableList = ArrayList() //站点坐标数据 + var textureList: MutableList = ArrayList() + var texIndexList: MutableList = ArrayList() + private var mArrivedRes: BitmapDescriptor? = null + private var mUnArrivedRes: BitmapDescriptor? = null + + private val routeArrivied: MutableList = ArrayList() + private val routeArriving: MutableList = ArrayList() + private var location: MogoLocation? = null + + init { + try { + initView(context) + } catch (e: Exception) { + e.printStackTrace() + } + } + + private fun initView(context: Context) { + d(M_BUS_P + TAG, "initView") + val smpView = LayoutInflater.from(context).inflate(R.layout.bus_p_map_view, this) + mAMapNaviView = smpView.findViewById(R.id.bus_p_line_amap_view) as TextureMapView + initAMapView() + + // 注册定位监听 + CallerChassisLocationGCJ02ListenerManager.addListener(TAG, 10, this) + } + + override fun onDetachedFromWindow() { + super.onDetachedFromWindow() + // 注册定位监听 + CallerChassisLocationGCJ02ListenerManager.removeListener(TAG) + } + + private fun initAMapView() { + mAMap = mAMapNaviView.map + // 设置导航地图模式,aMap是地图控制器对象。 + mAMap.mapType = AMap.MAP_TYPE_NIGHT + + // 关闭显示实时路况图层,aMap是地图控制器对象。 + mAMap.isTrafficEnabled = false + + // 设置 锚点 图标 + mCarMarker = mAMap.addMarker(MarkerOptions().icon(BitmapDescriptorFactory.fromResource(R.drawable.bus_p_map_car)).anchor(0.5f, 0.5f)) + mArrivedRes = BitmapDescriptorFactory.fromResource(R.drawable.bus_p_map_arrow_arrived) + mUnArrivedRes = BitmapDescriptorFactory.fromResource(R.drawable.bus_p_map_arrow_un_arrive) + + // 加载自定义样式 + val customMapStyleOptions = CustomMapStyleOptions() + .setEnable(true) + .setStyleData( + BusPassengerMapAssetStyleUtil.getAssetsStyle( + context, "map_style.data" + ) + ) + .setStyleExtraData( + BusPassengerMapAssetStyleUtil.getAssetsExtraStyle( + context, "map_style_extra.data" + ) + ) + // 设置自定义样式 + mAMap.setCustomMapStyle(customMapStyleOptions) + + // 设置地图的样式 + mAMap.uiSettings.apply { + isZoomControlsEnabled = false // 地图缩放级别的交换按钮 + setAllGesturesEnabled(false) // 所有手势 + isMyLocationButtonEnabled = false // 显示默认的定位按钮 + setLogoBottomMargin(-150) //设置Logo下边界距离屏幕底部的边距,设置为负值即可 + } + + mAMap.setOnMapLoadedListener { + d(M_BUS_P + TAG, "smp---onMapLoaded") + // 加载自定义样式 + val options = CustomMapStyleOptions() + .setEnable(true) + .setStyleData( + BusPassengerMapAssetStyleUtil.getAssetsStyle( + context, "map_style.data" + ) + ) + .setStyleExtraData( + BusPassengerMapAssetStyleUtil.getAssetsExtraStyle( + context, "map_style_extra.data" + ) + ) + // 设置自定义样式 + mAMap.setCustomMapStyle(options) + mAMapNaviView.map.setPointToCenter( + mAMapNaviView.width / 2, + mAMapNaviView.height / 2 + ) + } + + //设置地图状态的监听接口 + mAMap.setOnCameraChangeListener(this) + } + + override fun onInterceptTouchEvent(ev: MotionEvent): Boolean { + return true + } + + override fun onChassisLocationGCJ02(mogoLocation: MogoLocation?) { + if (mogoLocation == null) { + return + } + val currentLatLng = LatLng(mogoLocation.latitude, mogoLocation.longitude) + + //更新车辆位置 + mCarMarker.rotateAngle = (360 - mogoLocation.heading).toFloat() + mCarMarker.position = currentLatLng + mCarMarker.setToTop() + try { + //圈定地图显示范围 + val boundsBuilder = LatLngBounds.Builder() + routeArrivied.forEach { + boundsBuilder.include(it) + } + routeArriving.forEach { + boundsBuilder.include(it) + } + mLineStationLatLng.forEach { + boundsBuilder.include(it) + } + boundsBuilder.include(currentLatLng) + mAMap.moveCamera( + CameraUpdateFactory.newLatLngBoundsRect( + boundsBuilder.build(), + 100, + 100, + 100, + 100 + ) + ) + } catch (e: Exception) { + e.printStackTrace() + } + } + + override fun drawablePolyline() { + if (routeArrivied.isEmpty() && routeArriving.isEmpty()) { + d(SceneConstant.M_TAXI + TAG, "没有点") + return + } + texIndexList.clear() + val allPoints = ArrayList(routeArrivied) + for (i in routeArrivied.indices) { + if (routeArrivied.size > 1 && i < routeArrivied.size - 1) { + texIndexList.add(0) + } + } + texIndexList.add(0) + allPoints.add(LatLng(location!!.latitude, location!!.longitude)) + allPoints.addAll(routeArriving) + for (ignored in routeArrivied) { + texIndexList.add(1) + } + if (mPolyline != null) { + mPolyline!!.points = allPoints + mPolyline!!.options.customTextureIndex = texIndexList + return + } + textureList.add(mArrivedRes) + textureList.add(mUnArrivedRes) + //设置线段纹理 + val polylineOptions = PolylineOptions().apply { + addAll(allPoints) + isUseTexture = true + width(15f) + lineCapType(PolylineOptions.LineCapType.LineCapRound) + customTextureList = textureList + customTextureIndex = texIndexList + } + + // 绘制线 + mPolyline = mAMap.addPolyline(polylineOptions) + } + + override fun clearPolyline() { + if (mPolyline != null) { + mPolyline!!.remove() + } + } + + override fun setLineMarker() {} + + fun clearCoordinatesLatLng() { + textureList.clear() + texIndexList.clear() + routeArrivied.clear() + routeArriving.clear() + mLineStationLatLng.clear() + d(M_BUS_P + TAG, " mCoordinatesLatLng.clear ") + } + + fun onCreateView(savedInstanceState: Bundle?) { + mAMapNaviView.onCreate(savedInstanceState) + } + + fun onResume() { + mAMapNaviView.onResume() + } + + fun onPause() { + mAMapNaviView.onPause() + } + + fun onDestroy() { + mAMapNaviView.onDestroy() + } + + fun setCoordinatesLatLng( + routeArrivied: List?, + routeArriving: List?, + location: MogoLocation? + ) { + this.routeArrivied.clear() + this.routeArrivied.addAll(routeArrivied!!) + this.routeArriving.clear() + this.routeArriving.addAll(routeArriving!!) + this.location = location + } + + fun clearLineMarkers() { + for (i in mLineMarkers.indices) { + mLineMarkers[i].isVisible = false + mLineMarkers[i].remove() + } + mLineMarkers.clear() + } + + fun setLinePointMarkerAndDraw(mLineStationsList: List, currentIndex: Int) { + clearLineMarkers() + mLineStationLatLng.clear() + mLineStationLatLng.addAll(mLineStationsList) + if (mLineStationsList.isNotEmpty()) { + // 起点marker, 终点marker, 过站marker, 未过站marker + val size = mLineStationsList.size + val mStartMarker = mAMap.addMarker( + MarkerOptions() + .icon(BitmapDescriptorFactory.fromResource(R.drawable.bus_p_map_start_point)) + ) + val mEndMarker = mAMap.addMarker( + MarkerOptions() + .icon(BitmapDescriptorFactory.fromResource(R.drawable.bus_p_map_end_point)) + ) + mStartMarker.position = mLineStationsList[0] + mLineMarkers.add(0, mStartMarker) + for (i in mLineStationsList.indices) { + if (currentIndex <= i && i < size - 1 && i > 0) { //未到达 + val unArrivedMarker = mAMap.addMarker( + MarkerOptions() + .icon(BitmapDescriptorFactory.fromResource(R.drawable.bus_p_map_unarrived_point)) + ) + unArrivedMarker.position = mLineStationsList[i] + mLineMarkers.add(i, unArrivedMarker) + } else if (i in 1 until currentIndex) { + val arrivedMarker = mAMap.addMarker( + MarkerOptions() + .icon(BitmapDescriptorFactory.fromResource(R.drawable.bus_p_map_arrived_point)) + ) + arrivedMarker.position = mLineStationsList[i] + mLineMarkers.add(i, arrivedMarker) + } + } + mEndMarker.position = mLineStationsList[size - 1] + mLineMarkers.add(size - 1, mEndMarker) + } + } + + override fun onCameraChange(cameraPosition: CameraPosition) { + } + + override fun onCameraChangeFinish(cameraPosition: CameraPosition) {} + +} \ No newline at end of file diff --git a/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/ui/BusPassengerRouteFragment.java b/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/ui/BusPassengerRouteFragment.java index b39b06239e..33d497dbf3 100644 --- a/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/ui/BusPassengerRouteFragment.java +++ b/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/ui/BusPassengerRouteFragment.java @@ -240,9 +240,9 @@ public class BusPassengerRouteFragment extends } } - public void routeResult(List latLngList,int haveArrivedIndex) { - if (latLngList.size() > 0) { - drawablePolyline(latLngList,haveArrivedIndex); + public void routeResult(List routeArrivied,List routeArriving,MogoLocation location) { + if (routeArrivied.size() > 0||routeArriving.size()>0) { + drawablePolyline(routeArrivied,routeArriving,location); } else { clearMapView(); } @@ -253,15 +253,10 @@ public class BusPassengerRouteFragment extends * * @param coordinates */ - private void drawablePolyline(List coordinates,int haveArrivedIndex) { + private void drawablePolyline(List routeArrivied,List routeArriving,MogoLocation location) { if (mMapDirectionView != null) { - mMapDirectionView.setCoordinatesLatLng(coordinates,haveArrivedIndex); - UiThreadHandler.post(new Runnable() { - @Override - public void run() { - mMapDirectionView.drawablePolyline(); - } - }); + mMapDirectionView.setCoordinatesLatLng(routeArrivied,routeArriving,location); + UiThreadHandler.post(() -> mMapDirectionView.drawablePolyline()); } } diff --git a/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/utils/BPRouteDataTestUtils.java b/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/utils/BPRouteDataTestUtils.java index ac7db3446d..1c420c3c15 100644 --- a/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/utils/BPRouteDataTestUtils.java +++ b/OCH/mogo-och-bus-passenger/src/jinlvvan/java/com/mogo/och/bus/passenger/utils/BPRouteDataTestUtils.java @@ -50,7 +50,7 @@ public class BPRouteDataTestUtils { } BusPassengerModel.getInstance().updateRoutePoints(list); BusPassengerModel.getInstance().startRemainRouteInfo(); - BusPassengerModel.getInstance().startToRouteAndWipe(); + //BusPassengerModel.getInstance().startToRouteAndWipe(); } catch (JSONException e) { e.printStackTrace(); } diff --git a/OCH/mogo-och-bus/src/jinlvvan/java/com/mogo/och/bus/model/OrderModel.java b/OCH/mogo-och-bus/src/jinlvvan/java/com/mogo/och/bus/model/OrderModel.java index cb551c077d..3e0a97a21b 100644 --- a/OCH/mogo-och-bus/src/jinlvvan/java/com/mogo/och/bus/model/OrderModel.java +++ b/OCH/mogo-och-bus/src/jinlvvan/java/com/mogo/och/bus/model/OrderModel.java @@ -63,6 +63,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.ITrajectoryListener; +import com.mogo.och.common.module.manager.trajectorymamager.TrajectoryAndDistanceManager; import com.mogo.och.common.module.utils.CoordinateCalculateRouteUtil; import com.mogo.och.common.module.utils.DateTimeUtil; import com.mogo.och.common.module.utils.NumberFormatUtil; @@ -172,6 +174,8 @@ public class OrderModel { AbnormalFactorsLoopManager.INSTANCE.startLoopAbnormalFactors(mContext); + TrajectoryAndDistanceManager.INSTANCE.addTrajectoryListener(TAG,trajectoryListener); + //2022.1.28 // 调用Disposable.dispose() 时候会出现InterruptedException 导致出现崩溃 // The exception could not be delivered to the consumer because it has already canceled/disposed @@ -267,6 +271,12 @@ public class OrderModel { this.mControllerStatusCallback = callback; } + private final ITrajectoryListener trajectoryListener = new ITrajectoryListener() { + @Override + public void trajectoryCallback(@NonNull List routeArrivied, @NonNull List routeArriving, @NonNull MogoLocation location) { + + } + }; private final IMoGoPlanningRottingListener moGoAutopilotPlanningListener = new IMoGoPlanningRottingListener() { @Override @@ -346,6 +356,8 @@ public class OrderModel { OCHSocketMessageManager.msgWriteOffPassengerType); AbnormalFactorsLoopManager.INSTANCE.stopLoopAbnormalFactors(); + + TrajectoryAndDistanceManager.INSTANCE.removeListener(TAG); } private Object readResolve() { @@ -614,6 +626,7 @@ public class OrderModel { , nextStation , isLastStop); } + } private void onStartAutopilot(int leaveIndex) { @@ -756,16 +769,24 @@ public class OrderModel { CallerLogger.INSTANCE.d(M_BUS + TAG, "leaveStation-backgroundCurrentStationIndex = " + backgroundCurrentStationIndex); String nextStationName = ""; String nextStationNameKr = ""; + MogoLocation nextStationPoint = new MogoLocation(); if (backgroundCurrentStationIndex < stationList.size() - 1) { - nextStationName = stationList.get(backgroundCurrentStationIndex + 1).getName(); - nextStationNameKr = stationList.get(backgroundCurrentStationIndex + 1).getNameKr(); + BusStationBean nextStation = stationList.get(backgroundCurrentStationIndex + 1); + nextStationName = nextStation.getName(); + nextStationNameKr = nextStation.getNameKr(); + nextStationPoint.setLongitude(nextStation.getGcjLon()); + nextStationPoint.setLatitude(nextStation.getGcjLat()); } - final String currentStationName = stationList.get(backgroundCurrentStationIndex).getName(); + BusStationBean busStationBean = stationList.get(backgroundCurrentStationIndex); + final String currentStationName = busStationBean.getName(); String finalNextStationName = nextStationName; String finalNextStationNameKr = nextStationNameKr; + MogoLocation currentStationPoint = new MogoLocation(); + currentStationPoint.setLongitude(busStationBean.getGcjLon()); + currentStationPoint.setLatitude(busStationBean.getGcjLat()); OrderServiceManager.leaveStation(mContext, - stationList.get(backgroundCurrentStationIndex).getSeq(), - stationList.get(backgroundCurrentStationIndex).getSiteId(), + busStationBean.getSeq(), + busStationBean.getSiteId(), currentTaskId, new OchCommonServiceCallback() { @Override @@ -777,6 +798,7 @@ public class OrderModel { queryBusRoutes(); leaveStationSuccess(backgroundCurrentStationIndex, currentStationName, finalNextStationName,finalNextStationNameKr); + setTrajectoryStation(currentStationPoint,nextStationPoint, (long) currentLineId); } @@ -1032,7 +1054,7 @@ public class OrderModel { } CallerLogger.INSTANCE.d(M_BUS + TAG, "单程结束===="); CallerAutoPilotControlManager.INSTANCE.cancelAutoPilot(); - + setTrajectoryStation(null,null,-1L); endTask(); } @@ -1253,4 +1275,8 @@ public class OrderModel { return parameters; } + + public void setTrajectoryStation(MogoLocation startStation,MogoLocation endStation,Long lineId){ + TrajectoryAndDistanceManager.INSTANCE.setStationPoint(startStation,endStation,lineId); + } } 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 13726d30f5..89ca3ba516 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 @@ -101,13 +101,17 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{ } private fun removeTempData() { + resetStation() + preCarLocationIndexInTrajectory = 0 + lineId = null + } + private fun resetStation() { this.endStationInfo.index = null this.endStationInfo.distance = null this.endStationInfo.isNext = null this.startStationInfo.index = null this.startStationInfo.distance = null this.startStationInfo.isNext = null - preCarLocationIndexInTrajectory = 0 } fun cleanRoutePoints() { @@ -117,18 +121,37 @@ object TrajectoryAndDistanceManager: IMoGoPlanningRottingListener{ /** * 设置或清理站点坐标 */ - fun setStationPoint(startStationInfo: MogoLocation?,endStationInfo: MogoLocation?) { - this.endStationInfo.stationPoint = endStationInfo - this.startStationInfo.stationPoint = startStationInfo - if (this.endStationInfo.stationPoint == null) { + fun setStationPoint(startStationInfo: MogoLocation?,endStationInfo: MogoLocation?,lineId:Long?) { + if (startStationInfo == null || endStationInfo == null || lineId == -1L) { removeTempData() endCalculateDistanceLoop() cleanRoutePoints() }else{ + if(isSameStation(this.startStationInfo.stationPoint,startStationInfo)&& + isSameStation(this.endStationInfo.stationPoint,endStationInfo)){ + if(this.lineId!=lineId){ + resetStation() + } + }else{ + resetStation() + } + this.endStationInfo.stationPoint = endStationInfo + this.startStationInfo.stationPoint = startStationInfo + this.lineId = lineId startCalculateDistanceLoop() } } + private fun isSameStation(stationOne: MogoLocation?,stationTwo: MogoLocation?):Boolean{ + if(stationOne==null||stationTwo==null){ + return false + } + if(stationOne.longitude==stationTwo.longitude&&stationOne.latitude==stationTwo.latitude){ + return true + } + return false + } + /** * 根据两点距离和轨迹距离来计算真实距离 */ diff --git a/OCH/mogo-och-taxi-passenger/src/main/java/com/mogo/och/taxi/passenger/model/TaxiPassengerModel.java b/OCH/mogo-och-taxi-passenger/src/main/java/com/mogo/och/taxi/passenger/model/TaxiPassengerModel.java index 83f5e3ae9b..c5101319c1 100644 --- a/OCH/mogo-och-taxi-passenger/src/main/java/com/mogo/och/taxi/passenger/model/TaxiPassengerModel.java +++ b/OCH/mogo-och-taxi-passenger/src/main/java/com/mogo/och/taxi/passenger/model/TaxiPassengerModel.java @@ -1068,12 +1068,12 @@ public class TaxiPassengerModel implements IOCHTaxiPassengerNaviChangedCallback MogoLocation endStation = new MogoLocation(); endStation.setLongitude(mCurrentOCHOrder.endSiteGcjPoint.get(0)); endStation.setLatitude(mCurrentOCHOrder.endSiteGcjPoint.get(1)); - TrajectoryAndDistanceManager.INSTANCE.setStationPoint(startStation,endStation); + TrajectoryAndDistanceManager.INSTANCE.setStationPoint(startStation,endStation,mCurrentOCHOrder.lineId); } } public void cleanStation(){ - TrajectoryAndDistanceManager.INSTANCE.setStationPoint(null,null); + TrajectoryAndDistanceManager.INSTANCE.setStationPoint(null,null,-1L); } } 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 9f72c19b8d..2667c72c42 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 @@ -1719,11 +1719,11 @@ public class TaxiModel { MogoLocation endStation = new MogoLocation(); endStation.setLongitude(currentOCHOrder.endSiteGcjPoint.get(0)); endStation.setLatitude(currentOCHOrder.endSiteGcjPoint.get(1)); - TrajectoryAndDistanceManager.INSTANCE.setStationPoint(startStation,endStation); + TrajectoryAndDistanceManager.INSTANCE.setStationPoint(startStation,endStation,currentOCHOrder.lineId); } } public void cleanStation(){ - TrajectoryAndDistanceManager.INSTANCE.setStationPoint(null,null); + TrajectoryAndDistanceManager.INSTANCE.setStationPoint(null,null,-1L); } }