312 lines
10 KiB
Java
312 lines
10 KiB
Java
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 com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
|
||
import com.mogo.map.center.CenterLine;
|
||
import com.mogo.map.overlay.proxy.line.IMapPolylineOverlay;
|
||
import com.mogo.map.overlay.proxy.point.IMapPointOverlay;
|
||
import com.mogo.map.overlay.wrapper.point.AMapPointWrapper;
|
||
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.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;
|
||
import com.zhidaoauto.map.sdk.open.poyline.PolylineOptions;
|
||
import com.zhidaoauto.map.sdk.open.query.LonLatPoint;
|
||
import com.zhidaoauto.map.sdk.open.tools.MapTools;
|
||
import com.zhidaoauto.map.sdk.open.view.MapAutoView;
|
||
import com.zhidaoauto.map.sdk.open.view.MapAutoViewHelper;
|
||
|
||
import java.util.ArrayList;
|
||
import java.util.Collections;
|
||
import java.util.HashMap;
|
||
import java.util.List;
|
||
|
||
import mogo.telematics.pad.MessagePad;
|
||
import mogo.yycp.api.proto.SocketDownData;
|
||
|
||
/**
|
||
* @author congtaowang
|
||
* @since 2019-12-18
|
||
* <p>
|
||
* 代理自研AMap
|
||
*/
|
||
public class AMapWrapper implements IMogoMap {
|
||
|
||
private static final String TAG = "AMapWrapper";
|
||
|
||
private static MapAutoViewHelper sAMap;
|
||
private final IMogoMapUIController mMapUIController;
|
||
private MapAutoViewHelper mAMap;
|
||
private final MapAutoView mMapView;
|
||
private IMogoUiSettings mUiSettings;
|
||
|
||
public AMapWrapper(MapAutoViewHelper map, MapAutoView mapView, IMogoMapUIController controller) {
|
||
CallerLogger.INSTANCE.i(TAG, "autoop--AMapWrapper: init" + this);
|
||
this.mAMap = map;
|
||
sAMap = map;
|
||
this.mMapView = mapView;
|
||
mMapUIController = controller;
|
||
// 设置实现自定义 info window
|
||
// MapAutoApi.INSTANCE.setInfoWindowAdapter(new AMapInfoWindowAdapter());
|
||
AMapUIController.getInstance().initClient(mMapUIController);
|
||
}
|
||
|
||
public static MapAutoViewHelper getAMap() {
|
||
return sAMap;
|
||
}
|
||
|
||
@Override
|
||
public IMogoUiSettings getUiSettings() {
|
||
if (!checkAMap()) {
|
||
return null;
|
||
}
|
||
if (mUiSettings == null) {
|
||
mUiSettings = new AMapUiSettingsWrapper(mAMap);
|
||
}
|
||
return mUiSettings;
|
||
}
|
||
|
||
@Override
|
||
public IMogoMapUIController getUIController() {
|
||
return mMapUIController;
|
||
}
|
||
|
||
@Override
|
||
public IMapPointOverlay addPoint(com.mogo.map.overlay.point.Point.Options options) {
|
||
if (!checkAMap()) {
|
||
return null;
|
||
}
|
||
MarkerOptions markerOptions = ObjectUtils.fromMogo(options);
|
||
if (markerOptions == null) {
|
||
CallerLogger.INSTANCE.e(TAG, "marker参数为空");
|
||
return null;
|
||
}
|
||
Marker delegate = mAMap.addMarker(markerOptions);
|
||
if (delegate == null) {
|
||
return null;
|
||
}
|
||
return new AMapPointWrapper(options.getId(), delegate);
|
||
}
|
||
|
||
@Override
|
||
public IMapPolylineOverlay addLine(com.mogo.map.overlay.line.Polyline.Options options) {
|
||
if (!checkAMap()) {
|
||
return null;
|
||
}
|
||
PolylineOptions polylineOptions = ObjectUtils.fromMogo(options);
|
||
if (polylineOptions == null) {
|
||
CallerLogger.INSTANCE.e(TAG, "polyline参数为空");
|
||
return null;
|
||
}
|
||
Polyline delegate = polylineOptions.lineWidth > 0 ? mAMap.drawThickLine(polylineOptions) : mAMap.drawLine(polylineOptions);
|
||
if (delegate == null) {
|
||
return null;
|
||
}
|
||
return new com.mogo.map.overlay.wrapper.line.AMapPolylineWrapper(options.getId(), delegate);
|
||
}
|
||
|
||
BatchMarkerOptions batchMarkerOptions = new BatchMarkerOptions();
|
||
|
||
@SuppressLint("NewApi")
|
||
@Override
|
||
public void updateBatchMarkerPosition(HashMap<String, MessagePad.TrackedObject> optionsArrayList) {
|
||
if (!checkAMap()) {
|
||
return;
|
||
}
|
||
if(optionsArrayList == null || optionsArrayList.size() == 0){
|
||
return;
|
||
}
|
||
ArrayList<MarkerSimpleData> markerOptionsArrayList = new ArrayList<>();
|
||
optionsArrayList.forEach((s, trackedObject) -> {
|
||
MarkerSimpleData markerOptions = ObjectUtils.fromTrafficData(trackedObject);
|
||
if (markerOptions != null) {
|
||
markerOptionsArrayList.add(markerOptions);
|
||
}
|
||
});
|
||
if(markerOptionsArrayList.size() == 0){
|
||
return;
|
||
}
|
||
long time = markerOptionsArrayList.get(0).getTime();
|
||
batchMarkerOptions.list = markerOptionsArrayList;
|
||
batchMarkerOptions.delayStrategy = false;
|
||
batchMarkerOptions.ruleAngle = FunctionBuildConfig.isBeautyMode ? 8.0f : 0f;
|
||
batchMarkerOptions.controlIcon = 1;
|
||
batchMarkerOptions.satelliteTime = time;
|
||
batchMarkerOptions.deleteRule = 0;
|
||
MarkerHelper.INSTANCE.updateBatchMarkerPositon(batchMarkerOptions);
|
||
}
|
||
|
||
BatchMarkerOptions aiBatchMarkerOptions = new BatchMarkerOptions();
|
||
|
||
@SuppressLint("NewApi")
|
||
@Override
|
||
public void updateBatchAiMarkerPosition(HashMap<String, SocketDownData.CloudRoadDataProto> optionsArrayList) {
|
||
if (!checkAMap()) {
|
||
return;
|
||
}
|
||
if(optionsArrayList == null || optionsArrayList.size() == 0){
|
||
return;
|
||
}
|
||
ArrayList<MarkerSimpleData> markerOptionsArrayList = new ArrayList<>();
|
||
optionsArrayList.forEach((s, trackedObject) -> {
|
||
MarkerSimpleData markerOptions = ObjectUtils.fromAiData(trackedObject);
|
||
if (markerOptions != null) {
|
||
markerOptionsArrayList.add(markerOptions);
|
||
}
|
||
});
|
||
if(markerOptionsArrayList.size() == 0){
|
||
return;
|
||
}
|
||
long time = markerOptionsArrayList.get(0).getTime();
|
||
// 最后一个参数,是否管理锚点的删除
|
||
aiBatchMarkerOptions.list = markerOptionsArrayList;
|
||
aiBatchMarkerOptions.delayStrategy = false;
|
||
aiBatchMarkerOptions.ruleAngle = FunctionBuildConfig.isBeautyMode ? 8.0f : 0f;
|
||
aiBatchMarkerOptions.controlIcon = 1;
|
||
aiBatchMarkerOptions.satelliteTime = time;
|
||
aiBatchMarkerOptions.deleteRule = 0;
|
||
MarkerHelper.INSTANCE.updateBatchMarkerPositon(aiBatchMarkerOptions);
|
||
}
|
||
|
||
@Override
|
||
public String addPreVehicleModel(int type, int modelRes) {
|
||
try {
|
||
return MarkerHelper.INSTANCE.addPreVehicleModel(type, modelRes);
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
return null;
|
||
}
|
||
|
||
@Override
|
||
public void removeMarker(String uuidString) {
|
||
try {
|
||
MarkerHelper.INSTANCE.removeMarker(uuidString);
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public void clear() {
|
||
if (checkAMap()) {
|
||
mAMap.clearPanel();
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public void clear(boolean isKeepMyLocationOverlay) {
|
||
if (checkAMap()) {
|
||
mAMap.clearPanel();
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public void setPointToCenter(int x, int y) {
|
||
if (checkAMap()) {
|
||
LonLatPoint lonLatPoint = MapTools.INSTANCE.fromScreenLocation(new Point(x, y));
|
||
mAMap.setCenter(lonLatPoint);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public float getScalePerPixel() {
|
||
if (checkAMap()) {
|
||
return mAMap.getScalePerPixel();
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
@Override
|
||
public void changeZoom(float zoom) {
|
||
CallerLogger.INSTANCE.d(TAG, "changeZoom %s", zoom);
|
||
if (checkAMap()) {
|
||
mAMap.setZoom((int) zoom);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public void changeZoom2(float zoom) {
|
||
CallerLogger.INSTANCE.d(TAG, "changeZoom %s", zoom);
|
||
if (checkAMap()) {
|
||
mAMap.setZoomVal(zoom);
|
||
}
|
||
}
|
||
|
||
@Override
|
||
public float getZoomLevel() {
|
||
if (checkAMap()) {
|
||
try {
|
||
return mAMap.getZoom();
|
||
} catch (Exception ignored) {
|
||
|
||
}
|
||
}
|
||
return 0;
|
||
}
|
||
|
||
private boolean checkAMap() {
|
||
mAMap = mMapView.getMapAutoViewHelper();
|
||
sAMap = mAMap;
|
||
if (mAMap == null) {
|
||
CallerLogger.INSTANCE.e(TAG, "自研map实例为空,请检查");
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
@Override
|
||
public float getRoadWidth(double lon, double lat, float angle, boolean isGpsLocation, boolean isRTK) {
|
||
SinglePointRoadInfo singlePointRoadInfo = MapDataApi.INSTANCE.getSinglePointMatchRoad(lon, lat, angle, isGpsLocation, isRTK);
|
||
|
||
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) {
|
||
// com.zhidaoauto.map.sdk.open.road.RoadNameInfo info = MapDataApi.INSTANCE.getRoadName(lon, lat, angle);
|
||
// RoadNameInfo ret = null;
|
||
// if (info != null) {
|
||
// ret = new RoadNameInfo(info.tile_id, info.road_id, info.road_name);
|
||
// }
|
||
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;
|
||
}
|
||
}
|