diff --git a/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/navi/AMapNaviListenerAdapter.java b/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/navi/AMapNaviListenerAdapter.java index f870148573..8584b96289 100644 --- a/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/navi/AMapNaviListenerAdapter.java +++ b/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/navi/AMapNaviListenerAdapter.java @@ -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 ) { } + + } diff --git a/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/navi/CalculatePathItem.java b/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/navi/CalculatePathItem.java index a89996465e..83a63aa0ec 100644 --- a/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/navi/CalculatePathItem.java +++ b/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/navi/CalculatePathItem.java @@ -94,6 +94,8 @@ public class CalculatePathItem { return mDistanceCacheStr; } + + private StringBuilder mDescBuilder = null; public String getDesc() { diff --git a/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/navi/NaviClient.java b/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/navi/NaviClient.java index 52d98b5d51..04ae2cb8c0 100644 --- a/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/navi/NaviClient.java +++ b/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/navi/NaviClient.java @@ -162,6 +162,13 @@ public class NaviClient implements IMogoNavi { return null; } + @Override public List getCalculatedPathPos() { + if ( mAMapNaviListener != null ) { + return mAMapNaviListener.getCalculatedPathPos(); + } + return null; + } + @Override public OnCalculatePathItemClickInteraction getItemClickInteraction() { if ( mAMapNaviListener != null ) { diff --git a/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/navi/NaviListenerAdapter.java b/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/navi/NaviListenerAdapter.java index 572380b7d1..58178239a4 100644 --- a/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/navi/NaviListenerAdapter.java +++ b/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/navi/NaviListenerAdapter.java @@ -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 getCalculatedPathPos() { + if ( mNaviOverlayHelper != null ) { + return mNaviOverlayHelper.getCalculatedPathPos(); + } + return null; + } + + + + public OnCalculatePathItemClickInteraction getItemClickInteraction() { if ( mNaviOverlayHelper != null ) { return mNaviOverlayHelper.getItemClickInteraction(); diff --git a/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/navi/NaviOverlayHelper.java b/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/navi/NaviOverlayHelper.java index a8ef6433d6..ea00c257a0 100644 --- a/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/navi/NaviOverlayHelper.java +++ b/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/navi/NaviOverlayHelper.java @@ -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 mCalculatePathItems; + private List 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 getSortedPaths() { checkAMapInstance(); - final Map< Integer, AMapNaviPath > pathMap = mAMapNavi.getNaviPaths(); - if ( pathMap == null || pathMap.isEmpty() ) { + final Map 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 sortedMap = + new TreeMap(new Comparator() { + @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 items = new ArrayList<>(); + for (Map.Entry 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 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 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 coordList = calculatePathItem.getPath().getCoordList(); + ArrayList 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 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; } } diff --git a/libraries/mogo-map-api/src/main/java/com/mogo/map/navi/IMogoNavi.java b/libraries/mogo-map-api/src/main/java/com/mogo/map/navi/IMogoNavi.java index ed0d6819fc..005f123135 100644 --- a/libraries/mogo-map-api/src/main/java/com/mogo/map/navi/IMogoNavi.java +++ b/libraries/mogo-map-api/src/main/java/com/mogo/map/navi/IMogoNavi.java @@ -79,6 +79,17 @@ public interface IMogoNavi { */ List< MogoCalculatePath > getCalculatedStrategies(); + + + /** + * 获取路线坐标点 + * + * @return 规划的路线上所有的坐标点 + */ + List< MogoLatLng > getCalculatedPathPos(); + + + /** * 获取列表Item点击回调 * diff --git a/libraries/mogo-map-api/src/main/java/com/mogo/map/navi/MogoCalculatePath.java b/libraries/mogo-map-api/src/main/java/com/mogo/map/navi/MogoCalculatePath.java index 5c26ec925b..e3d8b3be98 100644 --- a/libraries/mogo-map-api/src/main/java/com/mogo/map/navi/MogoCalculatePath.java +++ b/libraries/mogo-map-api/src/main/java/com/mogo/map/navi/MogoCalculatePath.java @@ -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 coordList; + + public List getCoordList() { + return coordList; + } + + public void setCoordList(List coordList) { + this.coordList = coordList; + } + public MogoCalculatePath() { } diff --git a/libraries/mogo-map/src/main/java/com/mogo/map/MogoNavi.java b/libraries/mogo-map/src/main/java/com/mogo/map/MogoNavi.java index 97664d9dcd..8aaac07801 100644 --- a/libraries/mogo-map/src/main/java/com/mogo/map/MogoNavi.java +++ b/libraries/mogo-map/src/main/java/com/mogo/map/MogoNavi.java @@ -107,6 +107,13 @@ public class MogoNavi implements IMogoNavi { return null; } + @Override public List getCalculatedPathPos() { + if (mDelegate != null) { + return mDelegate.getCalculatedPathPos(); + } + return null; + } + @Override public OnCalculatePathItemClickInteraction getItemClickInteraction() { if (mDelegate != null) {