路径问题

This commit is contained in:
zhangyuanzhen
2020-02-07 21:41:26 +08:00
parent a3cffb1cb4
commit 796c7e5755
3 changed files with 49 additions and 34 deletions

View File

@@ -6,8 +6,11 @@ import android.text.TextUtils;
import com.amap.api.maps.AMap;
import com.amap.api.navi.model.AMapNaviPath;
import com.amap.api.navi.model.AMapNaviStep;
import com.amap.api.navi.model.NaviLatLng;
import com.mogo.map.MogoLatLng;
import com.mogo.map.impl.amap.overlay.RouteOverLayWrapper;
import java.util.ArrayList;
import java.util.List;
/**
@@ -33,14 +36,14 @@ public class CalculatePathItem {
return mPath;
}
public RouteOverLayWrapper getOverLazWrapper( boolean createIfNull ) {
if ( mOverLazWrapper == null && createIfNull ) {
mOverLazWrapper = new RouteOverLayWrapper( mContext, mAMap, mPath );
public RouteOverLayWrapper getOverLazWrapper(boolean createIfNull) {
if (mOverLazWrapper == null && createIfNull) {
mOverLazWrapper = new RouteOverLayWrapper(mContext, mAMap, mPath);
}
return mOverLazWrapper;
}
public CalculatePathItem( Context context, AMap amap, int id, AMapNaviPath path ) {
public CalculatePathItem(Context context, AMap amap, int id, AMapNaviPath path) {
mContext = context;
mAMap = amap;
this.mId = id;
@@ -52,41 +55,41 @@ public class CalculatePathItem {
}
public String getTime() {
if ( mTimeBuilder == null ) {
if (mTimeBuilder == null) {
final int time = mPath.getAllTime();
mTimeBuilder = new StringBuilder();
fillFormatTime( time, mTimeBuilder );
fillFormatTime(time, mTimeBuilder);
}
return mTimeBuilder.toString();
}
private StringBuilder mTimeBuilder;
private void fillFormatTime( int seconds, StringBuilder builder ) {
// int days = seconds / ( 24 * 60 * 60 );
// if ( days > 0 ) {
// builder.append( days ).append( "天" );
// }
// seconds -= days * 24 * 60 * 60;
int hours = seconds / ( 60 * 60 );
if ( hours > 0 ) {
builder.append( hours ).append( "小时" );
private void fillFormatTime(int seconds, StringBuilder builder) {
// int days = seconds / ( 24 * 60 * 60 );
// if ( days > 0 ) {
// builder.append( days ).append( "天" );
// }
// seconds -= days * 24 * 60 * 60;
int hours = seconds / (60 * 60);
if (hours > 0) {
builder.append(hours).append("小时");
}
seconds -= hours * 60 * 60;
int min = seconds / 60;
builder.append( min > 1 ? min : 1 ).append( "分钟" );
builder.append(min > 1 ? min : 1).append("分钟");
}
private String mDistanceCacheStr = "";
public String getDistance() {
if ( TextUtils.isEmpty( mDistanceCacheStr ) ) {
if (TextUtils.isEmpty(mDistanceCacheStr)) {
int distance = mPath.getAllLength();
if ( distance == -1 ) {
if (distance == -1) {
mDistanceCacheStr = "路程总程未获取";
}
if ( distance >= 1000 ) {
mDistanceCacheStr = String.format( "%.1f公里", ( float ) distance / 1000 );
if (distance >= 1000) {
mDistanceCacheStr = String.format("%.1f公里", (float) distance / 1000);
} else {
mDistanceCacheStr = distance + "";
}
@@ -94,19 +97,17 @@ public class CalculatePathItem {
return mDistanceCacheStr;
}
private StringBuilder mDescBuilder = null;
public String getDesc() {
if ( mDescBuilder == null ) {
if (mDescBuilder == null) {
mDescBuilder = new StringBuilder();
int lightsSize = getTrafficNumber();
if ( lightsSize > 0 ) {
mDescBuilder.append( "红绿灯" ).append( lightsSize ).append( "" );
if (lightsSize > 0) {
mDescBuilder.append("红绿灯").append(lightsSize).append("");
}
mDescBuilder.append( " " );
mDescBuilder.append( "收费" ).append( mPath.getTollCost() ).append( "" );
mDescBuilder.append(" ");
mDescBuilder.append("收费").append(mPath.getTollCost()).append("");
}
return mDescBuilder.toString();
@@ -114,11 +115,11 @@ public class CalculatePathItem {
public int getTrafficNumber() {
int trafficLightNumber = 0;
if ( mPath == null ) {
if (mPath == null) {
return trafficLightNumber;
}
List< AMapNaviStep > steps = mPath.getSteps();
for ( AMapNaviStep step : steps ) {
List<AMapNaviStep> steps = mPath.getSteps();
for (AMapNaviStep step : steps) {
trafficLightNumber += step.getTrafficLightNumber();
}
return trafficLightNumber;
@@ -128,9 +129,21 @@ public class CalculatePathItem {
mContext = null;
mAMap = null;
mPath = null;
if ( mOverLazWrapper != null ) {
if (mOverLazWrapper != null) {
mOverLazWrapper.destroy();
}
mOverLazWrapper = null;
}
public List<MogoLatLng> getCoordList() {
ArrayList<MogoLatLng> mogoLatLngs = new ArrayList<>();
for (NaviLatLng latlng : mPath.getCoordList()
) {
MogoLatLng mogoLatLng =
new MogoLatLng(latlng.getLatitude(), latlng.getLongitude());
mogoLatLngs.add(mogoLatLng);
}
return mogoLatLngs;
}
}

View File

@@ -319,9 +319,12 @@ public class NaviOverlayHelper implements OnCalculatePathItemClickInteraction {
public List<MogoLatLng> getCalculatedPathPos() {
if (mPaths != null && !mPaths.isEmpty()) {
return mPaths.get(0).getCoordList();
if (mSelectedCalculatePathItem != null) {
return mSelectedCalculatePathItem.getCoordList();
}
//if (mPaths != null && !mPaths.isEmpty()) {
// return mPaths.get(0).getCoordList();
//}
return null;
}

View File

@@ -45,7 +45,6 @@ class ChoosePathFragment : BaseFragment(), IMogoNaviListener {
override fun onCalculateSuccess() {
var calculatedStrategies = SearchServiceHolder.getNavi()
.calculatedStrategies
if (calculatedStrategies != null && calculatedStrategies.size > 0) {
mAdapter.setDatas(calculatedStrategies)
mAdapter.selectTag = calculatedStrategies[0].tagId