地图模块适配
This commit is contained in:
@@ -62,6 +62,7 @@ import com.mogo.map.utils.MogoMapUtils;
|
||||
import com.mogo.map.utils.ObjectUtils;
|
||||
import com.mogo.map.utils.ResIdCache;
|
||||
import com.zhidaoauto.map.sdk.open.MapAutoApi;
|
||||
import com.zhidaoauto.map.sdk.open.abs.IResult;
|
||||
import com.zhidaoauto.map.sdk.open.abs.MapStatusListener;
|
||||
import com.zhidaoauto.map.sdk.open.abs.OnCameraChangeListener;
|
||||
import com.zhidaoauto.map.sdk.open.abs.OnHdDataDownByCityListener;
|
||||
@@ -83,11 +84,12 @@ import com.zhidaoauto.map.sdk.open.location.LocationClient;
|
||||
import com.zhidaoauto.map.sdk.open.location.MyLocationStyle;
|
||||
import com.zhidaoauto.map.sdk.open.marker.BitmapDescriptorFactory;
|
||||
import com.zhidaoauto.map.sdk.open.marker.Marker;
|
||||
import com.zhidaoauto.map.sdk.open.marker.MarkerHelper;
|
||||
import com.zhidaoauto.map.sdk.open.marker.OnMarkClickListener;
|
||||
import com.zhidaoauto.map.sdk.open.query.LonLatPoint;
|
||||
import com.zhidaoauto.map.sdk.open.road.RoadCross;
|
||||
import com.zhidaoauto.map.sdk.open.road.RoadRectInfos;
|
||||
import com.zhidaoauto.map.sdk.open.road.StopLine;
|
||||
import com.zhidaoauto.map.sdk.open.routeinfo.RoadInfo;
|
||||
import com.zhidaoauto.map.sdk.open.tools.MapTools;
|
||||
import com.zhidaoauto.map.sdk.open.view.MapAutoView;
|
||||
import com.zhidaoauto.map.sdk.open.view.MapAutoViewHelper;
|
||||
@@ -136,7 +138,7 @@ public class AMapViewWrapper implements IMogoMapView,
|
||||
|
||||
private void initViews() {
|
||||
// 初始化首次地图进入的时候的样式, MapAutoApi.INSTANCE.init(context, mapParams);将影响这里的数据
|
||||
int mapStyle = MapAutoApi.INSTANCE.getMapParams().getStyleMode();
|
||||
int mapStyle = mMapView.getMapStyleParams().getStyleMode();
|
||||
CallerLogger.INSTANCE.d(M_MAP + TAG, "默认配置地图模式:mapStyle=" + mapStyle);
|
||||
switch (mapStyle) {
|
||||
case MapAutoApi.MAP_STYLE_DAY:
|
||||
@@ -197,7 +199,7 @@ public class AMapViewWrapper implements IMogoMapView,
|
||||
mMapView.setOnRoamStatusListener(this);
|
||||
mMapView.setOnMapViewVisualAngleChangeListener(this);
|
||||
mMapView.setOnRoadInfoListener(this, 1);
|
||||
MapAutoApi.INSTANCE.registerLogListener(this);
|
||||
MapAutoApi.INSTANCE.registerLogListener(this,mMapView.getEventController());
|
||||
CallerLogger.INSTANCE.d(M_MAP + TAG, "styleop - initListeners - setOnMapStyleListener - view " + mMapView);
|
||||
}
|
||||
|
||||
@@ -225,14 +227,14 @@ public class AMapViewWrapper implements IMogoMapView,
|
||||
@Override
|
||||
public void onStopLineInfo(@androidx.annotation.Nullable StopLine stopLine) {
|
||||
MogoLocation carLoc = CallerChassisLocationWGS84ListenerManager.INSTANCE.getChassisLocationWGS84();
|
||||
if (stopLine != null && stopLine.road_id != null && !stopLine.road_id.isEmpty() && stopLine.points != null && stopLine.points.size() > 0) {
|
||||
ArrayList<LonLatPoint> points = stopLine.points;
|
||||
if (stopLine != null && stopLine.getRoad_id() != null && !stopLine.getRoad_id().isEmpty() && stopLine.getPoints() != null && stopLine.getPoints().size() > 0) {
|
||||
ArrayList<LonLatPoint> points = stopLine.getPoints();
|
||||
if (carLoc != null) {
|
||||
// //CallerLogger.INSTANCE.d(M_MAP + TAG, "onStopLineInfo:stop_line" + stopLine + ", car_loc:{lon: " + carLoc.getLatitude() + ", lat: " + carLoc.getLongitude() + "}");
|
||||
MapRoadInfo.StopLine stopInfo = convert(stopLine);
|
||||
LonLatPoint p1 = points.get(0);
|
||||
LonLatPoint p2 = points.get(points.size() - 1);
|
||||
double distanceOfCarToStopLine = MapDataApi.INSTANCE.getNearstFromPointToSegment(carLoc.getLongitude(), carLoc.getLatitude(), p1.longitude, p1.latitude, p2.longitude, p2.latitude) * 10_0000;
|
||||
double distanceOfCarToStopLine = MapDataApi.INSTANCE.getNearstFromPointToSegment(carLoc.getLongitude(), carLoc.getLatitude(), p1.getLongitude(), p1.getLatitude(), p2.getLongitude(), p2.getLatitude()) * 10_0000;
|
||||
stopInfo.setDistanceOfCarToStopLine(distanceOfCarToStopLine);
|
||||
//CallerLogger.INSTANCE.d(M_MAP + TAG, "onStopLineInfo: --- distance: " + distanceOfCarToStopLine);
|
||||
CallerMapRoadListenerManager.INSTANCE.invokeListenersOnStopLineGet(stopInfo);
|
||||
@@ -246,21 +248,21 @@ public class AMapViewWrapper implements IMogoMapView,
|
||||
|
||||
private MapRoadInfo.StopLine convert(StopLine line) {
|
||||
MapRoadInfo.StopLine ret = new MapRoadInfo.StopLine();
|
||||
ret.setDistance(line.distance);
|
||||
ret.setLaneId(line.lane_id);
|
||||
ret.setRoadId(line.road_id);
|
||||
ret.setTieId(line.tile_id);
|
||||
ArrayList<LonLatPoint> points = line.points;
|
||||
ret.setDistance(line.getDistance());
|
||||
ret.setLaneId(line.getLane_id());
|
||||
ret.setRoadId(line.getRoad_id());
|
||||
ret.setTieId(line.getTile_id());
|
||||
ArrayList<LonLatPoint> points = line.getPoints();
|
||||
if (points != null && points.size() > 0) {
|
||||
List<MogoLatLng> newPoints = new ArrayList<>();
|
||||
for (int i = 0; i < points.size(); i++) {
|
||||
LonLatPoint lonLatPoint = points.get(i);
|
||||
MogoLatLng latLng = new MogoLatLng(lonLatPoint.latitude, lonLatPoint.longitude);
|
||||
latLng.duration = lonLatPoint.duration;
|
||||
latLng.angle = lonLatPoint.angle;
|
||||
latLng.speed = lonLatPoint.speed;
|
||||
latLng.altitude = lonLatPoint.altitude;
|
||||
latLng.provider = lonLatPoint.provider;
|
||||
MogoLatLng latLng = new MogoLatLng(lonLatPoint.getLatitude(), lonLatPoint.getLongitude());
|
||||
latLng.duration = lonLatPoint.getDuration();
|
||||
latLng.angle = lonLatPoint.getAngle();
|
||||
latLng.speed = lonLatPoint.getSpeed();
|
||||
latLng.altitude = lonLatPoint.getAltitude();
|
||||
latLng.provider = lonLatPoint.getProvider();
|
||||
newPoints.add(latLng);
|
||||
}
|
||||
ret.setPoints(newPoints);
|
||||
@@ -316,7 +318,7 @@ public class AMapViewWrapper implements IMogoMapView,
|
||||
mMapView.setOnMapTouchListener(null);
|
||||
mMapView.setOnMapClickListener(null);
|
||||
mMapView.setOnCameraChangeListener(null);
|
||||
MapAutoApi.INSTANCE.unregisterLogListener(this);
|
||||
MapAutoApi.INSTANCE.unregisterLogListener(this,mMapView.getEventController());
|
||||
CallerLogger.INSTANCE.d(M_MAP + TAG, "map onDestroy");
|
||||
}
|
||||
|
||||
@@ -485,7 +487,7 @@ public class AMapViewWrapper implements IMogoMapView,
|
||||
|
||||
public void initMyLocation() {
|
||||
if (checkAMapView()) {
|
||||
MarkerHelper.INSTANCE.addPreModel(R.raw.guangquan);
|
||||
mMapView.getMarkerController().addPreModel(R.raw.guangquan);
|
||||
// MarkerHelper.addPreModel(R.raw.guangquan_day)
|
||||
mMapView.getMapAutoViewHelper().setMyLocationEnabled(true);
|
||||
}
|
||||
@@ -509,13 +511,13 @@ public class AMapViewWrapper implements IMogoMapView,
|
||||
|
||||
@Override
|
||||
public MogoLatLng getCameraNorthEastPosition() {
|
||||
return ObjectUtils.fromAMap(MapTools.INSTANCE.getVisibleRegion().getRightTopPoint());
|
||||
return ObjectUtils.fromAMap(MapTools.INSTANCE.getVisibleRegion(mMapView.getMapController()).getRightTopPoint());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MogoLatLng getCameraSouthWestPosition() {
|
||||
try {
|
||||
return ObjectUtils.fromAMap(MapTools.INSTANCE.getVisibleRegion().getLeftBottomPoint());
|
||||
return ObjectUtils.fromAMap(MapTools.INSTANCE.getVisibleRegion(mMapView.getMapController()).getLeftBottomPoint());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -549,7 +551,7 @@ public class AMapViewWrapper implements IMogoMapView,
|
||||
public Point getLocationPointInScreen(MogoLatLng latLng) {
|
||||
if (checkAMapView()) {
|
||||
try {
|
||||
return MapTools.INSTANCE.toScreenLocation(ObjectUtils.fromMogo(latLng));
|
||||
return MapTools.INSTANCE.toScreenLocation(ObjectUtils.fromMogo(latLng),mMapView.getMapController());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
@@ -563,7 +565,7 @@ public class AMapViewWrapper implements IMogoMapView,
|
||||
if (checkAMapView()) {
|
||||
try {
|
||||
return ObjectUtils.fromAMap(
|
||||
MapTools.INSTANCE.fromScreenLocation(point));
|
||||
MapTools.INSTANCE.fromScreenLocation(point,mMapView.getMapController()));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
@@ -701,15 +703,7 @@ public class AMapViewWrapper implements IMogoMapView,
|
||||
return getMap().getUIController().getTileId(lon, lat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLimitSpeed(double lon, double lat, float angle) {
|
||||
return MapDataApi.INSTANCE.getLimitSpeed(lon, lat, angle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CenterLine getCenterLineInfo(double lon, double lat, float angle) {
|
||||
return ObjectUtils.transformCenterLine(MapDataApi.INSTANCE.getCenterLineInfo(lon, lat, angle));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void result(@NonNull String filePath) {
|
||||
@@ -917,10 +911,6 @@ public class AMapViewWrapper implements IMogoMapView,
|
||||
return MapAutoApi.INSTANCE.getAngle(startLon, startLat, endLon, endLat);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getRoadAngle(Double lon, Double lat, float angle) {
|
||||
return MapDataApi.INSTANCE.getRoadRectInfo(lon, lat, angle).getAngle();
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载3D模型
|
||||
@@ -1023,7 +1013,7 @@ public class AMapViewWrapper implements IMogoMapView,
|
||||
public void setIsDrawPointCloud(Boolean isDrawPointCloud) {
|
||||
try {
|
||||
// 是否绘制点云
|
||||
PointCloudHelper.INSTANCE.setIsDrawPointCloud(isDrawPointCloud);
|
||||
PointCloudHelper.INSTANCE.setIsDrawPointCloud(isDrawPointCloud,mMapView.getMapController());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -1032,13 +1022,13 @@ public class AMapViewWrapper implements IMogoMapView,
|
||||
@Override
|
||||
public void setPointCloudSize(Float pointCloudSize) {
|
||||
//设置点云大小
|
||||
PointCloudHelper.INSTANCE.setPointCloudSize(pointCloudSize);
|
||||
PointCloudHelper.INSTANCE.setPointCloudSize(pointCloudSize,mMapView.getMapController());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPointCloudColor(String color) {
|
||||
// 设置点云颜色
|
||||
PointCloudHelper.INSTANCE.setPointCloudColor(color);
|
||||
PointCloudHelper.INSTANCE.setPointCloudColor(color,mMapView.getMapController());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1130,14 +1120,20 @@ public class AMapViewWrapper implements IMogoMapView,
|
||||
CallerLogger.INSTANCE.i(M_MAP + TAG, "gdCityCode is:" + gdCityCode);
|
||||
Integer id = HDMapUtils.getHDCityCode(gdCityCode);
|
||||
if (id != null) {
|
||||
List<CityInfo> cityInfoList = mMapView.getMapAutoViewHelper().getAllCityCode();
|
||||
if (cityInfoList != null) {
|
||||
for (CityInfo cityInfo : cityInfoList) {
|
||||
if (id == cityInfo.getCityCode()) {
|
||||
return cityInfo.isCache;
|
||||
//TODO 回调改造
|
||||
mMapView.getMapAutoViewHelper().getAllCityCode(new IResult<ArrayList<CityInfo>>() {
|
||||
@Override
|
||||
public void result(int code, @androidx.annotation.Nullable ArrayList<CityInfo> cityInfoList) {
|
||||
if (cityInfoList != null) {
|
||||
for (CityInfo cityInfo : cityInfoList) {
|
||||
if (id == cityInfo.getCityCode()) {
|
||||
// return cityInfo.isCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -3,7 +3,9 @@ package com.mogo.map;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.Point;
|
||||
import android.util.Pair;
|
||||
import com.mogo.eagle.core.data.config.FunctionBuildConfig;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
|
||||
import com.mogo.map.center.CenterLine;
|
||||
import com.mogo.map.overlay.proxy.line.IMapPolylineOverlay;
|
||||
@@ -13,11 +15,11 @@ import com.mogo.map.road.RoadNameInfo;
|
||||
import com.mogo.map.uicontroller.AMapUIController;
|
||||
import com.mogo.map.uicontroller.IMogoMapUIController;
|
||||
import com.mogo.map.utils.ObjectUtils;
|
||||
import com.zhidaoauto.map.sdk.open.abs.IResult;
|
||||
import com.zhidaoauto.map.sdk.open.data.MapDataApi;
|
||||
import com.zhidaoauto.map.sdk.open.data.SinglePointRoadInfo;
|
||||
import com.zhidaoauto.map.sdk.open.marker.BatchMarkerOptions;
|
||||
import com.zhidaoauto.map.sdk.open.marker.Marker;
|
||||
import com.zhidaoauto.map.sdk.open.marker.MarkerHelper;
|
||||
import com.zhidaoauto.map.sdk.open.marker.MarkerOptions;
|
||||
import com.zhidaoauto.map.sdk.open.marker.MarkerSimpleData;
|
||||
import com.zhidaoauto.map.sdk.open.poyline.Polyline;
|
||||
@@ -87,7 +89,7 @@ public class AMapWrapper implements IMogoMap {
|
||||
if (!checkAMap()) {
|
||||
return null;
|
||||
}
|
||||
MarkerOptions markerOptions = ObjectUtils.fromMogo(options);
|
||||
MarkerOptions markerOptions = ObjectUtils.fromMogo(options,mMapView);
|
||||
if (markerOptions == null) {
|
||||
CallerLogger.INSTANCE.e(TAG, "marker参数为空");
|
||||
return null;
|
||||
@@ -96,7 +98,7 @@ public class AMapWrapper implements IMogoMap {
|
||||
if (delegate == null) {
|
||||
return null;
|
||||
}
|
||||
return new AMapPointWrapper(options.getId(), delegate);
|
||||
return new AMapPointWrapper(options.getId(), delegate,mMapView);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -104,16 +106,16 @@ public class AMapWrapper implements IMogoMap {
|
||||
if (!checkAMap()) {
|
||||
return null;
|
||||
}
|
||||
PolylineOptions polylineOptions = ObjectUtils.fromMogo(options);
|
||||
PolylineOptions polylineOptions = ObjectUtils.fromMogo(options,mMapView);
|
||||
if (polylineOptions == null) {
|
||||
CallerLogger.INSTANCE.e(TAG, "polyline参数为空");
|
||||
return null;
|
||||
}
|
||||
Polyline delegate = polylineOptions.lineWidth > 0 ? mAMap.drawThickLine(polylineOptions) : mAMap.drawLine(polylineOptions);
|
||||
Polyline delegate = polylineOptions.getLineWidth() > 0 ? mAMap.drawThickLine(polylineOptions) : mAMap.drawLine(polylineOptions);
|
||||
if (delegate == null) {
|
||||
return null;
|
||||
}
|
||||
return new com.mogo.map.overlay.wrapper.line.AMapPolylineWrapper(options.getId(), delegate);
|
||||
return new com.mogo.map.overlay.wrapper.line.AMapPolylineWrapper(options.getId(), delegate,mMapView);
|
||||
}
|
||||
|
||||
BatchMarkerOptions batchMarkerOptions = new BatchMarkerOptions();
|
||||
@@ -138,13 +140,15 @@ public class AMapWrapper implements IMogoMap {
|
||||
return;
|
||||
}
|
||||
long time = markerOptionsArrayList.get(0).getTime();
|
||||
batchMarkerOptions.list = markerOptionsArrayList;
|
||||
batchMarkerOptions.delayStrategy = false;
|
||||
batchMarkerOptions.ruleAngle = 8.0f;
|
||||
batchMarkerOptions.controlIcon = 1;
|
||||
batchMarkerOptions.satelliteTime = time;
|
||||
batchMarkerOptions.deleteRule = 0;
|
||||
MarkerHelper.INSTANCE.updateBatchMarkerPositon(batchMarkerOptions);
|
||||
batchMarkerOptions.setList(markerOptionsArrayList);
|
||||
batchMarkerOptions.setDelayStrategy(false);
|
||||
batchMarkerOptions.setRuleAngle(8.0f);
|
||||
batchMarkerOptions.setControlIcon(1);
|
||||
batchMarkerOptions.setSatelliteTime(time);
|
||||
batchMarkerOptions.setDeleteRule(0);
|
||||
if(mMapView.getMarkerController() != null){
|
||||
mMapView.getMarkerController().updateBatchMarkerPositon(batchMarkerOptions);
|
||||
}
|
||||
}
|
||||
|
||||
BatchMarkerOptions aiBatchMarkerOptions = new BatchMarkerOptions();
|
||||
@@ -170,19 +174,23 @@ public class AMapWrapper implements IMogoMap {
|
||||
}
|
||||
long time = markerOptionsArrayList.get(0).getTime();
|
||||
// 最后一个参数,是否管理锚点的删除
|
||||
aiBatchMarkerOptions.list = markerOptionsArrayList;
|
||||
aiBatchMarkerOptions.delayStrategy = false;
|
||||
aiBatchMarkerOptions.ruleAngle = 8.0f;
|
||||
aiBatchMarkerOptions.controlIcon = 1;
|
||||
aiBatchMarkerOptions.satelliteTime = time;
|
||||
aiBatchMarkerOptions.deleteRule = 0;
|
||||
MarkerHelper.INSTANCE.updateBatchMarkerPositon(aiBatchMarkerOptions);
|
||||
aiBatchMarkerOptions.setList(markerOptionsArrayList);
|
||||
aiBatchMarkerOptions.setDelayStrategy(false);
|
||||
aiBatchMarkerOptions.setRuleAngle(8.0f);
|
||||
aiBatchMarkerOptions.setControlIcon(1);
|
||||
aiBatchMarkerOptions.setSatelliteTime(time);
|
||||
aiBatchMarkerOptions.setDeleteRule(0);
|
||||
if(mMapView.getMarkerController() != null) {
|
||||
mMapView.getMarkerController().updateBatchMarkerPositon(aiBatchMarkerOptions);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addPreVehicleModel(int type, int modelRes) {
|
||||
try {
|
||||
return MarkerHelper.INSTANCE.addPreVehicleModel(type, modelRes);
|
||||
if(mMapView.getMarkerController() != null){
|
||||
return mMapView.getMarkerController().addPreVehicleModel(type, modelRes);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -192,7 +200,9 @@ public class AMapWrapper implements IMogoMap {
|
||||
@Override
|
||||
public void removeMarker(String uuidString) {
|
||||
try {
|
||||
MarkerHelper.INSTANCE.removeMarker(uuidString);
|
||||
if(mMapView.getMarkerController() != null){
|
||||
mMapView.getMarkerController().removeMarker(uuidString);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -215,7 +225,7 @@ public class AMapWrapper implements IMogoMap {
|
||||
@Override
|
||||
public void setPointToCenter(int x, int y) {
|
||||
if (checkAMap()) {
|
||||
LonLatPoint lonLatPoint = MapTools.INSTANCE.fromScreenLocation(new Point(x, y));
|
||||
LonLatPoint lonLatPoint = MapTools.INSTANCE.fromScreenLocation(new Point(x, y), mMapView.getMapController());
|
||||
mAMap.setCenter(lonLatPoint);
|
||||
}
|
||||
}
|
||||
@@ -273,20 +283,7 @@ public class AMapWrapper implements IMogoMap {
|
||||
return singlePointRoadInfo != null ? singlePointRoadInfo.getLaneWidth() : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CenterLine getCenterLineRangeInfo(double lon, double lat, float angle, float distance) {
|
||||
try {
|
||||
com.zhidaoauto.map.sdk.open.road.CenterLine info = MapDataApi.INSTANCE.getCenterLineRangeInfo(lon, lat, angle, distance);
|
||||
CenterLine ret = null;
|
||||
if (info != null) {
|
||||
ret = new CenterLine(info.id, info.tile_id, info.road_id, info.lane_id, convert(info.points), info.angle == null ? 0f : info.angle);
|
||||
}
|
||||
return ret;
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RoadNameInfo getRoadName(double lon, double lat, float angle) {
|
||||
@@ -298,14 +295,5 @@ public class AMapWrapper implements IMogoMap {
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<Pair<Double, Double>> convert(List<LonLatPoint> points) {
|
||||
if (points == null || points.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<Pair<Double, Double>> ret = new ArrayList<>(points.size());
|
||||
for (LonLatPoint p : points) {
|
||||
ret.add(Pair.create(p.longitude, p.latitude));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
126
libraries/mogo-map/src/main/java/com/mogo/map/MapDataWrapper.kt
Normal file
126
libraries/mogo-map/src/main/java/com/mogo/map/MapDataWrapper.kt
Normal file
@@ -0,0 +1,126 @@
|
||||
package com.mogo.map
|
||||
|
||||
import android.util.Pair
|
||||
import com.mogo.eagle.core.data.map.CenterLine
|
||||
import com.mogo.map.utils.ObjectUtils
|
||||
import com.zhidaoauto.map.sdk.open.abs.IResult
|
||||
import com.zhidaoauto.map.sdk.open.data.MapDataApi
|
||||
import com.zhidaoauto.map.sdk.open.query.LonLatPoint
|
||||
import com.zhidaoauto.map.sdk.open.road.RoadRectInfos
|
||||
import com.zhidaoauto.map.sdk.open.routeinfo.RoadInfo
|
||||
|
||||
/**
|
||||
* 地图数据工具
|
||||
*/
|
||||
object MapDataWrapper {
|
||||
|
||||
/**
|
||||
* 获取车道中心线数据
|
||||
* @param lon 经度
|
||||
* @param lat 纬度
|
||||
* @param angle 角度
|
||||
* @param call 回调
|
||||
*/
|
||||
fun getCenterLineInfo(lon: Double, lat: Double, angle: Float,call:IResult<CenterLine>){
|
||||
MapDataApi.getCenterLineInfo(
|
||||
lon,
|
||||
lat,
|
||||
angle,
|
||||
object : IResult<com.zhidaoauto.map.sdk.open.road.CenterLine> {
|
||||
override fun result(
|
||||
code: Int,
|
||||
result: com.zhidaoauto.map.sdk.open.road.CenterLine?
|
||||
) {
|
||||
call.result(0,ObjectUtils.transformCenterLine(result))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取车道限速
|
||||
* @param lon 经度
|
||||
* @param lat 纬度
|
||||
* @param angle 角度
|
||||
* @param call 回调
|
||||
*/
|
||||
fun getLimitSpeed(lon: Double, lat: Double, angle: Float,call : IResult<Int>) {
|
||||
MapDataApi.getLimitSpeed(lon, lat, angle, object : IResult<RoadInfo> {
|
||||
override fun result(code: Int, result: RoadInfo?) {
|
||||
call.result(code,result?.speed?:0)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取道路角度
|
||||
* @param lon 经度
|
||||
* @param lat 纬度
|
||||
* @param angle 角度
|
||||
* @param call 回调
|
||||
*/
|
||||
fun getRoadAngle(lon: Double, lat: Double, angle: Float,call : IResult<Double>) {
|
||||
MapDataApi.getRoadRectInfo(lon, lat, angle, object : IResult<RoadRectInfos> {
|
||||
override fun result(code: Int, result: RoadRectInfos?) {
|
||||
call.result(code,result?.angle?:0.0)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 按距离获取道路数据
|
||||
* @param lon 经度
|
||||
* @param lat 纬度
|
||||
* @param angle 角度
|
||||
* @param call 回调
|
||||
*/
|
||||
fun getCenterLineRangeInfo(
|
||||
lon: Double,
|
||||
lat: Double,
|
||||
angle: Float,
|
||||
distance: Float,
|
||||
call:IResult<com.mogo.map.center.CenterLine>
|
||||
) {
|
||||
try {
|
||||
|
||||
MapDataApi.getCenterLineRangeInfo(
|
||||
lon,
|
||||
lat,
|
||||
angle,
|
||||
distance,
|
||||
object : IResult<com.zhidaoauto.map.sdk.open.road.CenterLine> {
|
||||
override fun result(
|
||||
code: Int,
|
||||
info: com.zhidaoauto.map.sdk.open.road.CenterLine?
|
||||
) {
|
||||
var ret: com.mogo.map.center.CenterLine? = null
|
||||
if (info != null) {
|
||||
ret = com.mogo.map.center.CenterLine(
|
||||
info.id,
|
||||
info.tile_id,
|
||||
info.road_id,
|
||||
info.lane_id,
|
||||
convert(info.points),
|
||||
info.angle?:0.0
|
||||
)
|
||||
}
|
||||
call.result(code,ret)
|
||||
}
|
||||
})
|
||||
} catch (t: Throwable) {
|
||||
t.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun convert(points: List<LonLatPoint>?): List<Pair<Double, Double>> {
|
||||
if (points == null || points.isEmpty()) {
|
||||
return emptyList()
|
||||
}
|
||||
val ret: MutableList<Pair<Double, Double>> = ArrayList(points.size)
|
||||
for (p in points) {
|
||||
ret.add(Pair.create(p.longitude, p.latitude))
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,9 +4,10 @@ import com.mogo.map.overlay.line.Polyline.Options
|
||||
import com.mogo.map.overlay.proxy.line.*
|
||||
import com.mogo.map.utils.ObjectUtils
|
||||
import com.zhidaoauto.map.sdk.open.poyline.*
|
||||
import com.zhidaoauto.map.sdk.open.view.MapAutoView
|
||||
import java.util.concurrent.atomic.*
|
||||
|
||||
class AMapPolylineWrapper(private val id: String, private val delegate: Polyline): IMapPolylineOverlay {
|
||||
class AMapPolylineWrapper(private val id: String, private val delegate: Polyline,private val mMapAutoView: MapAutoView): IMapPolylineOverlay {
|
||||
|
||||
private val isDestroyed by lazy { AtomicBoolean(false) }
|
||||
|
||||
@@ -63,7 +64,7 @@ class AMapPolylineWrapper(private val id: String, private val delegate: Polyline
|
||||
return
|
||||
}
|
||||
delegate.also {
|
||||
val option = ObjectUtils.fromMogo(options)
|
||||
val option = ObjectUtils.fromMogo(options,mMapAutoView)
|
||||
if (option != null) {
|
||||
it.setOption(option)
|
||||
}
|
||||
|
||||
@@ -6,9 +6,10 @@ import com.mogo.map.overlay.proxy.point.*
|
||||
import com.mogo.map.utils.ObjectUtils
|
||||
import com.zhidaoauto.map.sdk.open.marker.*
|
||||
import com.zhidaoauto.map.sdk.open.query.LonLatPoint
|
||||
import com.zhidaoauto.map.sdk.open.view.MapAutoView
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
class AMapPointWrapper(private val id: String, private val delegate: Marker): IMapPointOverlay {
|
||||
class AMapPointWrapper(private val id: String, private val delegate: Marker, private val mMapAutoView: MapAutoView): IMapPointOverlay {
|
||||
|
||||
private val isDestroyed by lazy { AtomicBoolean(false) }
|
||||
|
||||
@@ -71,7 +72,7 @@ class AMapPointWrapper(private val id: String, private val delegate: Marker): IM
|
||||
if (isDestroyed.get() || isRemoved.get()) {
|
||||
return
|
||||
}
|
||||
delegate.setMarkerOptions(ObjectUtils.fromMogo(opt))
|
||||
delegate.setMarkerOptions(ObjectUtils.fromMogo(opt,mMapAutoView))
|
||||
}
|
||||
|
||||
override fun addDynamicAnchorPosition(point: MogoLatLng, angle: Float, duration: Long) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.zhidaoauto.map.sdk.open.marker.MarkerOptions;
|
||||
import com.zhidaoauto.map.sdk.open.marker.MarkerSimpleData;
|
||||
import com.zhidaoauto.map.sdk.open.poyline.PolylineOptions;
|
||||
import com.zhidaoauto.map.sdk.open.query.LonLatPoint;
|
||||
import com.zhidaoauto.map.sdk.open.view.MapAutoView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -32,7 +33,7 @@ import mogo.yycp.api.proto.SocketDownData;
|
||||
*/
|
||||
public class ObjectUtils {
|
||||
|
||||
public static MarkerOptions fromMogo(Point.Options opt) {
|
||||
public static MarkerOptions fromMogo(Point.Options opt, MapAutoView mapAutoView) {
|
||||
|
||||
if (opt == null) {
|
||||
return null;
|
||||
@@ -49,15 +50,15 @@ public class ObjectUtils {
|
||||
}
|
||||
MarkerOptions markerOptions;
|
||||
if(TextUtils.isEmpty(opt.getId())){
|
||||
markerOptions = new MarkerOptions();
|
||||
markerOptions = new MarkerOptions(mapAutoView.getMapController());
|
||||
}else{
|
||||
markerOptions = new MarkerOptions(opt.getId());
|
||||
markerOptions = new MarkerOptions(opt.getId(),mapAutoView.getMapController());
|
||||
}
|
||||
|
||||
markerOptions.setGps(opt.isGps())
|
||||
.position(new LonLatPoint(opt.getLongitude(), opt.getLatitude()))
|
||||
.anchor(opt.getU(), opt.getV())
|
||||
.icons(descriptors)
|
||||
.icons(descriptors,mapAutoView.getMapController())
|
||||
.period(opt.getPeriod())
|
||||
.controlAngle(opt.isControlAngle())
|
||||
.rotateAngle(opt.getRotate())
|
||||
@@ -84,10 +85,10 @@ public class ObjectUtils {
|
||||
} else {
|
||||
BitmapDescriptor descriptor = getBitmapDescriptorFromMogo(opt.getIcon(), opt.getIconView());
|
||||
if (descriptor != null) {
|
||||
markerOptions.markerIcon(descriptor);
|
||||
markerOptions.markerIcon(descriptor,mapAutoView.getMapController());
|
||||
}
|
||||
if (opt.getIcon3DRes() != 0) {
|
||||
markerOptions.marker3DIcon(opt.getIcon3DRes());
|
||||
markerOptions.marker3DIcon(opt.getIcon3DRes(),mapAutoView.getMapController());
|
||||
}
|
||||
}
|
||||
String title = opt.getTitle();
|
||||
@@ -170,11 +171,11 @@ public class ObjectUtils {
|
||||
return new MogoLatLng(point.getLatitude(), point.getLongitude());
|
||||
}
|
||||
|
||||
public static PolylineOptions fromMogo(Polyline.Options options) {
|
||||
public static PolylineOptions fromMogo(Polyline.Options options,MapAutoView mapAutoView) {
|
||||
if (options == null) {
|
||||
return null;
|
||||
}
|
||||
PolylineOptions target = new PolylineOptions();
|
||||
PolylineOptions target = new PolylineOptions(mapAutoView.getMapController());
|
||||
target.setGps(options.isUseGps());
|
||||
if (options.getPoints() != null) {
|
||||
List<LonLatPoint> points = new ArrayList<>();
|
||||
@@ -193,15 +194,15 @@ public class ObjectUtils {
|
||||
target.useFacade(options.getUseFacade());
|
||||
target.setVisible(options.isVisible());
|
||||
if (options.getMaxIndex() >= 0f) {
|
||||
target.maxIndex = options.getMaxIndex();
|
||||
target.maxIndex(options.getMaxIndex());
|
||||
}
|
||||
if (options.getColors() != null) {
|
||||
target.colorValues(options.getColors());
|
||||
}
|
||||
if (options.isLightOn()) {
|
||||
target.isBright = true;
|
||||
target.brightColor = options.getLightColor();
|
||||
target.brightSpeed = options.getLightSpeed();
|
||||
target.setIsBright(true);
|
||||
target.setBrightColor(options.getLightColor());
|
||||
target.setBrightSpeed(options.getLightSpeed());
|
||||
}
|
||||
return target;
|
||||
}
|
||||
@@ -223,23 +224,23 @@ public class ObjectUtils {
|
||||
CenterLine resultCenterLine = null;
|
||||
if (centerLine != null) {
|
||||
resultCenterLine = new CenterLine();
|
||||
resultCenterLine.setId(centerLine.id);
|
||||
resultCenterLine.setLane_id(centerLine.lane_id);
|
||||
resultCenterLine.setAngle(centerLine.angle);
|
||||
resultCenterLine.setRoad_id(centerLine.road_id);
|
||||
resultCenterLine.setTile_id(centerLine.tile_id);
|
||||
resultCenterLine.setId(centerLine.getId());
|
||||
resultCenterLine.setLane_id(centerLine.getLane_id());
|
||||
resultCenterLine.setAngle(centerLine.getAngle());
|
||||
resultCenterLine.setRoad_id(centerLine.getRoad_id());
|
||||
resultCenterLine.setTile_id(centerLine.getTile_id());
|
||||
ArrayList<com.mogo.eagle.core.data.map.LonLatPoint> arrayList = new ArrayList<>();
|
||||
if (centerLine.points != null) {
|
||||
for (com.zhidaoauto.map.sdk.open.query.LonLatPoint point : centerLine.points) {
|
||||
if (centerLine.getPoints() != null) {
|
||||
for (com.zhidaoauto.map.sdk.open.query.LonLatPoint point : centerLine.getPoints()) {
|
||||
com.mogo.eagle.core.data.map.LonLatPoint lonLatPoint = new com.mogo.eagle.core.data.map.LonLatPoint();
|
||||
lonLatPoint.setAltitude(point.altitude);
|
||||
lonLatPoint.setAngle(point.angle);
|
||||
lonLatPoint.setDistance(point.distance);
|
||||
lonLatPoint.setLatitude(point.latitude);
|
||||
lonLatPoint.setLongitude(point.longitude);
|
||||
lonLatPoint.setProvider(point.provider);
|
||||
lonLatPoint.setSpeed(point.speed);
|
||||
lonLatPoint.setDuration(point.duration);
|
||||
lonLatPoint.setAltitude(point.getAltitude());
|
||||
lonLatPoint.setAngle(point.getAngle());
|
||||
lonLatPoint.setDistance(point.getDistance());
|
||||
lonLatPoint.setLatitude(point.getLatitude());
|
||||
lonLatPoint.setLongitude(point.getLongitude());
|
||||
lonLatPoint.setProvider(point.getProvider());
|
||||
lonLatPoint.setSpeed(point.getSpeed());
|
||||
lonLatPoint.setDuration(point.getDuration());
|
||||
arrayList.add(lonLatPoint);
|
||||
}
|
||||
resultCenterLine.setPoints(arrayList);
|
||||
|
||||
Reference in New Issue
Block a user