Merge remote-tracking branch 'origin/feature/v1.0.0' into feature/v1.0.0
This commit is contained in:
@@ -8,6 +8,7 @@ import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.module.common.MogoModule;
|
||||
import com.mogo.module.common.MogoModulePaths;
|
||||
import com.mogo.module.onlinecar.OnLineCarConstants;
|
||||
import com.mogo.tanlu.constant.TanluConstants;
|
||||
|
||||
/**
|
||||
@@ -24,8 +25,8 @@ public class MogoApplication extends AbsMogoApplication {
|
||||
// MogoModulePaths.addModule( new MogoModule( DemoConstants.TAG, "CARD_DEMO" ) );
|
||||
// MogoModulePaths.addModule( new MogoModule( Demo2Constants.TAG, "CARD_DEMO2" ) );
|
||||
DebugConfig.setNetMode( DebugConfig.NET_MODE_QA );
|
||||
MogoModulePaths.addModule(new MogoModule(OnLineCarConstants.TAG, "CARD_TYPE_ROAD_ONLINECAR"));
|
||||
MogoModulePaths.addModule( new MogoModule( TanluConstants.TAG, "CARD_TYPE_ROAD_CODITION" ) );
|
||||
// MogoModulePaths.addModule(new MogoModule(OnLineCarConstants.TAG, "CARD_TYPE_ROAD_ONLINECAR"));
|
||||
// MogoModulePaths.addModule(new MogoModule( CallChatConstant.PROVIDER, CallChatConstant.MODULE_NAME));
|
||||
}
|
||||
|
||||
|
||||
@@ -95,6 +95,7 @@ ext {
|
||||
mogoconnection : "com.mogo.connection:mogo-connection:${MOGO_CONNECTION_VERSION}",
|
||||
moduleextensions : "com.mogo.module:module-extensions:${MOGO_MODULE_EXTENSIONS_VERSION}",
|
||||
modulechatting : "com.mogo.module.carchatting:module-carchatting:${CARCHATTING_VERSION}",
|
||||
// 在线车辆
|
||||
moduleonlinecar : "com.mogo.module:module-onlinecar:${MOGO_MODULE_ONLINECAR_VERSION}",
|
||||
|
||||
// 长链
|
||||
|
||||
@@ -3,15 +3,25 @@ package com.mogo.module.service;
|
||||
import android.content.Context;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||
import com.mogo.map.marker.IMogoMarkerManager;
|
||||
import com.mogo.map.marker.MogoMarkerOptions;
|
||||
import com.mogo.map.navi.IMogoNavi;
|
||||
import com.mogo.map.uicontroller.IMogoMapUIController;
|
||||
import com.mogo.module.service.entity.MarkerResponse;
|
||||
import com.mogo.module.service.marker.MapMarkerView;
|
||||
import com.mogo.module.service.marker.MarkerInfoWindowAdapter;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.connection.IMogoOnMessageListener;
|
||||
import com.mogo.service.connection.IMogoSocketManager;
|
||||
import com.mogo.service.imageloader.IMogoImageloader;
|
||||
import com.mogo.service.map.IMogoMapService;
|
||||
import com.mogo.utils.TipToast;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* author : donghongyu
|
||||
* e-mail : 1358506549@qq.com
|
||||
@@ -20,17 +30,34 @@ import com.mogo.utils.logger.Logger;
|
||||
* version: 1.0
|
||||
*/
|
||||
public class MarkerServiceHandler {
|
||||
private static final String TAG = "MarkerServiceHandler";
|
||||
|
||||
private static MogoMarkerClickListener mogoMarkerClickListener;
|
||||
|
||||
private static IMogoMapService mMapService;
|
||||
private static IMogoMarkerManager mMarkerManager;
|
||||
private static IMogoNavi mNavi;
|
||||
private static IMogoMapUIController mMapUIController;
|
||||
|
||||
private static IMogoImageloader mImageloader;
|
||||
private static IMogoSocketManager mMogoSocketManager;
|
||||
private static MarkerInfoWindowAdapter markerInfoWindowAdapter;
|
||||
|
||||
public static void init(Context context) {
|
||||
private static Context mContext;
|
||||
|
||||
public static void init(final Context context) {
|
||||
mContext = context;
|
||||
mMapService = (IMogoMapService) ARouter.getInstance().build(MogoServicePaths.PATH_SERVICES_MAP).navigation(context);
|
||||
mImageloader = (IMogoImageloader) ARouter.getInstance().build(MogoServicePaths.PATH_UTILS_IMAGE_LOADER).navigation(context);
|
||||
mMarkerManager = mMapService.getMarkerManager(context);
|
||||
mNavi = mMapService.getNavi(context);
|
||||
markerInfoWindowAdapter = new MarkerInfoWindowAdapter(context, getNavi(), getImageloader());
|
||||
mMapUIController = mMapService.getMapUIController();
|
||||
|
||||
|
||||
mogoMarkerClickListener = new MogoMarkerClickListener();
|
||||
|
||||
// 长连接
|
||||
mMogoSocketManager = (IMogoSocketManager) ARouter.getInstance().build(MogoServicePaths.PATH_SOCKET_MANAGER).navigation();
|
||||
mMogoSocketManager.registerOnMessageListener(401001, new IMogoOnMessageListener<MarkerResponse>() {
|
||||
|
||||
@@ -42,6 +69,10 @@ public class MarkerServiceHandler {
|
||||
@Override
|
||||
public void onMsgReceived(MarkerResponse obj) {
|
||||
Logger.e("donghongyu", "===" + obj);
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
drawMapMarker();
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
@@ -55,6 +86,14 @@ public class MarkerServiceHandler {
|
||||
return mMarkerManager;
|
||||
}
|
||||
|
||||
public static IMogoNavi getNavi() {
|
||||
return mNavi;
|
||||
}
|
||||
|
||||
public static IMogoMapUIController getMapUIController() {
|
||||
return mMapUIController;
|
||||
}
|
||||
|
||||
public static IMogoImageloader getImageloader() {
|
||||
return mImageloader;
|
||||
}
|
||||
@@ -63,4 +102,35 @@ public class MarkerServiceHandler {
|
||||
return mMogoSocketManager;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 地图上的Marker点击回调
|
||||
*/
|
||||
static class MogoMarkerClickListener implements IMogoMarkerClickListener {
|
||||
|
||||
@Override
|
||||
public boolean onMarkerClicked(IMogoMarker marker) {
|
||||
TipToast.shortTip("点击了大而全中的Marker");
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void drawMapMarker() {
|
||||
TipToast.shortTip("绘制Marker");
|
||||
|
||||
MapMarkerView mapMarkerView = new MapMarkerView(mContext);
|
||||
|
||||
MogoMarkerOptions options = new MogoMarkerOptions()
|
||||
.icon(mapMarkerView)
|
||||
.owner(TAG)
|
||||
.latitude(39.574525d + new Random().nextDouble())
|
||||
.longitude(116.21733d + new Random().nextDouble());
|
||||
IMogoMarker marker = getMarkerManager().addMarker(TAG, options);
|
||||
marker.setInfoWindowAdapter(markerInfoWindowAdapter);
|
||||
marker.setOnMarkerClickListener(mogoMarkerClickListener);
|
||||
|
||||
getMapUIController().changeZoom(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.view.LayoutInflater;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
import com.mogo.module.service.R;
|
||||
|
||||
@@ -16,7 +17,7 @@ import com.mogo.module.service.R;
|
||||
* desc : 地图Marker图标带文本信息
|
||||
* version: 1.0
|
||||
*/
|
||||
public class MapMarkerInfoView extends LinearLayout {
|
||||
public class MapMarkerInfoView extends ConstraintLayout {
|
||||
public MapMarkerInfoView(Context context) {
|
||||
super(context);
|
||||
initView(context);
|
||||
|
||||
@@ -3,9 +3,9 @@ package com.mogo.module.service.marker;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
import com.mogo.module.service.R;
|
||||
|
||||
@@ -16,7 +16,7 @@ import com.mogo.module.service.R;
|
||||
* desc : 地图Marker图标
|
||||
* version: 1.0
|
||||
*/
|
||||
public class MapMarkerView extends LinearLayout {
|
||||
public class MapMarkerView extends ConstraintLayout {
|
||||
public MapMarkerView(Context context) {
|
||||
super(context);
|
||||
initView(context);
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.mogo.module.service.marker;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.View;
|
||||
|
||||
import com.mogo.map.marker.IMogoInfoWindowAdapter;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.navi.IMogoNavi;
|
||||
import com.mogo.service.imageloader.IMogoImageloader;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
|
||||
/**
|
||||
* author : donghongyu
|
||||
* e-mail : 1358506549@qq.com
|
||||
* date : 2020-01-0818:11
|
||||
* desc :
|
||||
* version: 1.0
|
||||
*/
|
||||
public class MarkerInfoWindowAdapter implements IMogoInfoWindowAdapter {
|
||||
|
||||
private static final String TAG = "MarkerInfoWindowAdapter";
|
||||
|
||||
private Context mContext;
|
||||
private IMogoNavi mNavi;
|
||||
private IMogoImageloader mImageloader;
|
||||
|
||||
public MarkerInfoWindowAdapter(Context mContext, IMogoNavi mNavi, IMogoImageloader iMogoImageloader) {
|
||||
this.mContext = mContext;
|
||||
this.mNavi = mNavi;
|
||||
this.mImageloader = iMogoImageloader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getInfoWindow(IMogoMarker marker) {
|
||||
Logger.e(TAG,"getInfoWindow====");
|
||||
MapMarkerInfoView mapMarkerInfoView = new MapMarkerInfoView(mContext);
|
||||
return mapMarkerInfoView;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 3.0 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 902 B |
@@ -12,6 +12,4 @@
|
||||
</shape >
|
||||
</rotate >
|
||||
</item >
|
||||
|
||||
|
||||
</layer-list >
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" >
|
||||
android:orientation="vertical"
|
||||
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivBg"
|
||||
@@ -11,7 +13,6 @@
|
||||
android:layout_height="@dimen/dp_105"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/bg_map_marker_blue"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
@@ -27,4 +28,14 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivCar"
|
||||
android:layout_width="@dimen/dp_34"
|
||||
android:layout_height="@dimen/dp_64"
|
||||
android:rotation="270"
|
||||
android:src="@drawable/icon_map_marker_car_blue"
|
||||
app:layout_constraintEnd_toEndOf="@+id/ivBg"
|
||||
app:layout_constraintStart_toStartOf="@+id/ivBg"
|
||||
app:layout_constraintTop_toBottomOf="@+id/ivBg" />
|
||||
</merge >
|
||||
@@ -1,32 +1,66 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal" >
|
||||
android:orientation="horizontal"
|
||||
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvMarkerContent"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/llMarkerContent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="@dimen/dp_94"
|
||||
android:background="@drawable/bg_map_marker_blue_info"
|
||||
android:drawableLeft="@drawable/icon_default"
|
||||
android:drawablePadding="@dimen/dp_20"
|
||||
android:gravity="center"
|
||||
android:text="诗一样的女子"
|
||||
android:textColor="#ffffff"
|
||||
android:textSize="@dimen/sp_32"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
app:layout_constraintTop_toTopOf="parent" >
|
||||
|
||||
<com.mogo.service.imageloader.MogoImageView
|
||||
android:id="@+id/ivUserHead"
|
||||
android:layout_width="@dimen/dp_80"
|
||||
android:layout_height="@dimen/dp_80"
|
||||
android:background="@drawable/icon_default"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:miv_failureHolder="@drawable/icon_default"
|
||||
app:miv_overlayImageId="@drawable/icon_default"
|
||||
app:miv_placeHolder="@drawable/icon_default"
|
||||
app:miv_shape="circle" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvMarkerContent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/dp_20"
|
||||
android:gravity="center"
|
||||
android:text="诗一样的女子"
|
||||
android:textColor="#ffffff"
|
||||
android:textSize="@dimen/sp_32"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/ivUserHead"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/ivUserHead"
|
||||
app:layout_constraintTop_toTopOf="@+id/ivUserHead" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout >
|
||||
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivReverseTriangle"
|
||||
android:layout_width="27dp"
|
||||
android:layout_height="15dp"
|
||||
android:layout_width="10dp"
|
||||
android:layout_height="10dp"
|
||||
android:src="@drawable/bg_shape_reverse_triangle_blue"
|
||||
app:layout_constraintEnd_toEndOf="@+id/tvMarkerContent"
|
||||
app:layout_constraintStart_toStartOf="@+id/tvMarkerContent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tvMarkerContent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout >
|
||||
app:layout_constraintEnd_toEndOf="@+id/llMarkerContent"
|
||||
app:layout_constraintStart_toStartOf="@+id/llMarkerContent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/llMarkerContent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivCar"
|
||||
android:layout_width="@dimen/dp_34"
|
||||
android:layout_height="@dimen/dp_64"
|
||||
android:rotation="270"
|
||||
android:src="@drawable/icon_map_marker_car_blue"
|
||||
app:layout_constraintEnd_toEndOf="@+id/ivReverseTriangle"
|
||||
app:layout_constraintStart_toStartOf="@+id/ivReverseTriangle"
|
||||
app:layout_constraintTop_toBottomOf="@+id/ivReverseTriangle" />
|
||||
</merge >
|
||||
268
modules/mogo-module-tanlu/src/main/java/com/mogo/tanlu/map/AMapUtil.java
Executable file
268
modules/mogo-module-tanlu/src/main/java/com/mogo/tanlu/map/AMapUtil.java
Executable file
@@ -0,0 +1,268 @@
|
||||
package com.mogo.tanlu.map;
|
||||
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.widget.EditText;
|
||||
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.amap.api.services.core.LatLonPoint;
|
||||
import com.amap.api.services.route.BusPath;
|
||||
import com.amap.api.services.route.BusStep;
|
||||
import com.amap.api.services.route.RouteBusLineItem;
|
||||
import com.amap.api.services.route.RouteRailwayItem;
|
||||
import com.mogo.tanlu.R;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class AMapUtil {
|
||||
/**
|
||||
* 判断edittext是否null
|
||||
*/
|
||||
public static String checkEditText(EditText editText) {
|
||||
if (editText != null && editText.getText() != null
|
||||
&& !(editText.getText().toString().trim().equals(""))) {
|
||||
return editText.getText().toString().trim();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static Spanned stringToSpan(String src) {
|
||||
return src == null ? null : Html.fromHtml(src.replace("\n", "<br />"));
|
||||
}
|
||||
|
||||
public static String colorFont(String src, String color) {
|
||||
StringBuffer strBuf = new StringBuffer();
|
||||
|
||||
strBuf.append("<font color=").append(color).append(">").append(src)
|
||||
.append("</font>");
|
||||
return strBuf.toString();
|
||||
}
|
||||
|
||||
public static String makeHtmlNewLine() {
|
||||
return "<br />";
|
||||
}
|
||||
|
||||
public static String makeHtmlSpace(int number) {
|
||||
final String space = " ";
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int i = 0; i < number; i++) {
|
||||
result.append(space);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static String getFriendlyLength(int lenMeter) {
|
||||
if (lenMeter > 10000) // 10 km
|
||||
{
|
||||
int dis = lenMeter / 1000;
|
||||
return dis + ChString.Kilometer;
|
||||
}
|
||||
|
||||
if (lenMeter > 1000) {
|
||||
float dis = (float) lenMeter / 1000;
|
||||
DecimalFormat fnum = new DecimalFormat("##0.0");
|
||||
String dstr = fnum.format(dis);
|
||||
return dstr + ChString.Kilometer;
|
||||
}
|
||||
|
||||
if (lenMeter > 100) {
|
||||
int dis = lenMeter / 50 * 50;
|
||||
return dis + ChString.Meter;
|
||||
}
|
||||
|
||||
int dis = lenMeter / 10 * 10;
|
||||
if (dis == 0) {
|
||||
dis = 10;
|
||||
}
|
||||
|
||||
return dis + ChString.Meter;
|
||||
}
|
||||
|
||||
public static boolean IsEmptyOrNullString(String s) {
|
||||
return (s == null) || (s.trim().length() == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把LatLng对象转化为LatLonPoint对象
|
||||
*/
|
||||
public static LatLonPoint convertToLatLonPoint(LatLng latlon) {
|
||||
return new LatLonPoint(latlon.latitude, latlon.longitude);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把LatLonPoint对象转化为LatLon对象
|
||||
*/
|
||||
public static LatLng convertToLatLng(LatLonPoint latLonPoint) {
|
||||
return new LatLng(latLonPoint.getLatitude(), latLonPoint.getLongitude());
|
||||
}
|
||||
|
||||
/**
|
||||
* 把集合体的LatLonPoint转化为集合体的LatLng
|
||||
*/
|
||||
public static ArrayList<LatLng> convertArrList(List<LatLonPoint> shapes) {
|
||||
ArrayList<LatLng> lineShapes = new ArrayList<LatLng>();
|
||||
for (LatLonPoint point : shapes) {
|
||||
LatLng latLngTemp = AMapUtil.convertToLatLng(point);
|
||||
lineShapes.add(latLngTemp);
|
||||
}
|
||||
return lineShapes;
|
||||
}
|
||||
|
||||
/**
|
||||
* long类型时间格式化
|
||||
*/
|
||||
public static String convertToTime(long time) {
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Date date = new Date(time);
|
||||
return df.format(date);
|
||||
}
|
||||
|
||||
public static final String HtmlBlack = "#000000";
|
||||
public static final String HtmlGray = "#808080";
|
||||
|
||||
public static String getFriendlyTime(int second) {
|
||||
if (second > 3600) {
|
||||
int hour = second / 3600;
|
||||
int miniate = (second % 3600) / 60;
|
||||
return hour + "小时" + miniate + "分钟";
|
||||
}
|
||||
if (second >= 60) {
|
||||
int miniate = second / 60;
|
||||
return miniate + "分钟";
|
||||
}
|
||||
return second + "秒";
|
||||
}
|
||||
|
||||
//路径规划方向指示和图片对应
|
||||
public static int getDriveActionID(String actionName) {
|
||||
if (actionName == null || actionName.equals("")) {
|
||||
return R.drawable.dir3;
|
||||
}
|
||||
if ("左转".equals(actionName)) {
|
||||
return R.drawable.dir2;
|
||||
}
|
||||
if ("右转".equals(actionName)) {
|
||||
return R.drawable.dir1;
|
||||
}
|
||||
if ("向左前方行驶".equals(actionName) || "靠左".equals(actionName)) {
|
||||
return R.drawable.dir6;
|
||||
}
|
||||
if ("向右前方行驶".equals(actionName) || "靠右".equals(actionName)) {
|
||||
return R.drawable.dir5;
|
||||
}
|
||||
if ("向左后方行驶".equals(actionName) || "左转调头".equals(actionName)) {
|
||||
return R.drawable.dir7;
|
||||
}
|
||||
if ("向右后方行驶".equals(actionName)) {
|
||||
return R.drawable.dir8;
|
||||
}
|
||||
if ("直行".equals(actionName)) {
|
||||
return R.drawable.dir3;
|
||||
}
|
||||
if ("减速行驶".equals(actionName)) {
|
||||
return R.drawable.dir4;
|
||||
}
|
||||
return R.drawable.dir3;
|
||||
}
|
||||
|
||||
public static int getWalkActionID(String actionName) {
|
||||
if (actionName == null || actionName.equals("")) {
|
||||
return R.drawable.dir13;
|
||||
}
|
||||
if ("左转".equals(actionName)) {
|
||||
return R.drawable.dir2;
|
||||
}
|
||||
if ("右转".equals(actionName)) {
|
||||
return R.drawable.dir1;
|
||||
}
|
||||
if ("向左前方".equals(actionName) || "靠左".equals(actionName) || actionName.contains("向左前方")) {
|
||||
return R.drawable.dir6;
|
||||
}
|
||||
if ("向右前方".equals(actionName) || "靠右".equals(actionName) || actionName.contains("向右前方")) {
|
||||
return R.drawable.dir5;
|
||||
}
|
||||
if ("向左后方".equals(actionName) || actionName.contains("向左后方")) {
|
||||
return R.drawable.dir7;
|
||||
}
|
||||
if ("向右后方".equals(actionName) || actionName.contains("向右后方")) {
|
||||
return R.drawable.dir8;
|
||||
}
|
||||
if ("直行".equals(actionName)) {
|
||||
return R.drawable.dir3;
|
||||
}
|
||||
if ("通过人行横道".equals(actionName)) {
|
||||
return R.drawable.dir9;
|
||||
}
|
||||
if ("通过过街天桥".equals(actionName)) {
|
||||
return R.drawable.dir11;
|
||||
}
|
||||
if ("通过地下通道".equals(actionName)) {
|
||||
return R.drawable.dir10;
|
||||
}
|
||||
|
||||
return R.drawable.dir13;
|
||||
}
|
||||
|
||||
public static String getBusPathTitle(BusPath busPath) {
|
||||
if (busPath == null) {
|
||||
return String.valueOf("");
|
||||
}
|
||||
List<BusStep> busSetps = busPath.getSteps();
|
||||
if (busSetps == null) {
|
||||
return String.valueOf("");
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (BusStep busStep : busSetps) {
|
||||
StringBuffer title = new StringBuffer();
|
||||
if (busStep.getBusLines().size() > 0) {
|
||||
for (RouteBusLineItem busline : busStep.getBusLines()) {
|
||||
if (busline == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String buslineName = getSimpleBusLineName(busline.getBusLineName());
|
||||
title.append(buslineName);
|
||||
title.append(" / ");
|
||||
}
|
||||
// RouteBusLineItem busline = busStep.getBusLines().get(0);
|
||||
|
||||
sb.append(title.substring(0, title.length() - 3));
|
||||
sb.append(" > ");
|
||||
}
|
||||
if (busStep.getRailway() != null) {
|
||||
RouteRailwayItem railway = busStep.getRailway();
|
||||
sb.append(railway.getTrip() + "(" + railway.getDeparturestop().getName()
|
||||
+ " - " + railway.getArrivalstop().getName() + ")");
|
||||
sb.append(" > ");
|
||||
}
|
||||
}
|
||||
return sb.substring(0, sb.length() - 3);
|
||||
}
|
||||
|
||||
public static String getBusPathDes(BusPath busPath) {
|
||||
if (busPath == null) {
|
||||
return String.valueOf("");
|
||||
}
|
||||
long second = busPath.getDuration();
|
||||
String time = getFriendlyTime((int) second);
|
||||
float subDistance = busPath.getDistance();
|
||||
String subDis = getFriendlyLength((int) subDistance);
|
||||
float walkDistance = busPath.getWalkDistance();
|
||||
String walkDis = getFriendlyLength((int) walkDistance);
|
||||
return String.valueOf(time + " | " + subDis + " | 步行" + walkDis);
|
||||
}
|
||||
|
||||
public static String getSimpleBusLineName(String busLineName) {
|
||||
if (busLineName == null) {
|
||||
return String.valueOf("");
|
||||
}
|
||||
return busLineName.replaceAll("\\(.*?\\)", "");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
26
modules/mogo-module-tanlu/src/main/java/com/mogo/tanlu/map/ChString.java
Executable file
26
modules/mogo-module-tanlu/src/main/java/com/mogo/tanlu/map/ChString.java
Executable file
@@ -0,0 +1,26 @@
|
||||
package com.mogo.tanlu.map;
|
||||
|
||||
public class ChString {
|
||||
public static final String Kilometer = "\u516c\u91cc";// "公里";
|
||||
public static final String Meter = "\u7c73";// "米";
|
||||
public static final String ByFoot = "\u6b65\u884c";// "步行";
|
||||
public static final String To = "\u53bb\u5f80";// "去往";
|
||||
public static final String Station = "\u8f66\u7ad9";// "车站";
|
||||
public static final String TargetPlace = "\u76ee\u7684\u5730";// "目的地";
|
||||
public static final String StartPlace = "\u51fa\u53d1\u5730";// "出发地";
|
||||
public static final String About = "\u5927\u7ea6";// "大约";
|
||||
public static final String Direction = "\u65b9\u5411";// "方向";
|
||||
|
||||
public static final String GetOn = "\u4e0a\u8f66";// "上车";
|
||||
public static final String GetOff = "\u4e0b\u8f66";// "下车";
|
||||
public static final String Zhan = "\u7ad9";// "站";
|
||||
|
||||
public static final String cross = "\u4ea4\u53c9\u8def\u53e3"; // 交叉路口
|
||||
public static final String type = "\u7c7b\u522b"; // 类别
|
||||
public static final String address = "\u5730\u5740"; // 地址
|
||||
public static final String PrevStep = "\u4e0a\u4e00\u6b65";
|
||||
public static final String NextStep = "\u4e0b\u4e00\u6b65";
|
||||
public static final String Gong = "\u516c\u4ea4";
|
||||
public static final String ByBus = "\u4e58\u8f66";
|
||||
public static final String Arrive = "\u5230\u8FBE";// 到达
|
||||
}
|
||||
@@ -0,0 +1,384 @@
|
||||
package com.mogo.tanlu.map;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.amap.api.maps.AMap;
|
||||
import com.amap.api.maps.model.BitmapDescriptor;
|
||||
import com.amap.api.maps.model.BitmapDescriptorFactory;
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.amap.api.maps.model.LatLngBounds;
|
||||
import com.amap.api.maps.model.Marker;
|
||||
import com.amap.api.maps.model.MarkerOptions;
|
||||
import com.amap.api.maps.model.PolylineOptions;
|
||||
import com.amap.api.services.core.LatLonPoint;
|
||||
import com.amap.api.services.route.DrivePath;
|
||||
import com.amap.api.services.route.DriveStep;
|
||||
import com.amap.api.services.route.TMC;
|
||||
import com.mogo.tanlu.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* 导航路线图层类
|
||||
*/
|
||||
public class DrivingRouteOverlay extends RouteOverlay {
|
||||
private DrivePath drivePath;
|
||||
private List<LatLonPoint> throughPointList;
|
||||
private List<Marker> throughPointMarkerList = new ArrayList<Marker>();
|
||||
private boolean throughPointMarkerVisible = true;
|
||||
private List<TMC> tmcs;
|
||||
private PolylineOptions mPolylineOptions;
|
||||
private PolylineOptions mPolylineOptionscolor;
|
||||
private Context mContext;
|
||||
private boolean isColorfulline = true;
|
||||
private float mWidth = 4;
|
||||
private List<LatLng> mLatLngsOfPath;
|
||||
|
||||
public void setIsColorfulline(boolean iscolorfulline) {
|
||||
this.isColorfulline = iscolorfulline;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据给定的参数,构造一个导航路线图层类对象。
|
||||
*
|
||||
* @param amap 地图对象。
|
||||
* @param path 导航路线规划方案。
|
||||
* @param context 当前的activity对象。
|
||||
*/
|
||||
public DrivingRouteOverlay(Context context, AMap amap, DrivePath path,
|
||||
LatLonPoint start, LatLonPoint end, List<LatLonPoint> throughPointList) {
|
||||
super(context);
|
||||
mContext = context;
|
||||
mAMap = amap;
|
||||
this.drivePath = path;
|
||||
startPoint = AMapUtil.convertToLatLng(start);
|
||||
endPoint = AMapUtil.convertToLatLng(end);
|
||||
this.throughPointList = throughPointList;
|
||||
|
||||
initBitmapDescriptor();
|
||||
}
|
||||
|
||||
public float getRouteWidth() {
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置路线宽度
|
||||
*
|
||||
* @param mWidth 路线宽度,取值范围:大于0
|
||||
*/
|
||||
public void setRouteWidth(float mWidth) {
|
||||
this.mWidth = mWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加驾车路线添加到地图上显示。
|
||||
*/
|
||||
public void addToMap() {
|
||||
initPolylineOptions();
|
||||
try {
|
||||
if (mAMap == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mWidth == 0 || drivePath == null) {
|
||||
return;
|
||||
}
|
||||
mLatLngsOfPath = new ArrayList<LatLng>();
|
||||
tmcs = new ArrayList<TMC>();
|
||||
List<DriveStep> drivePaths = drivePath.getSteps();
|
||||
mPolylineOptions.add(startPoint);
|
||||
for (int i = 0; i < drivePaths.size(); i++) {
|
||||
DriveStep step = drivePaths.get(i);
|
||||
List<LatLonPoint> latlonPoints = step.getPolyline();
|
||||
List<TMC> tmclist = step.getTMCs();
|
||||
tmcs.addAll(tmclist);
|
||||
addDrivingStationMarkers(step, convertToLatLng(latlonPoints.get(0)));
|
||||
for (LatLonPoint latlonpoint : latlonPoints) {
|
||||
mPolylineOptions.add(convertToLatLng(latlonpoint));
|
||||
mLatLngsOfPath.add(convertToLatLng(latlonpoint));
|
||||
}
|
||||
}
|
||||
mPolylineOptions.add(endPoint);
|
||||
if (startMarker != null) {
|
||||
startMarker.remove();
|
||||
startMarker = null;
|
||||
}
|
||||
|
||||
if (endMarker != null) {
|
||||
endMarker.remove();
|
||||
endMarker = null;
|
||||
}
|
||||
// addStartAndEndMarker();
|
||||
// addThroughPointMarker();
|
||||
if (isColorfulline && tmcs.size() > 0) {
|
||||
colorWayUpdate(tmcs);
|
||||
showcolorPolyline();
|
||||
} else {
|
||||
showPolyline();
|
||||
}
|
||||
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化线段属性
|
||||
*/
|
||||
private void initPolylineOptions() {
|
||||
mPolylineOptions = null;
|
||||
mPolylineOptions = new PolylineOptions();
|
||||
mPolylineOptions.color(getDriveColor()).width(getRouteWidth());
|
||||
}
|
||||
|
||||
private void showPolyline() {
|
||||
addPolyLine(mPolylineOptions);
|
||||
}
|
||||
|
||||
private void showcolorPolyline() {
|
||||
addPolyLine(mPolylineOptionscolor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据不同的路段拥堵情况展示不同的颜色
|
||||
*
|
||||
* @param tmcSection
|
||||
*/
|
||||
private void colorWayUpdate(List<TMC> tmcSection) {
|
||||
if (mAMap == null) {
|
||||
return;
|
||||
}
|
||||
if (tmcSection == null || tmcSection.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
TMC segmentTrafficStatus;
|
||||
mPolylineOptionscolor = null;
|
||||
mPolylineOptionscolor = new PolylineOptions();
|
||||
mPolylineOptionscolor.width(getRouteWidth());
|
||||
List<Integer> colorList = new ArrayList<Integer>();
|
||||
List<BitmapDescriptor> bitmapDescriptors = new ArrayList<BitmapDescriptor>();
|
||||
List<LatLng> points = new ArrayList<>();
|
||||
List<Integer> texIndexList = new ArrayList<Integer>();
|
||||
// mPolylineOptionscolor.add(startPoint);
|
||||
// mPolylineOptionscolor.add(AMapUtil.convertToLatLng(tmcSection.get(0).getPolyline().get(0)));
|
||||
|
||||
points.add(startPoint);
|
||||
points.add(AMapUtil.convertToLatLng(tmcSection.get(0).getPolyline().get(0)));
|
||||
colorList.add(getDriveColor());
|
||||
bitmapDescriptors.add(defaultRoute);
|
||||
|
||||
BitmapDescriptor bitmapDescriptor = null;
|
||||
int textIndex = 0;
|
||||
texIndexList.add(textIndex);
|
||||
texIndexList.add(++textIndex);
|
||||
for (int i = 0; i < tmcSection.size(); i++) {
|
||||
segmentTrafficStatus = tmcSection.get(i);
|
||||
int color = getcolor(segmentTrafficStatus.getStatus());
|
||||
bitmapDescriptor = getTrafficBitmapDescriptor(segmentTrafficStatus.getStatus());
|
||||
List<LatLonPoint> mployline = segmentTrafficStatus.getPolyline();
|
||||
for (int j = 0; j < mployline.size(); j++) {
|
||||
// mPolylineOptionscolor.add(AMapUtil.convertToLatLng(mployline.get(j)));
|
||||
points.add(AMapUtil.convertToLatLng(mployline.get(j)));
|
||||
colorList.add(color);
|
||||
|
||||
texIndexList.add(++textIndex);
|
||||
bitmapDescriptors.add(bitmapDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
points.add(endPoint);
|
||||
colorList.add(getDriveColor());
|
||||
bitmapDescriptors.add(defaultRoute);
|
||||
texIndexList.add(++textIndex);
|
||||
mPolylineOptionscolor.addAll(points);
|
||||
mPolylineOptionscolor.colorValues(colorList);
|
||||
|
||||
// mPolylineOptionscolor.setCustomTextureIndex(texIndexList);
|
||||
// mPolylineOptionscolor.setCustomTextureList(bitmapDescriptors);
|
||||
}
|
||||
|
||||
private BitmapDescriptor defaultRoute = null;
|
||||
private BitmapDescriptor unknownTraffic = null;
|
||||
private BitmapDescriptor smoothTraffic = null;
|
||||
private BitmapDescriptor slowTraffic = null;
|
||||
private BitmapDescriptor jamTraffic = null;
|
||||
private BitmapDescriptor veryJamTraffic = null;
|
||||
|
||||
private void initBitmapDescriptor() {
|
||||
defaultRoute = BitmapDescriptorFactory.fromResource(R.drawable.amap_route_color_texture_6_arrow);
|
||||
smoothTraffic = BitmapDescriptorFactory.fromResource(R.drawable.amap_route_color_texture_4_arrow);
|
||||
unknownTraffic = BitmapDescriptorFactory.fromResource(R.drawable.amap_route_color_texture_0_arrow);
|
||||
slowTraffic = BitmapDescriptorFactory.fromResource(R.drawable.amap_route_color_texture_3_arrow);
|
||||
jamTraffic = BitmapDescriptorFactory.fromResource(R.drawable.amap_route_color_texture_2_arrow);
|
||||
veryJamTraffic = BitmapDescriptorFactory.fromResource(R.drawable.amap_route_color_texture_9_arrow);
|
||||
}
|
||||
|
||||
private BitmapDescriptor getTrafficBitmapDescriptor(String status) {
|
||||
if (status.equals("畅通")) {
|
||||
return smoothTraffic;
|
||||
} else if (status.equals("缓行")) {
|
||||
return slowTraffic;
|
||||
} else if (status.equals("拥堵")) {
|
||||
return jamTraffic;
|
||||
} else if (status.equals("严重拥堵")) {
|
||||
return veryJamTraffic;
|
||||
} else {
|
||||
return defaultRoute;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private int getcolor(String status) {
|
||||
if (status.equals("畅通")) {
|
||||
return Color.GREEN;
|
||||
} else if (status.equals("缓行")) {
|
||||
return Color.YELLOW;
|
||||
} else if (status.equals("拥堵")) {
|
||||
return Color.RED;
|
||||
} else if (status.equals("严重拥堵")) {
|
||||
return Color.parseColor("#990033");
|
||||
} else {
|
||||
return Color.GREEN;
|
||||
}
|
||||
}
|
||||
|
||||
public LatLng convertToLatLng(LatLonPoint point) {
|
||||
return new LatLng(point.getLatitude(), point.getLongitude());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param driveStep
|
||||
* @param latLng
|
||||
*/
|
||||
private void addDrivingStationMarkers(DriveStep driveStep, LatLng latLng) {
|
||||
addStationMarker(new MarkerOptions()
|
||||
.position(latLng)
|
||||
.title("\u65B9\u5411:" + driveStep.getAction()
|
||||
+ "\n\u9053\u8DEF:" + driveStep.getRoad())
|
||||
.snippet(driveStep.getInstruction()).visible(nodeIconVisible)
|
||||
.anchor(0.5f, 0.5f).icon(getDriveBitmapDescriptor()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LatLngBounds getLatLngBounds() {
|
||||
LatLngBounds.Builder b = LatLngBounds.builder();
|
||||
b.include(new LatLng(startPoint.latitude, startPoint.longitude));
|
||||
b.include(new LatLng(endPoint.latitude, endPoint.longitude));
|
||||
if (this.throughPointList != null && this.throughPointList.size() > 0) {
|
||||
for (int i = 0; i < this.throughPointList.size(); i++) {
|
||||
b.include(new LatLng(
|
||||
this.throughPointList.get(i).getLatitude(),
|
||||
this.throughPointList.get(i).getLongitude()));
|
||||
}
|
||||
}
|
||||
return b.build();
|
||||
}
|
||||
|
||||
public void setThroughPointIconVisibility(boolean visible) {
|
||||
try {
|
||||
throughPointMarkerVisible = visible;
|
||||
if (this.throughPointMarkerList != null
|
||||
&& this.throughPointMarkerList.size() > 0) {
|
||||
for (int i = 0; i < this.throughPointMarkerList.size(); i++) {
|
||||
this.throughPointMarkerList.get(i).setVisible(visible);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void addThroughPointMarker() {
|
||||
if (this.throughPointList != null && this.throughPointList.size() > 0) {
|
||||
LatLonPoint latLonPoint = null;
|
||||
for (int i = 0; i < this.throughPointList.size(); i++) {
|
||||
latLonPoint = this.throughPointList.get(i);
|
||||
if (latLonPoint != null) {
|
||||
throughPointMarkerList.add(mAMap
|
||||
.addMarker((new MarkerOptions())
|
||||
.position(
|
||||
new LatLng(latLonPoint
|
||||
.getLatitude(), latLonPoint
|
||||
.getLongitude()))
|
||||
.visible(throughPointMarkerVisible)
|
||||
.icon(getThroughPointBitDes())
|
||||
.title("\u9014\u7ECF\u70B9")));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private BitmapDescriptor getThroughPointBitDes() {
|
||||
return BitmapDescriptorFactory.fromResource(R.drawable.amap_through);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取两点间距离
|
||||
*
|
||||
* @param start
|
||||
* @param end
|
||||
* @return
|
||||
*/
|
||||
public static int calculateDistance(LatLng start, LatLng end) {
|
||||
double x1 = start.longitude;
|
||||
double y1 = start.latitude;
|
||||
double x2 = end.longitude;
|
||||
double y2 = end.latitude;
|
||||
return calculateDistance(x1, y1, x2, y2);
|
||||
}
|
||||
|
||||
public static int calculateDistance(double x1, double y1, double x2, double y2) {
|
||||
final double NF_pi = 0.01745329251994329; // 弧度 PI/180
|
||||
x1 *= NF_pi;
|
||||
y1 *= NF_pi;
|
||||
x2 *= NF_pi;
|
||||
y2 *= NF_pi;
|
||||
double sinx1 = Math.sin(x1);
|
||||
double siny1 = Math.sin(y1);
|
||||
double cosx1 = Math.cos(x1);
|
||||
double cosy1 = Math.cos(y1);
|
||||
double sinx2 = Math.sin(x2);
|
||||
double siny2 = Math.sin(y2);
|
||||
double cosx2 = Math.cos(x2);
|
||||
double cosy2 = Math.cos(y2);
|
||||
double[] v1 = new double[3];
|
||||
v1[0] = cosy1 * cosx1 - cosy2 * cosx2;
|
||||
v1[1] = cosy1 * sinx1 - cosy2 * sinx2;
|
||||
v1[2] = siny1 - siny2;
|
||||
double dist = Math.sqrt(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]);
|
||||
|
||||
return (int) (Math.asin(dist / 2) * 12742001.5798544);
|
||||
}
|
||||
|
||||
|
||||
//获取指定两点之间固定距离点
|
||||
public static LatLng getPointForDis(LatLng sPt, LatLng ePt, double dis) {
|
||||
double lSegLength = calculateDistance(sPt, ePt);
|
||||
double preResult = dis / lSegLength;
|
||||
return new LatLng((ePt.latitude - sPt.latitude) * preResult + sPt.latitude, (ePt.longitude - sPt.longitude) * preResult + sPt.longitude);
|
||||
}
|
||||
|
||||
/**
|
||||
* 去掉DriveLineOverlay上的线段和标记。
|
||||
*/
|
||||
@Override
|
||||
public void removeFromMap() {
|
||||
try {
|
||||
super.removeFromMap();
|
||||
if (this.throughPointMarkerList != null
|
||||
&& this.throughPointMarkerList.size() > 0) {
|
||||
for (int i = 0; i < this.throughPointMarkerList.size(); i++) {
|
||||
this.throughPointMarkerList.get(i).remove();
|
||||
}
|
||||
this.throughPointMarkerList.clear();
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
236
modules/mogo-module-tanlu/src/main/java/com/mogo/tanlu/map/RouteOverlay.java
Executable file
236
modules/mogo-module-tanlu/src/main/java/com/mogo/tanlu/map/RouteOverlay.java
Executable file
@@ -0,0 +1,236 @@
|
||||
package com.mogo.tanlu.map;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.amap.api.maps.AMap;
|
||||
import com.amap.api.maps.CameraUpdateFactory;
|
||||
import com.amap.api.maps.model.BitmapDescriptor;
|
||||
import com.amap.api.maps.model.BitmapDescriptorFactory;
|
||||
import com.amap.api.maps.model.LatLng;
|
||||
import com.amap.api.maps.model.LatLngBounds;
|
||||
import com.amap.api.maps.model.Marker;
|
||||
import com.amap.api.maps.model.MarkerOptions;
|
||||
import com.amap.api.maps.model.Polyline;
|
||||
import com.amap.api.maps.model.PolylineOptions;
|
||||
import com.mogo.tanlu.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class RouteOverlay {
|
||||
protected List<Marker> stationMarkers = new ArrayList<Marker>();
|
||||
protected List<Polyline> allPolyLines = new ArrayList<Polyline>();
|
||||
protected Marker startMarker;
|
||||
protected Marker endMarker;
|
||||
protected LatLng startPoint;
|
||||
protected LatLng endPoint;
|
||||
protected AMap mAMap;
|
||||
private Context mContext;
|
||||
private Bitmap startBit, endBit, busBit, walkBit, driveBit;
|
||||
protected boolean nodeIconVisible = true;
|
||||
|
||||
public RouteOverlay(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* 去掉BusRouteOverlay上所有的Marker。
|
||||
*
|
||||
* @since V2.1.0
|
||||
*/
|
||||
public void removeFromMap() {
|
||||
if (startMarker != null) {
|
||||
startMarker.remove();
|
||||
|
||||
}
|
||||
if (endMarker != null) {
|
||||
endMarker.remove();
|
||||
}
|
||||
for (Marker marker : stationMarkers) {
|
||||
marker.remove();
|
||||
}
|
||||
for (Polyline line : allPolyLines) {
|
||||
line.remove();
|
||||
}
|
||||
destroyBit();
|
||||
}
|
||||
|
||||
private void destroyBit() {
|
||||
if (startBit != null) {
|
||||
startBit.recycle();
|
||||
startBit = null;
|
||||
}
|
||||
if (endBit != null) {
|
||||
endBit.recycle();
|
||||
endBit = null;
|
||||
}
|
||||
if (busBit != null) {
|
||||
busBit.recycle();
|
||||
busBit = null;
|
||||
}
|
||||
if (walkBit != null) {
|
||||
walkBit.recycle();
|
||||
walkBit = null;
|
||||
}
|
||||
if (driveBit != null) {
|
||||
driveBit.recycle();
|
||||
driveBit = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 给起点Marker设置图标,并返回更换图标的图片。如不用默认图片,需要重写此方法。
|
||||
*
|
||||
* @return 更换的Marker图片。
|
||||
* @since V2.1.0
|
||||
*/
|
||||
protected BitmapDescriptor getStartBitmapDescriptor() {
|
||||
return BitmapDescriptorFactory.fromResource(R.drawable.amap_start);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给终点Marker设置图标,并返回更换图标的图片。如不用默认图片,需要重写此方法。
|
||||
*
|
||||
* @return 更换的Marker图片。
|
||||
* @since V2.1.0
|
||||
*/
|
||||
protected BitmapDescriptor getEndBitmapDescriptor() {
|
||||
return BitmapDescriptorFactory.fromResource(R.drawable.amap_end);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给公交Marker设置图标,并返回更换图标的图片。如不用默认图片,需要重写此方法。
|
||||
*
|
||||
* @return 更换的Marker图片。
|
||||
* @since V2.1.0
|
||||
*/
|
||||
protected BitmapDescriptor getBusBitmapDescriptor() {
|
||||
return BitmapDescriptorFactory.fromResource(R.drawable.amap_bus);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给步行Marker设置图标,并返回更换图标的图片。如不用默认图片,需要重写此方法。
|
||||
*
|
||||
* @return 更换的Marker图片。
|
||||
* @since V2.1.0
|
||||
*/
|
||||
protected BitmapDescriptor getWalkBitmapDescriptor() {
|
||||
return BitmapDescriptorFactory.fromResource(R.drawable.amap_man);
|
||||
}
|
||||
|
||||
protected BitmapDescriptor getDriveBitmapDescriptor() {
|
||||
return BitmapDescriptorFactory.fromResource(R.drawable.amap_car);
|
||||
}
|
||||
|
||||
protected void addStartAndEndMarker() {
|
||||
startMarker = mAMap.addMarker((new MarkerOptions())
|
||||
.position(startPoint).icon(getStartBitmapDescriptor())
|
||||
.title("\u8D77\u70B9"));
|
||||
// startMarker.showInfoWindow();
|
||||
|
||||
endMarker = mAMap.addMarker((new MarkerOptions()).position(endPoint)
|
||||
.icon(getEndBitmapDescriptor()).title("\u7EC8\u70B9"));
|
||||
// mAMap.moveCamera(CameraUpdateFactory.newLatLngZoom(startPoint,
|
||||
// getShowRouteZoom()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动镜头到当前的视角。
|
||||
*
|
||||
* @since V2.1.0
|
||||
*/
|
||||
public void zoomToSpan() {
|
||||
if (startPoint != null) {
|
||||
if (mAMap == null)
|
||||
return;
|
||||
try {
|
||||
LatLngBounds bounds = getLatLngBounds();
|
||||
mAMap.animateCamera(CameraUpdateFactory
|
||||
.newLatLngBounds(bounds, 50));
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected LatLngBounds getLatLngBounds() {
|
||||
LatLngBounds.Builder b = LatLngBounds.builder();
|
||||
b.include(new LatLng(startPoint.latitude, startPoint.longitude));
|
||||
b.include(new LatLng(endPoint.latitude, endPoint.longitude));
|
||||
for (Polyline polyline : allPolyLines) {
|
||||
for (LatLng point : polyline.getPoints()) {
|
||||
b.include(point);
|
||||
}
|
||||
}
|
||||
return b.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 路段节点图标控制显示接口。
|
||||
*
|
||||
* @param visible true为显示节点图标,false为不显示。
|
||||
* @since V2.3.1
|
||||
*/
|
||||
public void setNodeIconVisibility(boolean visible) {
|
||||
try {
|
||||
nodeIconVisible = visible;
|
||||
if (this.stationMarkers != null && this.stationMarkers.size() > 0) {
|
||||
for (int i = 0; i < this.stationMarkers.size(); i++) {
|
||||
this.stationMarkers.get(i).setVisible(visible);
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected void addStationMarker(MarkerOptions options) {
|
||||
if (options == null) {
|
||||
return;
|
||||
}
|
||||
Marker marker = mAMap.addMarker(options);
|
||||
if (marker != null) {
|
||||
stationMarkers.add(marker);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void addPolyLine(PolylineOptions options) {
|
||||
if (options == null) {
|
||||
return;
|
||||
}
|
||||
Polyline polyline = mAMap.addPolyline(options);
|
||||
if (polyline != null) {
|
||||
allPolyLines.add(polyline);
|
||||
}
|
||||
}
|
||||
|
||||
protected float getRouteWidth() {
|
||||
return 18f;
|
||||
}
|
||||
|
||||
protected int getWalkColor() {
|
||||
return Color.parseColor("#6db74d");
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义路线颜色。
|
||||
* return 自定义路线颜色。
|
||||
*
|
||||
* @since V2.2.1
|
||||
*/
|
||||
protected int getBusColor() {
|
||||
return Color.parseColor("#537edc");
|
||||
}
|
||||
|
||||
protected int getDriveColor() {
|
||||
return Color.parseColor("#537edc");
|
||||
}
|
||||
|
||||
// protected int getShowRouteZoom() {
|
||||
// return 15;
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user