[feature]
[bus 轨迹计算]
This commit is contained in:
@@ -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<LatLng> models,int haveArrivedIndex);
|
||||
void routeResult(List<LatLng> routeArrivied, List<LatLng> routeArriving, MogoLocation location);
|
||||
void routePlanningToNextStationChanged(long meters, long timeInSecond);
|
||||
void updateTotalDistance();
|
||||
}
|
||||
|
||||
@@ -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<LatLng> routeArriviedTemp = new ArrayList<>();
|
||||
List<LatLng> 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<MessagePad.Location> 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<Integer, List<MogoLocation>> lastPointsMap = CoordinateCalculateRouteUtil
|
||||
.getRemainPointListByCompareNew(mPreRouteIndex, mTwoStationsRouts, mLocation);
|
||||
if(lastPointsMap==null){
|
||||
return;
|
||||
}
|
||||
for (int index : lastPointsMap.keySet()) {
|
||||
mPreRouteIndex = index;
|
||||
break;
|
||||
}
|
||||
|
||||
for (List<MogoLocation> 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<Integer, List<MogoLocation>> lastPointsMap = CoordinateCalculateRouteUtil
|
||||
// .getRemainPointListByCompareNew(mPreRouteIndex, mTwoStationsRouts, mLocation);
|
||||
// if(lastPointsMap==null){
|
||||
// return;
|
||||
// }
|
||||
// for (int index : lastPointsMap.keySet()) {
|
||||
// mPreRouteIndex = index;
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// for (List<MogoLocation> 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<LatLng> 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<LatLng> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -152,10 +152,8 @@ public class BaseBusPassengerPresenter extends Presenter<BusPassengerRouteFragme
|
||||
}
|
||||
|
||||
@Override
|
||||
public void routeResult(List<LatLng> models, int haveArrivedIndex) {
|
||||
CallerLogger.INSTANCE.d(M_BUS_P + TAG, "routeResult:" + models.size()
|
||||
+ " haveArrivedIndex = "+haveArrivedIndex);
|
||||
runOnUIThread(() ->mView.routeResult(models,haveArrivedIndex));
|
||||
public void routeResult(List<LatLng> routeArrivied,List<LatLng> routeArriving,MogoLocation location) {
|
||||
runOnUIThread(() ->mView.routeResult(routeArrivied,routeArriving,location));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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<LatLng> mCoordinatesLatLng = new ArrayList<>(); //轨迹坐标数据
|
||||
private List<LatLng> mLineStationLatLng = new ArrayList<>();//站点坐标数据
|
||||
private Polyline mPolyline;
|
||||
|
||||
List<BitmapDescriptor> textureList = new ArrayList<>();
|
||||
List<Integer> texIndexList = new ArrayList<>();
|
||||
private int mHaveArrivedIndex = 0;
|
||||
|
||||
private List<Marker> 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<LatLng> 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<LatLng> 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) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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<Marker> = ArrayList()
|
||||
private lateinit var mCarMarker: Marker
|
||||
|
||||
private val mLineStationLatLng: MutableList<LatLng> = ArrayList() //站点坐标数据
|
||||
var textureList: MutableList<BitmapDescriptor?> = ArrayList()
|
||||
var texIndexList: MutableList<Int> = ArrayList()
|
||||
private var mArrivedRes: BitmapDescriptor? = null
|
||||
private var mUnArrivedRes: BitmapDescriptor? = null
|
||||
|
||||
private val routeArrivied: MutableList<LatLng> = ArrayList()
|
||||
private val routeArriving: MutableList<LatLng> = 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<View>(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<LatLng>?,
|
||||
routeArriving: List<LatLng>?,
|
||||
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<LatLng>, 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) {}
|
||||
|
||||
}
|
||||
@@ -240,9 +240,9 @@ public class BusPassengerRouteFragment extends
|
||||
}
|
||||
}
|
||||
|
||||
public void routeResult(List<LatLng> latLngList,int haveArrivedIndex) {
|
||||
if (latLngList.size() > 0) {
|
||||
drawablePolyline(latLngList,haveArrivedIndex);
|
||||
public void routeResult(List<LatLng> routeArrivied,List<LatLng> 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<LatLng> coordinates,int haveArrivedIndex) {
|
||||
private void drawablePolyline(List<LatLng> routeArrivied,List<LatLng> 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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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<MogoLocation> routeArrivied, @NonNull List<MogoLocation> 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<BaseData>() {
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据两点距离和轨迹距离来计算真实距离
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user