获取导航路径的点

This commit is contained in:
zhangyuanzhen
2020-02-07 20:05:35 +08:00
parent 05bfb55778
commit e16c82f666
8 changed files with 185 additions and 110 deletions

View File

@@ -15,7 +15,9 @@ import com.amap.api.navi.model.AimLessModeCongestionInfo;
import com.amap.api.navi.model.AimLessModeStat;
import com.amap.api.navi.model.NaviInfo;
import com.autonavi.tbt.TrafficFacilityInfo;
import com.mogo.map.MogoLatLng;
import com.mogo.utils.logger.Logger;
import java.util.List;
/**
* @author congtaowang
@@ -229,4 +231,6 @@ public abstract class AMapNaviListenerAdapter implements AMapNaviListener {
public void onNaviRouteNotify( AMapNaviRouteNotifyData aMapNaviRouteNotifyData ) {
}
}

View File

@@ -94,6 +94,8 @@ public class CalculatePathItem {
return mDistanceCacheStr;
}
private StringBuilder mDescBuilder = null;
public String getDesc() {

View File

@@ -162,6 +162,13 @@ public class NaviClient implements IMogoNavi {
return null;
}
@Override public List<MogoLatLng> getCalculatedPathPos() {
if ( mAMapNaviListener != null ) {
return mAMapNaviListener.getCalculatedPathPos();
}
return null;
}
@Override
public OnCalculatePathItemClickInteraction getItemClickInteraction() {
if ( mAMapNaviListener != null ) {

View File

@@ -15,6 +15,7 @@ import com.amap.api.navi.model.AMapNaviCameraInfo;
import com.amap.api.navi.model.AMapNaviInfo;
import com.amap.api.navi.model.AMapNaviLocation;
import com.amap.api.navi.model.NaviInfo;
import com.mogo.map.MogoLatLng;
import com.mogo.map.impl.amap.AMapWrapper;
import com.mogo.map.impl.amap.message.AMapMessageManager;
import com.mogo.map.impl.amap.utils.ObjectUtils;
@@ -231,6 +232,16 @@ public class NaviListenerAdapter extends AMapNaviListenerAdapter {
return null;
}
public List<MogoLatLng> getCalculatedPathPos() {
if ( mNaviOverlayHelper != null ) {
return mNaviOverlayHelper.getCalculatedPathPos();
}
return null;
}
public OnCalculatePathItemClickInteraction getItemClickInteraction() {
if ( mNaviOverlayHelper != null ) {
return mNaviOverlayHelper.getItemClickInteraction();

View File

@@ -12,6 +12,8 @@ import com.amap.api.navi.AMapNavi;
import com.amap.api.navi.model.AMapNaviLocation;
import com.amap.api.navi.model.AMapNaviPath;
import com.amap.api.navi.model.NaviInfo;
import com.amap.api.navi.model.NaviLatLng;
import com.mogo.map.MogoLatLng;
import com.mogo.map.impl.amap.AMapWrapper;
import com.mogo.map.impl.amap.R;
import com.mogo.map.impl.amap.overlay.RouteOverLayWrapper;
@@ -53,14 +55,14 @@ public class NaviOverlayHelper implements OnCalculatePathItemClickInteraction {
// 规划的路线显示边距
private Rect mBoundRect = null;
private List< CalculatePathItem > mCalculatePathItems;
private List< MogoCalculatePath > mPaths = new ArrayList<>();
private List<CalculatePathItem> mCalculatePathItems;
private List<MogoCalculatePath> mPaths = new ArrayList<>();
private int mSelectedPathId;
private CalculatePathItem mSelectedCalculatePathItem;
private OnCalculatePathItemClickInteraction mLineClickInteraction;
public NaviOverlayHelper( AMapNavi mAMapNavi, AMap mAMap, Context mContext ) {
public NaviOverlayHelper(AMapNavi mAMapNavi, AMap mAMap, Context mContext) {
this.mAMapNavi = mAMapNavi;
this.mAMap = mAMap;
this.mContext = mContext;
@@ -73,11 +75,11 @@ public class NaviOverlayHelper implements OnCalculatePathItemClickInteraction {
public void showCalculatedPaths() {
clearCalculatedOverlay();
mCalculatePathItems = getSortedPaths();
if ( mCalculatePathItems == null || mCalculatePathItems.isEmpty() ) {
if (mCalculatePathItems == null || mCalculatePathItems.isEmpty()) {
return;
}
showPathsBound( mCalculatePathItems.get( 0 ).getPath().getBoundsForPath() );
renderPathOverlay( mCalculatePathItems );
showPathsBound(mCalculatePathItems.get(0).getPath().getBoundsForPath());
renderPathOverlay(mCalculatePathItems);
}
/**
@@ -85,40 +87,41 @@ public class NaviOverlayHelper implements OnCalculatePathItemClickInteraction {
*
* @return 排序好的路径规划列表
*/
private List< CalculatePathItem > getSortedPaths() {
private List<CalculatePathItem> getSortedPaths() {
checkAMapInstance();
final Map< Integer, AMapNaviPath > pathMap = mAMapNavi.getNaviPaths();
if ( pathMap == null || pathMap.isEmpty() ) {
final Map<Integer, AMapNaviPath> pathMap = mAMapNavi.getNaviPaths();
if (pathMap == null || pathMap.isEmpty()) {
return null;
}
TreeMap< Integer, AMapNaviPath > sortedMap = new TreeMap< Integer, AMapNaviPath >( new Comparator< Integer >() {
@Override
public int compare( Integer obj1, Integer obj2 ) {
if ( obj1 != null ) {
return obj1.compareTo( obj2 );
TreeMap<Integer, AMapNaviPath> sortedMap =
new TreeMap<Integer, AMapNaviPath>(new Comparator<Integer>() {
@Override
public int compare(Integer obj1, Integer obj2) {
if (obj1 != null) {
return obj1.compareTo(obj2);
}
if (obj2 != null) {
return obj2.compareTo(obj1);
}
return 0;
}
if ( obj2 != null ) {
return obj2.compareTo( obj1 );
}
return 0;
}
} );
sortedMap.putAll( pathMap );
});
sortedMap.putAll(pathMap);
final List< CalculatePathItem > items = new ArrayList<>();
for ( Map.Entry< Integer, AMapNaviPath > entry : sortedMap.entrySet() ) {
if ( entry == null || entry.getKey() == null || entry.getValue() == null ) {
final List<CalculatePathItem> items = new ArrayList<>();
for (Map.Entry<Integer, AMapNaviPath> entry : sortedMap.entrySet()) {
if (entry == null || entry.getKey() == null || entry.getValue() == null) {
continue;
}
items.add( new CalculatePathItem( mContext, mAMap, entry.getKey(), entry.getValue() ) );
items.add(new CalculatePathItem(mContext, mAMap, entry.getKey(), entry.getValue()));
}
return items;
}
private void calculateBoundArea() {
if ( mBoundRect == null ) {
if (mBoundRect == null) {
mBoundRect = new Rect();
final int padding = WindowUtils.dip2px( mContext, 80 );
final int padding = WindowUtils.dip2px(mContext, 80);
mBoundRect.left = padding;
mBoundRect.right = padding;
mBoundRect.top = padding;
@@ -128,57 +131,59 @@ public class NaviOverlayHelper implements OnCalculatePathItemClickInteraction {
/**
* 将规划好的路径显示在视野内
*
* @param bounds
*/
private void showPathsBound( LatLngBounds bounds ) {
private void showPathsBound(LatLngBounds bounds) {
checkAMapInstance();
mAMap.animateCamera( CameraUpdateFactory.newLatLngBoundsRect( bounds, mBoundRect.left, mBoundRect.right, mBoundRect.top, mBoundRect.bottom ) );
mAMap.animateCamera(
CameraUpdateFactory.newLatLngBoundsRect(bounds, mBoundRect.left, mBoundRect.right,
mBoundRect.top, mBoundRect.bottom));
}
private void checkAMapInstance() {
if ( mAMap == null ) {
if (mAMap == null) {
mAMap = AMapWrapper.getAMap();
}
}
public void renderPathOverlay( List< CalculatePathItem > paths ) {
if ( paths == null || paths.size() == 0 ) {
public void renderPathOverlay(List<CalculatePathItem> paths) {
if (paths == null || paths.size() == 0) {
return;
}
for ( int i = 0; i < paths.size(); i++ ) {
final CalculatePathItem item = paths.get( i );
if ( item == null || item.getPath() == null ) {
for (int i = 0; i < paths.size(); i++) {
final CalculatePathItem item = paths.get(i);
if (item == null || item.getPath() == null) {
continue;
}
RouteOverLayWrapper wrapper = item.getOverLazWrapper( true );
wrapper.setTrafficLightsVisible( false );
RouteOverLayWrapper wrapper = item.getOverLazWrapper(true);
wrapper.setTrafficLightsVisible(false);
// 默认选中第一个
if ( i == 0 ) {
if (i == 0) {
mSelectedPathId = item.getId();
mSelectedCalculatePathItem = item;
wrapper.setStartBitmap( R.drawable.ic_navi_start ).setEndBitmap( R.drawable.ic_navi_target );
mAMapNavi.selectRouteId( item.getId() );
wrapper.setStartBitmap(R.drawable.ic_navi_start)
.setEndBitmap(R.drawable.ic_navi_target);
mAMapNavi.selectRouteId(item.getId());
}
wrapper.addToMap();
wrapper.setTransparency( i == 0 ? AMAP_ROUTE_OVERLAY_TRANSPARENCY_SELECTED : AMAP_ROUTE_OVERLAY_TRANSPARENCY_UNSELECTED );
wrapper.setTransparency(i == 0 ? AMAP_ROUTE_OVERLAY_TRANSPARENCY_SELECTED
: AMAP_ROUTE_OVERLAY_TRANSPARENCY_UNSELECTED);
}
}
public void clearCalculatedOverlay() {
if ( mCalculatePathItems != null && !mCalculatePathItems.isEmpty() ) {
for ( CalculatePathItem calculatePathItem : mCalculatePathItems ) {
if ( calculatePathItem == null ) {
if (mCalculatePathItems != null && !mCalculatePathItems.isEmpty()) {
for (CalculatePathItem calculatePathItem : mCalculatePathItems) {
if (calculatePathItem == null) {
continue;
}
RouteOverLayWrapper wrapper = calculatePathItem.getOverLazWrapper( false );
if ( wrapper != null ) {
RouteOverLayWrapper wrapper = calculatePathItem.getOverLazWrapper(false);
if (wrapper != null) {
wrapper.destroy();
}
}
mCalculatePathItems.clear();
}
if ( mPaths != null ) {
if (mPaths != null) {
mPaths.clear();
}
}
@@ -187,68 +192,67 @@ public class NaviOverlayHelper implements OnCalculatePathItemClickInteraction {
* 是否切换成功
*
* @param polyline 选中的线
* @return
*/
public boolean handleClickedPolyline( Polyline polyline, boolean isNaviing ) {
if ( polyline == null ) {
public boolean handleClickedPolyline(Polyline polyline, boolean isNaviing) {
if (polyline == null) {
return false;
}
if ( mPaths != null && !mPaths.isEmpty() ) {
for ( MogoCalculatePath path : mPaths ) {
if ( TextUtils.equals( path.getTagId(), polyline.getId() ) ) {
if ( mLineClickInteraction != null ) {
mLineClickInteraction.onItemClicked( path.getTagId() );
if (mPaths != null && !mPaths.isEmpty()) {
for (MogoCalculatePath path : mPaths) {
if (TextUtils.equals(path.getTagId(), polyline.getId())) {
if (mLineClickInteraction != null) {
mLineClickInteraction.onItemClicked(path.getTagId());
break;
}
}
}
}
return handleClickedPolyline( polyline.getId() );
return handleClickedPolyline(polyline.getId());
}
private boolean handleClickedPolyline( String id ) {
if ( id == null ) {
private boolean handleClickedPolyline(String id) {
if (id == null) {
return false;
}
Logger.i( TAG, "polyline id = " + id );
mSelectedCalculatePathItem = isCalculatePolyline( id );
if ( mSelectedCalculatePathItem == null ) {
Logger.i(TAG, "polyline id = " + id);
mSelectedCalculatePathItem = isCalculatePolyline(id);
if (mSelectedCalculatePathItem == null) {
return false;
}
mSelectedPathId = mSelectedCalculatePathItem.getId();
if ( mCalculatePathItems != null ) {
for ( CalculatePathItem item : mCalculatePathItems ) {
final RouteOverLayWrapper wrapper = item.getOverLazWrapper( false );
if ( wrapper == null ) {
if (mCalculatePathItems != null) {
for (CalculatePathItem item : mCalculatePathItems) {
final RouteOverLayWrapper wrapper = item.getOverLazWrapper(false);
if (wrapper == null) {
continue;
}
wrapper.setTransparency(
item == mSelectedCalculatePathItem
? AMAP_ROUTE_OVERLAY_TRANSPARENCY_SELECTED
: AMAP_ROUTE_OVERLAY_TRANSPARENCY_UNSELECTED
item == mSelectedCalculatePathItem
? AMAP_ROUTE_OVERLAY_TRANSPARENCY_SELECTED
: AMAP_ROUTE_OVERLAY_TRANSPARENCY_UNSELECTED
);
}
}
return true;
}
private CalculatePathItem isCalculatePolyline( String id ) {
private CalculatePathItem isCalculatePolyline(String id) {
CalculatePathItem result = null;
if ( mCalculatePathItems == null || mCalculatePathItems.isEmpty() ) {
if (mCalculatePathItems == null || mCalculatePathItems.isEmpty()) {
return result;
}
for ( CalculatePathItem calculatePathItem : mCalculatePathItems ) {
if ( calculatePathItem == null ) {
for (CalculatePathItem calculatePathItem : mCalculatePathItems) {
if (calculatePathItem == null) {
continue;
}
final RouteOverLayWrapper wrapper = calculatePathItem.getOverLazWrapper( false );
if ( wrapper == null ) {
final RouteOverLayWrapper wrapper = calculatePathItem.getOverLazWrapper(false);
if (wrapper == null) {
continue;
}
if ( wrapper.getTrafficColorfulPolyline() == null ) {
if (wrapper.getTrafficColorfulPolyline() == null) {
continue;
}
if ( TextUtils.equals( wrapper.getTrafficColorfulPolyline().getId(), id ) ) {
if (TextUtils.equals(wrapper.getTrafficColorfulPolyline().getId(), id)) {
result = calculatePathItem;
}
}
@@ -261,67 +265,82 @@ public class NaviOverlayHelper implements OnCalculatePathItemClickInteraction {
/**
* 车辆拐弯时绘制转向箭头
*
* @param naviInfo
*/
public void handleNaviInfoUpdate( NaviInfo naviInfo ) {
if ( mSelectedCalculatePathItem != null ) {
RouteOverLayWrapper wrapper = mSelectedCalculatePathItem.getOverLazWrapper( false );
if ( wrapper != null ) {
wrapper.drawArrow( naviInfo );
public void handleNaviInfoUpdate(NaviInfo naviInfo) {
if (mSelectedCalculatePathItem != null) {
RouteOverLayWrapper wrapper = mSelectedCalculatePathItem.getOverLazWrapper(false);
if (wrapper != null) {
wrapper.drawArrow(naviInfo);
}
}
}
public void handlePassedLocation( AMapNaviLocation location ) {
if ( mSelectedCalculatePathItem != null ) {
RouteOverLayWrapper wrapper = mSelectedCalculatePathItem.getOverLazWrapper( false );
if ( wrapper != null ) {
wrapper.updatePolyline( location );
public void handlePassedLocation(AMapNaviLocation location) {
if (mSelectedCalculatePathItem != null) {
RouteOverLayWrapper wrapper = mSelectedCalculatePathItem.getOverLazWrapper(false);
if (wrapper != null) {
wrapper.updatePolyline(location);
}
}
}
public List< MogoCalculatePath > getCalculateStrategies() {
if ( mCalculatePathItems != null && !mCalculatePathItems.isEmpty() ) {
for ( CalculatePathItem calculatePathItem : mCalculatePathItems ) {
public List<MogoCalculatePath> getCalculateStrategies() {
if (mCalculatePathItems != null && !mCalculatePathItems.isEmpty()) {
for (CalculatePathItem calculatePathItem : mCalculatePathItems) {
MogoCalculatePath path = new MogoCalculatePath();
path.setDistance( calculatePathItem.getDistance() );
path.setPathId( calculatePathItem.getId() );
path.setStrategyName( calculatePathItem.getStrategyName() );
path.setTime( calculatePathItem.getTime() );
path.setTrafficLights( calculatePathItem.getTrafficNumber() );
mPaths.add( path );
final RouteOverLayWrapper wrapper = calculatePathItem.getOverLazWrapper( true );
if ( wrapper == null ) {
path.setDistance(calculatePathItem.getDistance());
path.setPathId(calculatePathItem.getId());
path.setStrategyName(calculatePathItem.getStrategyName());
path.setTime(calculatePathItem.getTime());
List<NaviLatLng> coordList = calculatePathItem.getPath().getCoordList();
ArrayList<MogoLatLng> mogoLatLngs = new ArrayList<>();
for (NaviLatLng latlng : coordList
) {
MogoLatLng mogoLatLng =
new MogoLatLng(latlng.getLatitude(), latlng.getLongitude());
mogoLatLngs.add(mogoLatLng);
}
path.setCoordList(mogoLatLngs);
path.setTrafficLights(calculatePathItem.getTrafficNumber());
mPaths.add(path);
final RouteOverLayWrapper wrapper = calculatePathItem.getOverLazWrapper(true);
if (wrapper == null) {
continue;
}
if ( wrapper.getTrafficColorfulPolyline() == null ) {
if (wrapper.getTrafficColorfulPolyline() == null) {
continue;
}
path.setTagId( wrapper.getTrafficColorfulPolyline().getId() );
path.setTagId(wrapper.getTrafficColorfulPolyline().getId());
}
}
return mPaths;
}
public List<MogoLatLng> getCalculatedPathPos() {
if (mPaths != null && !mPaths.isEmpty()) {
return mPaths.get(0).getCoordList();
}
return null;
}
@Override
public void onItemClicked( String tagId ) {
handleClickedPolyline( tagId );
mAMapNavi.selectRouteId( getSelectedPathId() );
public void onItemClicked(String tagId) {
handleClickedPolyline(tagId);
mAMapNavi.selectRouteId(getSelectedPathId());
}
public OnCalculatePathItemClickInteraction getItemClickInteraction() {
return this;
}
public void setLineClickInteraction( OnCalculatePathItemClickInteraction lineClickInteraction ) {
public void setLineClickInteraction(OnCalculatePathItemClickInteraction lineClickInteraction) {
mLineClickInteraction = lineClickInteraction;
}
public void setCalculatePathDisplayBounds( Rect bounds ) {
if ( bounds != null ) {
public void setCalculatePathDisplayBounds(Rect bounds) {
if (bounds != null) {
mBoundRect = bounds;
}
}

View File

@@ -79,6 +79,17 @@ public interface IMogoNavi {
*/
List< MogoCalculatePath > getCalculatedStrategies();
/**
* 获取路线坐标点
*
* @return 规划的路线上所有的坐标点
*/
List< MogoLatLng > getCalculatedPathPos();
/**
* 获取列表Item点击回调
*

View File

@@ -1,5 +1,8 @@
package com.mogo.map.navi;
import com.mogo.map.MogoLatLng;
import java.util.List;
/**
* @author congtaowang
* @since 2020-01-08
@@ -38,6 +41,17 @@ public class MogoCalculatePath {
*/
private int mPathId;
private List<MogoLatLng> coordList;
public List<MogoLatLng> getCoordList() {
return coordList;
}
public void setCoordList(List<MogoLatLng> coordList) {
this.coordList = coordList;
}
public MogoCalculatePath() {
}

View File

@@ -107,6 +107,13 @@ public class MogoNavi implements IMogoNavi {
return null;
}
@Override public List<MogoLatLng> getCalculatedPathPos() {
if (mDelegate != null) {
return mDelegate.getCalculatedPathPos();
}
return null;
}
@Override
public OnCalculatePathItemClickInteraction getItemClickInteraction() {
if (mDelegate != null) {