优化
This commit is contained in:
@@ -287,6 +287,8 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
|||||||
String name = tip.getName();
|
String name = tip.getName();
|
||||||
String district = tip.getDistrict();
|
String district = tip.getDistrict();
|
||||||
endName = name;
|
endName = name;
|
||||||
|
endAddress = tip.getAddress();
|
||||||
|
isGetInputtips = true;
|
||||||
isUserSelectedDestination = true; // 标识用户手动选择了目的地
|
isUserSelectedDestination = true; // 标识用户手动选择了目的地
|
||||||
isProgrammaticTextChange = true; // 标识是程序自动设置文本
|
isProgrammaticTextChange = true; // 标识是程序自动设置文本
|
||||||
endInput.setText(district != null && !district.isEmpty() ? name + " " + district : name);
|
endInput.setText(district != null && !district.isEmpty() ? name + " " + district : name);
|
||||||
@@ -525,6 +527,8 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
|||||||
return panel;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isGetInputtips = false;
|
||||||
|
|
||||||
private void calculateRouteBeforeNavi() {
|
private void calculateRouteBeforeNavi() {
|
||||||
if (startPoint == null) {
|
if (startPoint == null) {
|
||||||
Toast.makeText(mContext, "正在定位...", Toast.LENGTH_SHORT).show();
|
Toast.makeText(mContext, "正在定位...", Toast.LENGTH_SHORT).show();
|
||||||
@@ -536,7 +540,18 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchTruckRouteAlgorithm(mLoc);
|
//如果是输入地址提示内容
|
||||||
|
|
||||||
|
if (isGetInputtips) {
|
||||||
|
// 开始规划前隐藏输入框面板
|
||||||
|
searchArea.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
RouteSearch.FromAndTo fromAndTo = new RouteSearch.FromAndTo(new LatLonPoint(startPoint.latitude, startPoint.longitude), new LatLonPoint(endPoint.latitude, endPoint.longitude));
|
||||||
|
RouteSearch.DriveRouteQuery query = new RouteSearch.DriveRouteQuery(fromAndTo, RouteSearch.DRIVING_SINGLE_DEFAULT, null, null, "");
|
||||||
|
routeSearch.calculateDriveRouteAsyn(query);
|
||||||
|
} else {
|
||||||
|
fetchTruckRouteAlgorithm(mLoc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -584,34 +599,58 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDriveRouteSearched(DriveRouteResult result, int rCode) {
|
public void onDriveRouteSearched(DriveRouteResult result, int rCode) {
|
||||||
if (rCode == AMapException.CODE_AMAP_SUCCESS && result != null && !result.getPaths().isEmpty()) {
|
mActivity.runOnUiThread(new Runnable() {
|
||||||
DrivePath path = result.getPaths().get(0);
|
@Override
|
||||||
|
public void run() {
|
||||||
// 规划成功,显示详情面板,隐藏模式选择
|
|
||||||
detailPanel.setVisibility(View.VISIBLE);
|
|
||||||
planToggleBtn.setVisibility(View.GONE);
|
|
||||||
modeMenu.setVisibility(View.GONE);
|
|
||||||
|
|
||||||
tvStationName.setText(endName);
|
|
||||||
tvStationAddr.setText(endAddress);
|
|
||||||
|
|
||||||
|
|
||||||
double distanceKm = path.getDistance() / 1000f;
|
if (rCode == AMapException.CODE_AMAP_SUCCESS && result != null && !result.getPaths().isEmpty()) {
|
||||||
long durationMin = path.getDuration() / 60;
|
DrivePath path = result.getPaths().get(0);
|
||||||
double tolls = path.getTolls();
|
|
||||||
String hydrogenCost = truckRouteData.algorithmPath.hydrogenCost;
|
|
||||||
|
|
||||||
tvDuration.setText("预计时间:" + durationMin + "分钟");
|
// 规划成功,显示详情面板,隐藏模式选择
|
||||||
tvDistance.setText("行驶里程:" + String.format("%.1f", distanceKm) + "公里");
|
if (detailPanel != null)
|
||||||
tvTolls.setText("过路费:" + (int) tolls + "元");
|
detailPanel.setVisibility(View.VISIBLE);
|
||||||
tvTollsFuel.setText("加氢费用:" + hydrogenCost + "元");
|
if (planToggleBtn != null)
|
||||||
|
planToggleBtn.setVisibility(View.GONE);
|
||||||
|
if (modeMenu != null)
|
||||||
|
modeMenu.setVisibility(View.GONE);
|
||||||
|
|
||||||
aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(endPoint, 13f));
|
tvStationName.setText(endName);
|
||||||
} else {
|
tvStationAddr.setText(endAddress);
|
||||||
// 规划失败回退面板
|
|
||||||
searchArea.setVisibility(View.VISIBLE);
|
double distanceKm = path.getDistance() / 1000f;
|
||||||
Toast.makeText(mContext, "路径规划失败: " + rCode, Toast.LENGTH_SHORT).show();
|
long durationMin = path.getDuration() / 60;
|
||||||
}
|
double tolls = path.getTolls();
|
||||||
|
|
||||||
|
String hydrogenCost = "--"; // 默认显示横线
|
||||||
|
try {
|
||||||
|
// 增加多级非空校验,防止点击搜索条目时崩溃
|
||||||
|
if (truckRouteData != null &&
|
||||||
|
truckRouteData.algorithmPath != null &&
|
||||||
|
truckRouteData.algorithmPath.hydrogenCost != null &&
|
||||||
|
!truckRouteData.algorithmPath.hydrogenCost.isEmpty()) {
|
||||||
|
hydrogenCost = truckRouteData.algorithmPath.hydrogenCost;
|
||||||
|
}
|
||||||
|
|
||||||
|
tvDuration.setText("预计时间:" + durationMin + "分钟");
|
||||||
|
tvDistance.setText("行驶里程:" + String.format("%.1f", distanceKm) + "公里");
|
||||||
|
tvTolls.setText("过路费:" + (int) tolls + "元");
|
||||||
|
tvTollsFuel.setText("加氢费用:" + (isGetInputtips ? "--" : hydrogenCost) + "元");
|
||||||
|
|
||||||
|
isGetInputtips = false;
|
||||||
|
|
||||||
|
aMap.animateCamera(CameraUpdateFactory.newLatLngZoom(endPoint, 13f));
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "获取加氢费用失败", e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 规划失败回退面板
|
||||||
|
searchArea.setVisibility(View.VISIBLE);
|
||||||
|
Toast.makeText(mContext, "路径规划失败: " + rCode, Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startRouteSearch() {
|
private void startRouteSearch() {
|
||||||
@@ -679,16 +718,20 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
|||||||
//车辆信息
|
//车辆信息
|
||||||
AMapCarInfo carInfo = new AMapCarInfo();
|
AMapCarInfo carInfo = new AMapCarInfo();
|
||||||
carInfo.setCarNumber(plateNumber);
|
carInfo.setCarNumber(plateNumber);
|
||||||
carInfo.setCarType(String.valueOf(truckRouteData.truckDto.mcarType));
|
|
||||||
carInfo.setVehicleAxis(String.valueOf(truckRouteData.truckDto.mvehicleAxis));
|
if (truckRouteData != null) {
|
||||||
carInfo.setVehicleHeight(truckRouteData.truckDto.mvehicleHeight);
|
carInfo.setCarType(String.valueOf(truckRouteData.truckDto.mcarType));
|
||||||
carInfo.setVehicleLength(truckRouteData.truckDto.mvehicleLength);
|
carInfo.setVehicleAxis(String.valueOf(truckRouteData.truckDto.mvehicleAxis));
|
||||||
carInfo.setVehicleWidth(truckRouteData.truckDto.mvehicleWidth);
|
carInfo.setVehicleHeight(truckRouteData.truckDto.mvehicleHeight);
|
||||||
carInfo.setVehicleSize(String.valueOf(truckRouteData.truckDto.mvehicleSize));
|
carInfo.setVehicleLength(truckRouteData.truckDto.mvehicleLength);
|
||||||
carInfo.setVehicleLoad(truckRouteData.truckDto.mvehicleLoad);
|
carInfo.setVehicleWidth(truckRouteData.truckDto.mvehicleWidth);
|
||||||
carInfo.setVehicleWeight(truckRouteData.truckDto.mvehicleWeight);
|
carInfo.setVehicleSize(String.valueOf(truckRouteData.truckDto.mvehicleSize));
|
||||||
carInfo.setRestriction(truckRouteData.truckDto.isRestriction);
|
carInfo.setVehicleLoad(truckRouteData.truckDto.mvehicleLoad);
|
||||||
carInfo.setVehicleLoadSwitch(truckRouteData.truckDto.mvehicleLoadSwitch);
|
carInfo.setVehicleWeight(truckRouteData.truckDto.mvehicleWeight);
|
||||||
|
carInfo.setRestriction(truckRouteData.truckDto.isRestriction);
|
||||||
|
carInfo.setVehicleLoadSwitch(truckRouteData.truckDto.mvehicleLoadSwitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 检查途径点数量,决定使用哪种导航方式
|
// 检查途径点数量,决定使用哪种导航方式
|
||||||
int wayPointsCount = waysPoiIds.size();
|
int wayPointsCount = waysPoiIds.size();
|
||||||
@@ -801,12 +844,17 @@ public class NativeMapView implements PlatformView, LocationSource, AMapLocation
|
|||||||
|
|
||||||
dismissLoading();
|
dismissLoading();
|
||||||
|
|
||||||
// 开始规划前隐藏输入框面板
|
mActivity.runOnUiThread(new Runnable() {
|
||||||
searchArea.setVisibility(View.GONE);
|
@Override
|
||||||
|
public void run() {
|
||||||
|
// 开始规划前隐藏输入框面板
|
||||||
|
searchArea.setVisibility(View.GONE);
|
||||||
|
|
||||||
RouteSearch.FromAndTo fromAndTo = new RouteSearch.FromAndTo(new LatLonPoint(startPoint.latitude, startPoint.longitude), new LatLonPoint(endPoint.latitude, endPoint.longitude));
|
RouteSearch.FromAndTo fromAndTo = new RouteSearch.FromAndTo(new LatLonPoint(startPoint.latitude, startPoint.longitude), new LatLonPoint(endPoint.latitude, endPoint.longitude));
|
||||||
RouteSearch.DriveRouteQuery query = new RouteSearch.DriveRouteQuery(fromAndTo, RouteSearch.DRIVING_SINGLE_DEFAULT, null, null, "");
|
RouteSearch.DriveRouteQuery query = new RouteSearch.DriveRouteQuery(fromAndTo, RouteSearch.DRIVING_SINGLE_DEFAULT, null, null, "");
|
||||||
routeSearch.calculateDriveRouteAsyn(query);
|
routeSearch.calculateDriveRouteAsyn(query);
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
dismissLoading();
|
dismissLoading();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user