自定义路线纹理,模拟数据

This commit is contained in:
liujing
2022-06-21 23:33:18 +08:00
parent 812d6e0437
commit 625987a19b

View File

@@ -39,6 +39,7 @@ import com.amap.api.navi.AMapNaviViewListener;
import com.amap.api.navi.AMapNaviViewOptions;
import com.amap.api.navi.ParallelRoadListener;
import com.amap.api.navi.enums.AMapNaviParallelRoadStatus;
import com.amap.api.navi.enums.NaviType;
import com.amap.api.navi.model.AMapCalcRouteResult;
import com.amap.api.navi.model.AMapLaneInfo;
import com.amap.api.navi.model.AMapModelCross;
@@ -80,7 +81,7 @@ import java.util.List;
*/
public class SmallMapDirectionView
extends RelativeLayout
implements IMoGoMapLocationListener, ISmallMapDirectionView, AMapNaviListener {
implements IMoGoMapLocationListener, ISmallMapDirectionView, AMapNaviListener, AMapNaviViewListener {
//小地图名称
public static final String TAG = "SmallMapDirectionView";
@@ -142,12 +143,13 @@ public class SmallMapDirectionView
mWayPointList.add(new NaviLatLng(26.81931096, 112.57279149));
View smpView = LayoutInflater.from(context).inflate(R.layout.module_small_map_view, this);
mAMapNaviView = smpView.findViewById(R.id.aMapNaviView);
overLayerView = findViewById(R.id.overLayer);
mAMapNavi = AMapNavi.getInstance(context);
mAMapNavi.setUseInnerVoice(true, true);
// mAMapNavi.setUseInnerVoice(true, true);
mAMapNavi.addAMapNaviListener(this);
mAMapNaviView.setAMapNaviViewListener(this);
// rlSmallMapBorder = findViewById(R.id.rlSmallMapBorder);
// rlSmallMapBorder.addView(mAMapNaviView);
initAMapView(context);
@@ -194,8 +196,6 @@ public class SmallMapDirectionView
AMapNaviViewOptions options = mAMapNaviView.getViewOptions();
//不显示导航界面
options.setLayoutVisible(false);
//打开走过的路段自定义
options.setAfterRouteAutoGray(true);
//黑夜模式
options.setNaviNight(true);
//导航全程光柱
@@ -207,11 +207,21 @@ public class SmallMapDirectionView
//自车车标
options.setCarBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.module_small_map_view_my_location_logo));
options.setFourCornersBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.module_small_map_view_border_north));
// options.setStartPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.module_small_map_view_dir_start));
//options.setWayPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.navi_way));
// options.setEndPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.module_small_map_view_dir_end));
mAMapNaviView.setViewOptions(options);
options.setStartPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.module_small_map_view_dir_start));
// options.setWayPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.navi_way));
options.setEndPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.module_small_map_view_dir_end));
options.setAfterRouteAutoGray(true);
RouteOverlayOptions routeOverlayOptions = new RouteOverlayOptions();
routeOverlayOptions.setSmoothTraffic(BitmapFactory.decodeResource(getResources(), R.drawable.module_small_map_view_dir_pass_route));
routeOverlayOptions.setPassRoute(BitmapFactory.decodeResource(getResources(), R.drawable.custtexture_slow));//走过的路段
//打开走过的路段自定义
if (routeOverlayOptions != null) {
Log.d(TAG, "routeOverlayOptions != null");
}
options.setRouteOverlayOptions(routeOverlayOptions);
mAMapNaviView.setViewOptions(options);
// 设置自定义样式
// mAMap.setCustomMapStyle(customMapStyleOptions);
@@ -262,6 +272,7 @@ public class SmallMapDirectionView
@Override
public void onLocationChanged(@org.jetbrains.annotations.Nullable MogoLocation location, int from) {
Log.d(TAG, "onLocationChanged location:" + location.toString());
if (location == null) {
return;
}
@@ -476,6 +487,7 @@ public class SmallMapDirectionView
mCoordinatesLatLng.addAll(latLngs);
}
//多路径算路成功回调
@Override
public void onCalculateRouteSuccess(int[] ints) {
Log.d(TAG, "onCalculateRouteSuccess int");
@@ -485,39 +497,37 @@ public class SmallMapDirectionView
if (routeOverLay == null) {
Log.d(TAG, "routeOverLay == null");
// 初始化路线参数
routeOverLay = new RouteOverLay(mAMapNaviView.getMap(), naviPath, mContext);
routeOverLay.setWayPointBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.icon_module_small_map_four_corners));
routeOverLay.setEndPointBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.module_small_map_view_dir_end));
routeOverLay.setStartPointBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.module_small_map_view_dir_start));
// routeOverLay = new RouteOverLay(mAMapNaviView.getMap(), naviPath, mContext);
// routeOverLay.setWayPointBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.icon_module_small_map_four_corners));
// routeOverLay.setEndPointBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.module_small_map_view_dir_end));
// routeOverLay.setStartPointBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.module_small_map_view_dir_start));
//自定义样式
RouteOverlayOptions routeOverlayOptions = new RouteOverlayOptions();
// RouteOverlayOptions routeOverlayOptions = new RouteOverlayOptions();
//驶过路段擦除
routeOverlayOptions.setPassRoute(BitmapFactory.decodeResource(getResources(), R.drawable.module_small_map_view_dir_pass_route));
routeOverlayOptions.setSmoothTraffic(BitmapFactory.decodeResource(getResources(), R.drawable.custtexture_green));//通畅路段
routeOverlayOptions.setSlowTraffic(BitmapFactory.decodeResource(getResources(), R.drawable.custtexture_slow));//缓慢路段
routeOverlayOptions.setJamTraffic(BitmapFactory.decodeResource(getResources(), R.drawable.custtexture_bad));//拥堵路段
routeOverlayOptions.setVeryJamTraffic(BitmapFactory.decodeResource(getResources(), R.drawable.custtexture_grayred));//超级拥堵路段
routeOverLay.setRouteOverlayOptions(routeOverlayOptions);
}
if (routeOverLay != null) {
Log.d(TAG, "routeOverLay != null");
routeOverLay.setAMapNaviPath(naviPath);
routeOverLay.addToMap();
// routeOverlayOptions.setPassRoute(BitmapFactory.decodeResource(getResources(), R.drawable.module_small_map_view_dir_pass_route));
// routeOverlayOptions.setSmoothTraffic(BitmapFactory.decodeResource(getResources(), R.drawable.custtexture_slow));//通畅路段
// routeOverLay.setRouteOverlayOptions(routeOverlayOptions);
}
// if (routeOverLay != null) {
// Log.d(TAG, "routeOverLay != null");
// routeOverLay.setAMapNaviPath(naviPath);
// routeOverLay.addToMap();
// }
float bearing = NaviUtil.getRotate(mStartLatlng, naviPath.getCoordList().get(1));
if (mStartLatlng != null) {
Log.d(TAG, "mStartLatlng != null");
carOverlay.reset();
/**
* 绘制自车位置
*/
carOverlay.draw(mAMapNaviView.getMap(), new LatLng(mStartLatlng.getLatitude(), mStartLatlng.getLongitude()), bearing);
if (naviPath.getEndPoint() != null) {
LatLng latlng = new LatLng(naviPath.getEndPoint().getLatitude(), naviPath.getEndPoint().getLongitude());
carOverlay.setEndPoi(latlng);
}
}
// if (mStartLatlng != null) {
// Log.d(TAG, "mStartLatlng != null");
// carOverlay.reset();
// /**
// * 绘制自车位置
// */
// carOverlay.draw(mAMapNaviView.getMap(), new LatLng(mStartLatlng.getLatitude(), mStartLatlng.getLongitude()), bearing);
// if (naviPath.getEndPoint() != null) {
// LatLng latlng = new LatLng(naviPath.getEndPoint().getLatitude(), naviPath.getEndPoint().getLongitude());
// carOverlay.setEndPoi(latlng);
// }
// }
// mAMapNavi.startNavi(NaviType.EMULATOR);
}
}
@@ -546,7 +556,7 @@ public class SmallMapDirectionView
@Override
public void onLocationChange(AMapNaviLocation aMapNaviLocation) {
Log.d(TAG, "onLocationChange");
Log.d(TAG, "高德地图:onLocationChange");
}
@Override
@@ -690,9 +700,11 @@ public class SmallMapDirectionView
}
//算路详情
@Override
public void onCalculateRouteSuccess(AMapCalcRouteResult aMapCalcRouteResult) {
Log.d(TAG, "onCalculateRouteSuccess aMapCalcRouteResult" + aMapCalcRouteResult.toString());
mAMapNavi.startNavi(NaviType.EMULATOR);
}
@Override
@@ -704,4 +716,59 @@ public class SmallMapDirectionView
public void onNaviRouteNotify(AMapNaviRouteNotifyData aMapNaviRouteNotifyData) {
Log.d(TAG, "onNaviRouteNotify");
}
@Override
public void onNaviSetting() {
}
@Override
public void onNaviCancel() {
}
@Override
public boolean onNaviBackClick() {
return false;
}
@Override
public void onNaviMapMode(int i) {
}
@Override
public void onNaviTurnClick() {
}
@Override
public void onNextRoadClick() {
}
@Override
public void onScanViewButtonClick() {
}
@Override
public void onLockMap(boolean b) {
}
@Override
public void onNaviViewLoaded() {
}
@Override
public void onMapTypeChanged(int i) {
}
@Override
public void onNaviViewShowMode(int i) {
}
}