286 lines
9.4 KiB
Java
286 lines
9.4 KiB
Java
package com.mogo.map;
|
||
|
||
import android.annotation.SuppressLint;
|
||
import android.graphics.Point;
|
||
|
||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger;
|
||
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.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.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.HashMap;
|
||
|
||
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 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;
|
||
this.mMapView = mapView;
|
||
mMapUIController = controller;
|
||
// 设置实现自定义 info window
|
||
// MapAutoApi.INSTANCE.setInfoWindowAdapter(new AMapInfoWindowAdapter());
|
||
AMapUIController.getInstance().initClient(mMapUIController);
|
||
}
|
||
|
||
@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,mMapView);
|
||
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,mMapView);
|
||
}
|
||
|
||
@Override
|
||
public IMapPolylineOverlay addLine(com.mogo.map.overlay.line.Polyline.Options options) {
|
||
if (!checkAMap()) {
|
||
return null;
|
||
}
|
||
PolylineOptions polylineOptions = ObjectUtils.fromMogo(options,mMapView);
|
||
if (polylineOptions == null) {
|
||
CallerLogger.INSTANCE.e(TAG, "polyline参数为空");
|
||
return null;
|
||
}
|
||
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,mMapView);
|
||
}
|
||
|
||
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.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();
|
||
|
||
@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.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 {
|
||
if(mMapView.getMarkerController() != null){
|
||
return mMapView.getMarkerController().addPreVehicleModel(type, modelRes);
|
||
}
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
return null;
|
||
}
|
||
|
||
@Override
|
||
public void removeMarker(String uuidString) {
|
||
try {
|
||
if(mMapView.getMarkerController() != null){
|
||
mMapView.getMarkerController().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), mMapView.getMapController());
|
||
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();
|
||
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) {
|
||
|
||
}
|
||
|
||
@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;
|
||
}
|
||
|
||
}
|