From d60db982df107d942ee8cca82e06975465434f36 Mon Sep 17 00:00:00 2001 From: zhongchao Date: Mon, 11 Sep 2023 15:58:53 +0800 Subject: [PATCH] merge --- .../map/sdk/open/abs/OnMapLoadedListener.kt | 2 +- .../java/com/mogo/map/AMapViewWrapper.java | 1166 ----------------- .../main/java/com/mogo/map/AMapWrapper.java | 182 +-- .../com/mogo/map/MogoMapUIController.java | 522 -------- 4 files changed, 36 insertions(+), 1836 deletions(-) delete mode 100644 libraries/mogo-map/src/main/java/com/mogo/map/AMapViewWrapper.java delete mode 100644 libraries/mogo-map/src/main/java/com/mogo/map/MogoMapUIController.java diff --git a/libraries/mapmodule/src/main/java/com/zhidaoauto/map/sdk/open/abs/OnMapLoadedListener.kt b/libraries/mapmodule/src/main/java/com/zhidaoauto/map/sdk/open/abs/OnMapLoadedListener.kt index 1d591ce038..4ddcdc9376 100644 --- a/libraries/mapmodule/src/main/java/com/zhidaoauto/map/sdk/open/abs/OnMapLoadedListener.kt +++ b/libraries/mapmodule/src/main/java/com/zhidaoauto/map/sdk/open/abs/OnMapLoadedListener.kt @@ -3,5 +3,5 @@ package com.zhidaoauto.map.sdk.open.abs interface OnMapLoadedListener { fun onMapInit() fun onMapLoaded() - fun onRoadLoaded(roadInfo:String?) + fun onRoadLoaded(roadInfo:String?){} } \ No newline at end of file diff --git a/libraries/mogo-map/src/main/java/com/mogo/map/AMapViewWrapper.java b/libraries/mogo-map/src/main/java/com/mogo/map/AMapViewWrapper.java deleted file mode 100644 index 3ecde6eca0..0000000000 --- a/libraries/mogo-map/src/main/java/com/mogo/map/AMapViewWrapper.java +++ /dev/null @@ -1,1166 +0,0 @@ -package com.mogo.map; - -import static com.mogo.eagle.core.data.deva.chain.ChainConstant.CHAIN_CODE_HD_MAP_CALL; -import static com.mogo.eagle.core.data.deva.chain.ChainConstant.CHAIN_CODE_INIT_ON_MAP_INIT; -import static com.mogo.eagle.core.data.deva.chain.ChainConstant.CHAIN_CODE_INIT_ON_MAP_LOADED; -import static com.mogo.eagle.core.data.deva.chain.ChainConstant.CHAIN_CODE_ROMA_MODE_INVOKE; -import static com.mogo.eagle.core.data.deva.chain.ChainConstant.CHAIN_CODE_ROMA_REQUEST_OK; -import static com.mogo.eagle.core.data.deva.chain.ChainConstant.CHAIN_SOURCE_INIT; -import static com.mogo.eagle.core.data.deva.chain.ChainConstant.CHAIN_SOURCE_MAP; -import static com.mogo.eagle.core.data.deva.chain.ChainConstant.CHAIN_TYPE_HD_MAP; -import static com.mogo.eagle.core.data.deva.chain.ChainConstant.CHAIN_TYPE_INIT_STATUS; -import static com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant.M_MAP; -import static com.mogo.map.uicontroller.VisualAngleMode.MAP_STYLE_VR_ANGLE_300; -import static com.mogo.map.uicontroller.VisualAngleMode.MAP_STYLE_VR_ANGLE_CROSS; -import static com.mogo.map.uicontroller.VisualAngleMode.MAP_STYLE_VR_ANGLE_TOP; -import static com.mogo.map.uicontroller.VisualAngleMode.MAP_STYLE_VR_ROMA; -import static com.mogo.map.uicontroller.VisualAngleMode.MODE_CLOSE_SIGHT; -import static com.mogo.map.uicontroller.VisualAngleMode.MODE_LONG_SIGHT; -import static com.mogo.map.uicontroller.VisualAngleMode.MODE_MEDIUM_SIGHT; - -import android.content.Context; -import android.graphics.Point; -import android.graphics.Rect; -import android.os.Bundle; -import android.os.Looper; -import android.text.TextUtils; -import android.view.MotionEvent; -import android.view.View; - -import androidx.annotation.NonNull; - -import com.mogo.eagle.core.data.config.HdMapBuildConfig; -import com.mogo.eagle.core.data.enums.TrafficTypeEnum; -import com.mogo.eagle.core.data.map.CenterLine; -import com.mogo.eagle.core.data.map.MapRoadInfo; -import com.mogo.eagle.core.data.map.MogoLatLng; -import com.mogo.eagle.core.data.map.MogoLocation; -import com.mogo.eagle.core.function.call.autopilot.CallerChassisLocationWGS84ListenerManager; -import com.mogo.eagle.core.function.call.map.CallerMapDataCollectorManager; -import com.mogo.eagle.core.function.call.map.CallerMapDevaListenerManager; -import com.mogo.eagle.core.function.call.map.CallerMapRoadListenerManager; -import com.mogo.eagle.core.function.call.map.CallerMapRomaListener; -import com.mogo.eagle.core.function.call.map.CallerMapStyleListenerManager; -import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger; -import com.mogo.eagle.core.utilcode.util.ThreadUtils; -import com.mogo.eagle.core.utilcode.util.UiThreadHandler; -import com.mogo.map.hdcache.IHdCacheListener; -import com.mogo.map.identify.MogoIdentifyManager; -import com.mogo.map.listener.MogoMapListenerHandler; -import com.mogo.map.location.GDLocationClient; -import com.mogo.map.uicontroller.CarCursorOption; -import com.mogo.map.uicontroller.EnumMapUI; -import com.mogo.map.uicontroller.IMogoMapUIController; -import com.mogo.map.uicontroller.MapCameraPosition; -import com.mogo.map.uicontroller.MapControlResult; -import com.mogo.map.uicontroller.VisualAngleMode; -import com.mogo.map.utils.HDMapUtils; -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.MapStatusListener; -import com.zhidaoauto.map.sdk.open.abs.OnCameraChangeListener; -import com.zhidaoauto.map.sdk.open.abs.OnHdDataDownByCityListener; -import com.zhidaoauto.map.sdk.open.abs.OnMapClickListener; -import com.zhidaoauto.map.sdk.open.abs.OnMapLoadedListener; -import com.zhidaoauto.map.sdk.open.abs.OnMapStyleListener; -import com.zhidaoauto.map.sdk.open.abs.OnMapTouchListener; -import com.zhidaoauto.map.sdk.open.abs.OnMapViewVisualAngleChangeListener; -import com.zhidaoauto.map.sdk.open.abs.OnRoadInfoListener; -import com.zhidaoauto.map.sdk.open.abs.OnRoamStatusListener; -import com.zhidaoauto.map.sdk.open.abs.log.ILog; -import com.zhidaoauto.map.sdk.open.business.PointCloudHelper; -import com.zhidaoauto.map.sdk.open.camera.CameraPosition; -import com.zhidaoauto.map.sdk.open.camera.CameraUpdateFactory; -import com.zhidaoauto.map.sdk.open.camera.LatLngBounds; -import com.zhidaoauto.map.sdk.open.data.CityInfo; -import com.zhidaoauto.map.sdk.open.data.MapDataApi; -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.StopLine; -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 com.zhjt.service.chain.ChainLog; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.List; - - -public class AMapViewWrapper implements IMogoMapView, - IMogoMapUIController, - OnMapLoadedListener, - MapStatusListener, - OnCameraChangeListener, - OnMapClickListener, - OnMapTouchListener, - OnMarkClickListener, - OnMapStyleListener, - OnMapViewVisualAngleChangeListener, - OnRoadInfoListener, - ILog, OnRoamStatusListener { - - private static final String TAG = "AMapViewWrapper"; - private final MapAutoView mMapView; - private final IMogoMap mIMap; - private final CarCursorOption DEFAULT_OPTION = new CarCursorOption.Builder() - .carCursorRes(R.drawable.map_api_ic_current_location2) - .naviCursorRes(R.drawable.ic_amap_navi_cursor) - .build(); - private CarCursorOption mCarCursorOption = DEFAULT_OPTION; - private EnumMapUI mCurrentUI = EnumMapUI.MAP_STYLE_NIGHT_VR; - private VisualAngleMode mVisualAngleMode = MODE_MEDIUM_SIGHT; - - private IHdCacheListener hdCacheListener; - - public AMapViewWrapper(MapAutoView mMapView) { - CallerLogger.i(M_MAP + TAG, "autoop--AMapViewWrapper: init"); - this.mMapView = mMapView; - initViews(); - initListeners(); - this.mIMap = new AMapWrapper(this.mMapView.getMapAutoViewHelper(), this.mMapView, this); - } - - private void initViews() { - // 初始化首次地图进入的时候的样式, MapAutoApi.INSTANCE.init(context, mapParams);将影响这里的数据 - int mapStyle = MapAutoApi.INSTANCE.getMapParams().getStyleMode(); - CallerLogger.d(M_MAP + TAG, "默认配置地图模式:mapStyle=" + mapStyle); - switch (mapStyle) { - case MapAutoApi.MAP_STYLE_DAY: - mCurrentUI = EnumMapUI.MAP_STYLE_DAY; - break; - case MapAutoApi.MAP_STYLE_DAY_NAV: - mCurrentUI = EnumMapUI.MAP_STYLE_DAY_NAV; - break; - case MapAutoApi.MAP_STYLE_NIGHT: - mCurrentUI = EnumMapUI.MAP_STYLE_NIGHT; - break; - case MapAutoApi.MAP_STYLE_NIGHT_NAV: - mCurrentUI = EnumMapUI.MAP_STYLE_NIGHT_NAV; - break; - case MapAutoApi.MAP_STYLE_DAY_VR: - mCurrentUI = EnumMapUI.MAP_STYLE_DAY_VR; - break; - case MapAutoApi.MAP_STYLE_NIGHT_VR: - mCurrentUI = EnumMapUI.MAP_STYLE_NIGHT_VR; - break; - default: - CallerLogger.e(M_MAP + TAG, "暂不支持此地图模式,默认使用VR夜间模式"); - } - - } - - private void initMapView() { - if (mMapView == null) { - return; - } - MapAutoViewHelper options = mMapView.getMapAutoViewHelper(); - ThreadUtils.getIoPool().submit(() -> { - if (options != null) { - //设置手势是否可以缩放 isCanZoom true 可缩放 false 不可缩放 - options.setZoomGesturesEnabled(true); - options.setScaleVRMode(true); - options.setWeatherEnable(false); -// options.setAllGesturesEnabled(false); //禁止全部手势 - if (options.getMyLocationStyle() != null) { - options.getMyLocationStyle().setDisplayAnimEnable(true); - } - //修改自车模型,未来需区分车的类型 - options.setMyLocationStyle(options.getMyLocationStyle().myLocationIcon(HdMapBuildConfig.currentCarVrIconRes, true)); - } - }); - } - - private void initListeners() { - mMapView.setOnMarkClickListener(this); - mMapView.setOnMapLoadedListener(this); - mMapView.setOnMapTouchListener(this); - mMapView.setOnMapClickListener(this); - mMapView.registerListener(this, MapAutoApi.LISTENER_TYPE_ZOOM); - mMapView.registerListener(this, MapAutoApi.LISTENER_TYPE_ROTATE); - mMapView.registerListener(this, MapAutoApi.LISTENER_TYPE_3D); - mMapView.setOnCameraChangeListener(this); - mMapView.setOnMapStyleListener(this); - mMapView.setOnRoamStatusListener(this); - mMapView.setOnMapViewVisualAngleChangeListener(this); - mMapView.setOnRoadInfoListener(this, 1); - MapAutoApi.INSTANCE.registerLogListener(this); - CallerLogger.d(M_MAP + TAG, "styleop - initListeners - setOnMapStyleListener - view " + mMapView); - } - - /** - * 修改获取当前车道号 - * - * @param roadId - * @param s1 - */ - @Override - public void onRoadIdInfo(@androidx.annotation.Nullable String roadId, @androidx.annotation.Nullable String s1) { - if (roadId != null && !TextUtils.isEmpty(roadId)) { - // CallerLogger.d(M_MAP + TAG, "onRoadIdInfo::" + roadId); - CallerMapRoadListenerManager.INSTANCE.invokeListenersOnRoadIdGet(roadId); - } else { - //CallerLogger.d(M_MAP + TAG, "onRoadIdInfo::null"); - } - } - - @Override - public void onRoadCrossInfo(@androidx.annotation.Nullable RoadCross roadCross) { - - } - - @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 points = stopLine.points; - if (carLoc != null) { -// //CallerLogger.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; - stopInfo.setDistanceOfCarToStopLine(distanceOfCarToStopLine); - //CallerLogger.d(M_MAP + TAG, "onStopLineInfo: --- distance: " + distanceOfCarToStopLine); - CallerMapRoadListenerManager.INSTANCE.invokeListenersOnStopLineGet(stopInfo); - } - } else { - if (carLoc != null) { - //CallerLogger.d(M_MAP + TAG, "onStopLineInfo::null, car_loc:{lon: " + carLoc.getLatitude() + ", lat: " + carLoc.getLongitude() + "}"); - } - } - } - - 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 points = line.points; - if (points != null && points.size() > 0) { - List 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; - newPoints.add(latLng); - } - ret.setPoints(newPoints); - } - return ret; - } - - - private Context getContext() { - return mMapView.getContext(); - } - - @Override - public View getMapView() { - return mMapView; - } - - @Override - public IMogoMap getMap() { - return mIMap; - } - - @Override - public void onCreate(Bundle bundle) { - if (mMapView != null) { - mMapView.onCreate(bundle); - CallerLogger.d(M_MAP + TAG, "map onCreate"); - } - } - - @Override - public void onResume() { - if (mMapView != null) { - mMapView.onResume(); - CallerLogger.d(M_MAP + TAG, "map onResume"); - } - } - - @Override - public void onPause() { - if (mMapView != null) { - mMapView.onPause(); - CallerLogger.d(M_MAP + TAG, "map onPause"); - } - } - - @Override - public void onDestroy() { - if (mMapView != null) { - mMapView.onDestroy(); - mMapView.setOnMarkClickListener(null); - mMapView.setOnMapLoadedListener(null); - mMapView.setOnMapTouchListener(null); - mMapView.setOnMapClickListener(null); - mMapView.setOnCameraChangeListener(null); - MapAutoApi.INSTANCE.unregisterLogListener(this); - CallerLogger.d(M_MAP + TAG, "map onDestroy"); - } - - } - - @Override - public void onSaveInstanceState(Bundle outState) { - if (mMapView != null) { - mMapView.onSaveInstanceState(outState); - CallerLogger.d(M_MAP + TAG, "map onSaveInstanceState"); - } - } - - @Override - public void onLowMemory() { - - } - - @Override - public MapControlResult changeZoom(float zoom) { - if (isVrMold()) { - return MapControlResult.ERROR; - } - CallerLogger.d(M_MAP + TAG, "changeZoom : " + zoom); - getMap().changeZoom(zoom); - return MapControlResult.SUCCESS; - } - - @Override - public void changeZoom2(float zoom) { -// if (isVrMold()) { -// return; -// } - CallerLogger.d(M_MAP + TAG, "changeZoom2 : " + zoom); - getMap().changeZoom2(zoom); - } - - @Override - public void setDebugMode(Boolean debugMode) { - MapAutoApi.INSTANCE.setDebugMode(debugMode); - } - - @Override - public void changeMapVisualAngle(VisualAngleMode angelMode, MogoLatLng mogoLatLng) { - MapAutoViewHelper mapAutoViewHelper = mMapView.getMapAutoViewHelper(); - if (mapAutoViewHelper != null) { - mVisualAngleMode = angelMode; - if (angelMode == MODE_CLOSE_SIGHT) { - if (mogoLatLng == null) { - CallerLogger.e(M_MAP + TAG, "切换地图近景需要传入要移动的经纬度数据"); - return; - } - // 近景传入经纬度为点击地图上静态marker经纬度数据,为GPS坐标点。 - mapAutoViewHelper.setNearViewAnglePosition(new LonLatPoint(mogoLatLng.lon, mogoLatLng.lat), true); - } else { - mapAutoViewHelper.setMapViewVisualAngle(angelMode.getCode()); - } - } - } - - @ChainLog( - linkChainLog = CHAIN_TYPE_HD_MAP, - linkCode = CHAIN_SOURCE_MAP, - nodeAliasCode = CHAIN_CODE_HD_MAP_CALL, - paramIndexes = {0} - ) - @Override - public void setRoamTrajectory(String trajectory) { - if (checkAMapView()) { - mMapView.getMapAutoViewHelper().setRoamTrajectory(trajectory); - } - } - - @ChainLog( - linkChainLog = CHAIN_TYPE_HD_MAP, - linkCode = CHAIN_SOURCE_MAP, - parentNodeAliasCode = CHAIN_CODE_ROMA_REQUEST_OK, - nodeAliasCode = CHAIN_CODE_ROMA_MODE_INVOKE, - paramIndexes = {0}, - endPoint = false - ) - @Override - public void setRomaMode(int mode) { - if (checkAMapView()) { - mMapView.getMapAutoViewHelper().setRoamStyle(mode, 1800, MapAutoApi.ROAM_SPEED_40); - } - } - - @Override - public VisualAngleMode getCurrentMapVisualAngle() { - return mVisualAngleMode; - } - - @Override - public void moveToCenter(MogoLatLng latLng) { - moveToCenter(latLng, true); - } - - private boolean checkAMapView() { - if (mMapView == null || mMapView.getMapAutoViewHelper() == null) { - CallerLogger.e(M_MAP + TAG, "自研mapView实例为空,请检查"); - return false; - } - return true; - } - - @Override - public void moveToCenter(MogoLatLng latLng, boolean animate) { - CallerLogger.d(M_MAP + TAG, "move to center " + latLng); - if (latLng == null || latLng.lat == 0.0d || latLng.lon == 0.0d) { - CallerLogger.e(M_MAP + TAG, "latLng = null or is illegal"); - return; - } - if (checkAMapView()) { - mMapView.getMapAutoViewHelper().animateCamera(new LonLatPoint(latLng.lon, latLng.lat)); - } - } - - @Override - public void showMyLocation(boolean visible) { - CallerLogger.d(M_MAP + TAG, "showMyLocation1 " + visible); - // 如果是VR模式 - if (isVrMold()) { - return; - } - // 不是VR模式情况强制刷新下 - if (checkAMapView()) { - MyLocationStyle style = mMapView.getMapAutoViewHelper().getMyLocationStyle(); - if (visible) { - // 强制刷新一遍车标 - style.myLocationIcon(mCarCursorOption.getCarCursorRes()); - } - mMapView.getMapAutoViewHelper().setMyLocationStyle(style); - } - } - - /** - * @return true-是,false=不是 - */ - private boolean isVrMold() { - boolean isVrMode = mCurrentUI == EnumMapUI.MAP_STYLE_NIGHT_VR || mCurrentUI == EnumMapUI.MAP_STYLE_DAY_VR; - CallerLogger.d(M_MAP + TAG, "是否是VR模式: " + isVrMode); - return isVrMode; - } - - /** - * 是否是白天模式 - * - * @return true-是,false-不是 - */ - @Override - public boolean isDayMode() { - return mCurrentUI == EnumMapUI.MAP_STYLE_DAY_VR - || mCurrentUI == EnumMapUI.MAP_STYLE_DAY - || mCurrentUI == EnumMapUI.MAP_STYLE_DAY_NAV; - } - - @Override - public void showMyLocation(View view) { - if (checkAMapView()) { - MyLocationStyle style = mMapView.getMapAutoViewHelper().getMyLocationStyle(); - style.myLocationIcon(BitmapDescriptorFactory.INSTANCE.convertViewToBitmap(view)); - mMapView.getMapAutoViewHelper().setMyLocationStyle(style); - } - } - - public void initMyLocation() { - if (checkAMapView()) { - MarkerHelper.INSTANCE.addPreModel(R.raw.guangquan); -// MarkerHelper.addPreModel(R.raw.guangquan_day) - mMapView.getMapAutoViewHelper().setMyLocationEnabled(true); - } - } - - - @Override - public float getScalePerPixel() { - return getMap().getScalePerPixel(); - } - - @Override - public float getZoomLevel() { - return getMap().getZoomLevel(); - } - - @Override - public float getRoadWidth(double lon, double lat, float angle, boolean isGpsLocation, boolean isRTK) { - return getMap().getRoadWidth(lon, lat, angle, isGpsLocation, isRTK); - } - - @Override - public MogoLatLng getCameraNorthEastPosition() { - return ObjectUtils.fromAMap(MapTools.INSTANCE.getVisibleRegion().getRightTopPoint()); - } - - @Override - public MogoLatLng getCameraSouthWestPosition() { - try { - return ObjectUtils.fromAMap(MapTools.INSTANCE.getVisibleRegion().getLeftBottomPoint()); - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - @Override - public MogoLatLng getWindowCenterLocation() { - try { - if (checkAMapView()) { - return ObjectUtils.fromAMap(mMapView.getMapAutoViewHelper().getCenter()); - } - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - @Override - public void setPointToCenter(double mapCenterX, double mapCenterY) { - if (checkAMapView()) { - if (isVrMold()) { - return; - } - CallerLogger.d(M_MAP + TAG, "setPointToCenter x : " + mapCenterX + " y : " + mapCenterY); - mMapView.getMapAutoViewHelper().setPointToCenter((float) mapCenterX, (float) mapCenterY); - } - } - - @Override - public Point getLocationPointInScreen(MogoLatLng latLng) { - if (checkAMapView()) { - try { - return MapTools.INSTANCE.toScreenLocation(ObjectUtils.fromMogo(latLng)); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - return null; - } - - @Override - public MogoLatLng getLocationMogoLatLngInScreen(Point point) { - if (checkAMapView()) { - try { - return ObjectUtils.fromAMap( - MapTools.INSTANCE.fromScreenLocation(point)); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - return null; - } - - @Override - public void setRenderFps(int fps) { - if (checkAMapView()) { - if (mMapView.getMapAutoViewHelper() != null) { - mMapView.getMapAutoViewHelper().setRenderFps(fps); - CallerLogger.d(M_MAP + TAG, "设置刷新帧率 fps = " + fps); - } - } - } - - @Override - public void showBounds(String tag, MogoLatLng carPosition, List lonLats, Rect bound, boolean lockCarPosition) { - if (!checkAMapView()) { - return; - } - if (isVrMold()) { - CallerLogger.w(M_MAP + TAG, "vr 模式下忽略该设置"); - return; - } - CallerLogger.i(M_MAP + TAG, "showBounds : " + M_MAP + TAG + " , " + carPosition.toString() + " , " + bound.toShortString() + " , " + lockCarPosition); - try { - LatLngBounds latLngBounds = MogoMapUtils.getLatLngBounds(carPosition, lonLats, lockCarPosition); - mMapView.getMapAutoViewHelper().setCenter(ObjectUtils.fromMogo(carPosition)); - mMapView.getMapAutoViewHelper().moveCamera(CameraUpdateFactory.INSTANCE.newLatLngBounds(latLngBounds, bound.left, bound.right, bound.top, bound.bottom)); - } catch (Exception e) { - CallerLogger.e(M_MAP + TAG, "M_MAP+TAG : " + M_MAP + TAG + " error : " + e); - } - } - - @Override - public void forceRender() { - if (checkAMapView()) { - mMapView.getMapAutoViewHelper().runOnDrawFrame(); - } - } - - @Override - public float calculateLineDistance(MogoLatLng p1, MogoLatLng p2) throws Exception { - if (p1 == null || p2 == null) { - throw new Exception("计算距离的点不能为 null"); - } - return MogoMapUtils.calculateLineDistance(ObjectUtils.fromMogo(p1), ObjectUtils.fromMogo(p2)); - } - - @Override - public synchronized boolean isCarLocked() { - return mMapView.getMapAutoViewHelper().getLockMode(); - } - - @Override - public void setCarCursorOption(CarCursorOption option) { - if (isVrMold()) { - return; - } - if (mCarCursorOption != null && mCarCursorOption != DEFAULT_OPTION) { - mCarCursorOption.destroy(); - } - if (option != null) { - try { - mCarCursorOption = option.clone(); - } catch (Exception e) { - mCarCursorOption = DEFAULT_OPTION; - } - } else { - mCarCursorOption = DEFAULT_OPTION; - } - if (!checkAMapView()) { - return; - } - - if (mMapView.getMapAutoViewHelper() == null) { - return; - } - MyLocationStyle style = mMapView.getMapAutoViewHelper().getMyLocationStyle(); - if (mCarCursorOption.getCarCursorBmp() != null && !mCarCursorOption.getCarCursorBmp().isRecycled()) { - style.myLocationIcon(mCarCursorOption.getCarCursorBmp()); - } else { - if (mCarCursorOption.getCarCursorRes() != 0) { - style.myLocationIcon(mCarCursorOption.getCarCursorRes()); - } - } - mMapView.getMapAutoViewHelper().setMyLocationStyle(style); - } - - /** - * 设置转向灯和刹车灯 - * - * @param type :车尾灯类型 - * @param time 闪烁时间 最小500ms 小于500ms 默认为500ms - */ - @Override - public void setCarLightsType(int type, int time) { - if (checkAMapView()) { - mMapView.getMapAutoViewHelper().setTailLightsType(type, time); - } - } - - @Override - public MapCameraPosition getMapCameraPosition() { - if (checkAMapView()) { - CameraPosition cameraPosition = mMapView.getMapAutoViewHelper().getCameraPosition(); - return ObjectUtils.fromAMap(cameraPosition); - } - return null; - } - - @Override - public void changeBearing(float bearing) { - if (checkAMapView()) { - mMapView.getMapAutoViewHelper().setMapViewRotation(bearing); - } - } - - @Override - public void changeMapViewAngle(int type) { - } - - @Override - public void changeCurrentIcon(int iconId) { - if (checkAMapView()) { - mMapView.getMapAutoViewHelper().getMyLocationStyle().myLocationIcon(iconId, true); - } - } - - @Override - public long getTileId(double lon, double lat) { - 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) { - CallerMapDevaListenerManager.INSTANCE.invokeUploadLogFile(filePath); - } - - @Override - public void onMapClick(@Nullable LonLatPoint lonLatPoint) { - MogoMapListenerHandler.Companion.getMogoMapListenerHandler().onMapClick(ObjectUtils.fromAMap(lonLatPoint)); - } - - - @ChainLog( - linkChainLog = CHAIN_TYPE_INIT_STATUS, - linkCode = CHAIN_SOURCE_INIT, - nodeAliasCode = CHAIN_CODE_INIT_ON_MAP_INIT, - paramIndexes = {-1} - ) - @Override - public void onMapInit() { - CallerLogger.i(M_MAP + TAG, "autoop--onMapInit: "); - MogoMapListenerHandler.Companion.getMogoMapListenerHandler().onMapLoaded(); - } - - @ChainLog( - linkChainLog = CHAIN_TYPE_INIT_STATUS, - linkCode = CHAIN_SOURCE_INIT, - nodeAliasCode = CHAIN_CODE_INIT_ON_MAP_LOADED, - paramIndexes = {-1} - ) - @Override - public void onMapLoaded() { - CallerLogger.i(M_MAP + TAG, "autoop--onMapLoaded: "); - if (checkAMapView()) { - CameraPosition cameraPosition = mMapView.getMapAutoViewHelper().getCameraPosition(); - MogoMapListenerHandler.Companion.getMogoMapListenerHandler().onMapChanged(ObjectUtils.fromAMap(cameraPosition.getTarget()), - cameraPosition.getZoom(), - cameraPosition.getTilt(), - cameraPosition.getBearing()); - initMapView(); - initMyLocation(); - loadPreVehicleModel(); - } - } - - @Override - public boolean onTouch(@Nullable MotionEvent motionEvent) { - MogoMapListenerHandler.Companion.getMogoMapListenerHandler().onTouch(motionEvent); - return false; - } - - @Override - public void onMarkClick(@NotNull Marker markerInfo) { -// mMarkerClickHandler.handleMarkerClicked(markerInfo); - } - - @Override - public void onRoadLoaded(@Nullable String s) { - } - - @Override - public void onMapStatusChanged(int type, int value) { - } - - @Override - public void onRoamStatus(int status, @NonNull String msg) { - CallerMapRomaListener.INSTANCE.invokeMapRomaStatus(status, msg); - } - - @Override - public void onMapViewVisualAngleChange(int i) { - CallerLogger.d(M_MAP + TAG, " 地图自动更改视距 currentThread : " + Thread.currentThread().getName()); - mVisualAngleMode = getVisualAngleMode(i); - MogoMapListenerHandler.Companion.getMogoMapListenerHandler().onMapVisualAngleChanged(mVisualAngleMode); - } - - /** - * 获取当前视距类型 - * - * @param mode 当前类型 - * @return 当前类型 - */ - private VisualAngleMode getVisualAngleMode(int mode) { - switch (mode) { - case 0: - return MODE_CLOSE_SIGHT; - case 1: - return MODE_MEDIUM_SIGHT; - case 2: - return MODE_LONG_SIGHT; - case 3: - return MAP_STYLE_VR_ANGLE_300; - case 4: - return MAP_STYLE_VR_ANGLE_TOP; - case 5: - return MAP_STYLE_VR_ANGLE_CROSS; - case 7: - return MAP_STYLE_VR_ROMA; - default: - return MODE_MEDIUM_SIGHT; - } - } - - @Override - public void onCameraChange(int type, int value) { - } - - @Override - public void onCameraChangeFinish(@Nullable CameraPosition cameraPosition) { - if (cameraPosition != null) { - MogoMapListenerHandler.Companion.getMogoMapListenerHandler().onMapChanged(ObjectUtils.fromAMap(cameraPosition.getTarget()), - cameraPosition.getZoom(), - cameraPosition.getTilt(), - cameraPosition.getBearing()); - } - } - - @Override - public void onChangeMapStyle(int styleId) { - CallerLogger.d(M_MAP + TAG, "currentMapStyle = " + styleId); - // 映射地图样式ID到鹰眼样式ID - if (styleId == MapAutoApi.MAP_STYLE_DAY - || styleId == MapAutoApi.MAP_STYLE_DAY_NAV) { - mCurrentUI = EnumMapUI.MAP_STYLE_DAY_NAV; - } else if (styleId == MapAutoApi.MAP_STYLE_NIGHT) { - mCurrentUI = EnumMapUI.MAP_STYLE_NIGHT; - } else if (styleId == MapAutoApi.MAP_STYLE_NIGHT_NAV) { - mCurrentUI = EnumMapUI.MAP_STYLE_NIGHT_NAV; - } else if (styleId == MapAutoApi.MAP_STYLE_NIGHT_VR) { - mCurrentUI = EnumMapUI.MAP_STYLE_NIGHT_VR; - } else if (styleId == MapAutoApi.MAP_STYLE_DAY_VR) { - mCurrentUI = EnumMapUI.MAP_STYLE_DAY_VR; - } - - loadPreVehicleModel(); - - if (mCurrentUI != null) { - UiThreadHandler.post(() -> { - try { - CallerLogger.d(M_MAP + TAG, "currentUI = " + mCurrentUI); - MogoMapListenerHandler.Companion.getMogoMapListenerHandler().onMapModeChanged(mCurrentUI); - CallerMapStyleListenerManager.INSTANCE.invokeMapStyleChange(styleId); - } catch (Exception e) { - e.printStackTrace(); - } - }); - } - } - - // 是否使用RTK数据 - private boolean mRtkEnable = false; - - @Override - public void rtkEnable(boolean enable) { - try { - mRtkEnable = !mRtkEnable; - if (mMapView != null && mMapView.getLocationClient() != null) { - mMapView.getLocationClient().rtkEnable(mRtkEnable); - } - } catch (Exception e) { - CallerLogger.e(M_MAP + TAG, "rtkEnable has exception : " + e); - } - } - - - @Override - public void stepInVrMode(boolean isDayMode) { -// try { -// int mapStyle; -// if (isDayMode) { -// mCurrentUI = EnumMapUI.MAP_STYLE_DAY_VR; -// mapStyle = MapAutoApi.MAP_STYLE_DAY_VR; -// } else { -// mCurrentUI = EnumMapUI.MAP_STYLE_NIGHT_VR; -// mapStyle = MapAutoApi.MAP_STYLE_NIGHT_VR; -// } -// if (mMapView != null && mMapView.getMapAutoViewHelper() != null) { -// mMapView.getMapAutoViewHelper().setMapStyle(mapStyle); -// } -// } catch (Exception e) { -// e.printStackTrace(); -// } - } - - @Override - public String getMarkerInfoResName(String speedVal) { - return ResIdCache.getVal(speedVal); - } - - @Override - public void setMarkerInfoResName(String speedVal, String val) { - ResIdCache.putVal(speedVal, val); - } - - @Override - public void setMapDAngle(float angle) { - if (checkAMapView()) { - mMapView.getMapAutoViewHelper().setMapDAngle(angle); - } - } - - @Override - public float getAngle(double startLon, double startLat, double endLon, double endLat) { - 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模型 - */ - private void loadPreVehicleModel() { - CallerLogger.d(M_MAP + TAG, "添加感知模型到地图中……"); - ThreadUtils.getIoPool().submit(() -> { - addPreVehicleModelWeiZhi(TrafficTypeEnum.TYPE_TRAFFIC_ID_WEI_ZHI, "添加感知模型到地图中……preVehicleStrWeiZhi="); - - addPreVehicleModelWeiZhi(TrafficTypeEnum.TYPE_TRAFFIC_ID_PEOPLE, "添加感知模型到地图中……preVehicleStrPeople="); - - addPreVehicleModelWeiZhi(TrafficTypeEnum.TYPE_TRAFFIC_ID_BICYCLE, "添加感知模型到地图中……preVehicleStrBicycle="); - - addPreVehicleModelWeiZhi(TrafficTypeEnum.TYPE_TRAFFIC_ID_TA_CHE, "添加感知模型到地图中……preVehicleStrTaChe="); - - addPreVehicleModelWeiZhi(TrafficTypeEnum.TYPE_TRAFFIC_ID_MOTO, "添加感知模型到地图中……preVehicleStrMoto="); - - addPreVehicleModelWeiZhi(TrafficTypeEnum.TYPE_TRAFFIC_ID_BUS, "添加感知模型到地图中……preVehicleStrBus="); - - addPreVehicleModelWeiZhi(TrafficTypeEnum.TYPE_TRAFFIC_ID_TRUCK, "添加感知模型到地图中……preVehicleStrTruck="); - }); - } - - /** - * 添加模型到地图中 - * - * @param typeTrafficId 障碍物类型ID - * @param logMsg 日志消息 - */ - private void addPreVehicleModelWeiZhi(TrafficTypeEnum typeTrafficId, String logMsg) { - String preVehicleStrWeiZhi; - // 根据当前的地图皮肤模式动态替换 - if (isDayMode()) { - preVehicleStrWeiZhi = - // 添加模型到地图中 - MogoIdentifyManager.getInstance(getContext()) - .addPreVehicleModel(typeTrafficId.getType(), typeTrafficId.getTraffic3DIconId()); - } else { - preVehicleStrWeiZhi = - // 添加模型到地图中 - MogoIdentifyManager.getInstance(getContext()) - .addPreVehicleModel(typeTrafficId.getType(), typeTrafficId.getTraffic3DNightIconId()); - } - - CallerLogger.d(M_MAP + TAG, logMsg + preVehicleStrWeiZhi); - - if (preVehicleStrWeiZhi == null) { - UiThreadHandler.postDelayed(() -> { - CallerLogger.w(M_MAP + TAG, "添加感知模型到地图中失败,尝试重复添加……"); - addPreVehicleModelWeiZhi(typeTrafficId, logMsg); - }, 1000L); - } - } - - @Override - public void setLockMode(boolean isLock) { - if (checkAMapView()) { - mMapView.getMapAutoViewHelper().setLockMode(isLock); - } - } - - @Override - public void setScrollGesturesEnable(boolean isEnable) { - if (checkAMapView()) { - mMapView.getMapAutoViewHelper().setScrollGesturesEnabled(isEnable); - } - } - - @Override - public void setAllGesturesEnabled(boolean isEnable) { - if (checkAMapView()) { - mMapView.getMapAutoViewHelper().setAllGesturesEnabled(isEnable); - } - } - - - @Override - public void setExtraGPSData(MogoLocation gnssInfo) { - LocationClient locationClient = mMapView.getLocationClient(); - if (locationClient != null) { - locationClient.setIsUseExtraGPSData(true);//设置是否使用外界坐标 - locationClient.rtkEnable(true);//设置是否是高精定位 - - LonLatPoint lonLatPoint = new LonLatPoint(); - lonLatPoint.setAngle(gnssInfo.getHeading()); - lonLatPoint.setAltitude(gnssInfo.getAltitude()); - lonLatPoint.setLongitude(gnssInfo.getLongitude()); - lonLatPoint.setLatitude(gnssInfo.getLatitude()); - lonLatPoint.setSatelliteTime(Double.valueOf(gnssInfo.getSatelliteTime() * 1000).longValue()); - lonLatPoint.setSpeed((float) gnssInfo.getGnssSpeed()); - - locationClient.updateLocation(lonLatPoint);//更新新自动驾驶RTK相关数据 - - CallerMapDataCollectorManager.INSTANCE.setIsInit(); - } - } - - @Override - public void setIsDrawPointCloud(Boolean isDrawPointCloud) { - try { - // 是否绘制点云 - PointCloudHelper.INSTANCE.setIsDrawPointCloud(isDrawPointCloud); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Override - public void setPointCloudSize(Float pointCloudSize) { - //设置点云大小 - PointCloudHelper.INSTANCE.setPointCloudSize(pointCloudSize); - } - - @Override - public void setPointCloudColor(String color) { - // 设置点云颜色 - PointCloudHelper.INSTANCE.setPointCloudColor(color); - } - - @Override - public void cacheHDDataByCity(IHdCacheListener listener) { - if (mMapView.getMapAutoViewHelper() != null) { - String gdCityCode = GDLocationClient.getInstance(getContext()).getLastCityCode(); - CallerLogger.i(M_MAP + TAG, "gdCityCode is:" + gdCityCode); - Integer id = HDMapUtils.getHDCityCode(gdCityCode); - if (id != null) { - hdCacheListener = listener; - mMapView.getMapAutoViewHelper().cacheHDDataByCity(id, new OnHdDataDownByCityListener() { - @Override - public void onMapHDDataCacheProgressByCity(int cityId, double progress) { - if (Thread.currentThread() == Looper.getMainLooper().getThread()) { - if (hdCacheListener != null) { - hdCacheListener.onMapHdCacheProgress(cityId, progress * 100); - } - } else { - UiThreadHandler.post(() -> { - if (hdCacheListener != null) { - hdCacheListener.onMapHdCacheProgress(cityId, progress * 100); - } - }, UiThreadHandler.MODE.QUEUE); - } - } - - @Override - public void onMapHDDataCacheStateByCity(int i, int state) {// 0失败,1成功 - if (Thread.currentThread() == Looper.getMainLooper().getThread()) { - if (hdCacheListener != null) { - hdCacheListener.onMapHdCacheResult(i, state); - } - } else { - UiThreadHandler.post(() -> { - if (hdCacheListener != null) { - hdCacheListener.onMapHdCacheResult(i, state); - } - }, UiThreadHandler.MODE.QUEUE); - } - } - }); - } - } - } - - @Override - public void cacheHDDataByCity(IHdCacheListener listener, MogoLocation location) { - if (mMapView.getMapAutoViewHelper() != null) { - hdCacheListener = listener; - CallerLogger.i(M_MAP + TAG, "location lon is:" + location.getLongitude() + ",lat is:" + location.getLatitude()); - mMapView.getMapAutoViewHelper().cacheHDDataByCityByLonLat(location.getLongitude(), location.getLatitude(), new OnHdDataDownByCityListener() { - @Override - public void onMapHDDataCacheProgressByCity(int cityId, double progress) { - if (Thread.currentThread() == Looper.getMainLooper().getThread()) { - if (hdCacheListener != null) { - hdCacheListener.onMapHdCacheProgress(cityId, progress * 100); - } - } else { - UiThreadHandler.post(() -> { - if (hdCacheListener != null) { - hdCacheListener.onMapHdCacheProgress(cityId, progress * 100); - } - }, UiThreadHandler.MODE.QUEUE); - } - } - - @Override - public void onMapHDDataCacheStateByCity(int i, int state) {// 0失败,1成功 - if (Thread.currentThread() == Looper.getMainLooper().getThread()) { - if (hdCacheListener != null) { - hdCacheListener.onMapHdCacheResult(i, state); - } - } else { - UiThreadHandler.post(() -> { - if (hdCacheListener != null) { - hdCacheListener.onMapHdCacheResult(i, state); - } - }, UiThreadHandler.MODE.QUEUE); - } - } - }); - } - } - - @Override - public boolean isCityDataCached() { - if (mMapView.getMapAutoViewHelper() != null) { - String gdCityCode = GDLocationClient.getInstance(getContext()).getLastCityCode(); - CallerLogger.i(M_MAP + TAG, "gdCityCode is:" + gdCityCode); - Integer id = HDMapUtils.getHDCityCode(gdCityCode); - if (id != null) { - List cityInfoList = mMapView.getMapAutoViewHelper().getAllCityCode(); - if (cityInfoList != null) { - for (CityInfo cityInfo : cityInfoList) { - if (id == cityInfo.getCityCode()) { - return cityInfo.isCache; - } - } - } - } - } - return false; - } - - @Override - public void cancelDownloadCacheData() { - if (mMapView.getMapAutoViewHelper() != null) { - mMapView.getMapAutoViewHelper().cancelCacheHDData(); - } - } - - @Override - public String getCityCode() { - return GDLocationClient.getInstance(getContext()).getLastCityCode(); - } - - @Override - public void animateTo(double lon, double lat, float rotateAngle, int duration, boolean isGps) { - if (mMapView.getMapAutoViewHelper() != null) { - mMapView.getMapAutoViewHelper().animateTo(lon, lat, rotateAngle, duration, isGps); - } - } - - @Override - public void animateTo(double lon, double lat, float v1, float v2, float v3, float v4, int duration, boolean isGps) { - if (mMapView.getMapAutoViewHelper() != null) { - mMapView.getMapAutoViewHelper().animateTo(lon, lat, v1, v2, v3, v4, duration, isGps); - } - } -} diff --git a/libraries/mogo-map/src/main/java/com/mogo/map/AMapWrapper.java b/libraries/mogo-map/src/main/java/com/mogo/map/AMapWrapper.java index da45eca7d8..441b2e5147 100644 --- a/libraries/mogo-map/src/main/java/com/mogo/map/AMapWrapper.java +++ b/libraries/mogo-map/src/main/java/com/mogo/map/AMapWrapper.java @@ -1,36 +1,26 @@ 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.NonNull; + 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; @@ -45,7 +35,6 @@ 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; @@ -54,16 +43,8 @@ public class AMapWrapper implements IMogoMap { public AMapWrapper(MapAutoViewHelper map, MapAutoView mapView, IMogoMapUIController controller) { CallerLogger.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 @@ -78,16 +59,16 @@ public class AMapWrapper implements IMogoMap { } @Override - public IMogoMapUIController getUIController() { + public IMogoMapUIController getUiController() { return mMapUIController; } @Override - public IMapPointOverlay addPoint(com.mogo.map.overlay.point.Point.Options options) { + public IMapPointOverlay addPoint(@NonNull com.mogo.map.overlay.point.Point.Options options) { if (!checkAMap()) { return null; } - MarkerOptions markerOptions = ObjectUtils.fromMogo(options); + MarkerOptions markerOptions = ObjectUtils.fromMogo(options,mMapView); if (markerOptions == null) { CallerLogger.e(TAG, "marker参数为空"); return null; @@ -96,24 +77,24 @@ public class AMapWrapper implements IMogoMap { if (delegate == null) { return null; } - return new AMapPointWrapper(options.getId(), delegate); + return new AMapPointWrapper(options.getId(), delegate,mMapView); } @Override - public IMapPolylineOverlay addLine(com.mogo.map.overlay.line.Polyline.Options options) { + public IMapPolylineOverlay addLine(@NonNull com.mogo.map.overlay.line.Polyline.Options options) { if (!checkAMap()) { return null; } - PolylineOptions polylineOptions = ObjectUtils.fromMogo(options); + PolylineOptions polylineOptions = ObjectUtils.fromMogo(options,mMapView); if (polylineOptions == null) { CallerLogger.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 +119,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 +153,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,73 +179,16 @@ 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(); } } - @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.d(TAG, "changeZoom %s", zoom); - if (checkAMap()) { - mAMap.setZoom((int) zoom); - } - } - - @Override - public void changeZoom2(float zoom) { - CallerLogger.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.e(TAG, "自研map实例为空,请检查"); return false; @@ -266,46 +196,4 @@ public class AMapWrapper implements IMogoMap { 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> convert(List points) { - if (points == null || points.isEmpty()) { - return Collections.emptyList(); - } - List> ret = new ArrayList<>(points.size()); - for (LonLatPoint p : points) { - ret.add(Pair.create(p.longitude, p.latitude)); - } - return ret; - } } diff --git a/libraries/mogo-map/src/main/java/com/mogo/map/MogoMapUIController.java b/libraries/mogo-map/src/main/java/com/mogo/map/MogoMapUIController.java deleted file mode 100644 index 7f68078bf7..0000000000 --- a/libraries/mogo-map/src/main/java/com/mogo/map/MogoMapUIController.java +++ /dev/null @@ -1,522 +0,0 @@ -package com.mogo.map; - -import android.graphics.Point; -import android.graphics.Rect; -import android.location.Location; -import android.view.View; - -import com.mogo.eagle.core.data.map.CenterLine; -import com.mogo.eagle.core.data.map.MogoLatLng; -import com.mogo.eagle.core.data.map.MogoLocation; -import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger; -import com.mogo.map.hdcache.IHdCacheListener; -import com.mogo.map.uicontroller.AMapUIController; -import com.mogo.map.uicontroller.CarCursorOption; -import com.mogo.map.uicontroller.IMogoMapUIController; -import com.mogo.map.uicontroller.MapCameraPosition; -import com.mogo.map.uicontroller.MapControlResult; -import com.mogo.map.uicontroller.VisualAngleMode; - -import java.util.List; - - -/** - * @author congtaowang - * @since 2019-12-26 - *

- * 地图控制 - */ -public class MogoMapUIController implements IMogoMapUIController { - - private static final String TAG = "MogoMapUIController"; - - private IMogoMapUIController mDelegate; - - private static volatile MogoMapUIController sInstance; - - private MogoMapUIController() { - initDelegate(); - } - - private void initDelegate() { - if (mDelegate == null) { - mDelegate = AMapUIController.getInstance(); - } - } - - public static MogoMapUIController getInstance() { - if (sInstance == null) { - synchronized (MogoMapUIController.class) { - if (sInstance == null) { - sInstance = new MogoMapUIController(); - } - } - } - return sInstance; - } - - public static synchronized void release() { - sInstance = null; - } - - @Override - public MapControlResult changeZoom(float zoom) { - initDelegate(); - if (mDelegate != null) { - return mDelegate.changeZoom(zoom); - } - return MapControlResult.ERROR; - } - - @Override - public void changeZoom2(float zoom) { - initDelegate(); - if (mDelegate != null) { - mDelegate.changeZoom2(zoom); - } - } - - @Override - public void setDebugMode(Boolean debugMode) { - initDelegate(); - if (mDelegate != null) { - mDelegate.setDebugMode(debugMode); - } - } - - @Override - public void changeMapVisualAngle(VisualAngleMode angelMode, MogoLatLng mogoLatLng) { - initDelegate(); - if (mDelegate != null) { - CallerLogger.d(TAG, "set VisualAngle: " + angelMode.name()); - mDelegate.changeMapVisualAngle(angelMode, mogoLatLng); - } - } - - @Override - public void setRoamTrajectory(String trajectory) { - initDelegate(); - if (mDelegate != null) { - mDelegate.setRoamTrajectory(trajectory); - } - } - - @Override - public void setRomaMode(int mode) { - initDelegate(); - if (mDelegate != null) { - CallerLogger.d(TAG, "set setRomaMode: " + mode); - mDelegate.setRomaMode(mode); - } - } - - @Override - public VisualAngleMode getCurrentMapVisualAngle() { - initDelegate(); - if (mDelegate != null) { - return mDelegate.getCurrentMapVisualAngle(); - } - return null; - } - - @Override - public void moveToCenter(MogoLatLng latLng, boolean animate) { - initDelegate(); - if (mDelegate != null) { - mDelegate.moveToCenter(latLng, animate); - } - } - - @Override - public boolean isDayMode() { - initDelegate(); - if (mDelegate != null) { - return mDelegate.isDayMode(); - } - return false; - } - - @Override - public void showMyLocation(boolean visible) { - initDelegate(); - if (mDelegate != null) { - mDelegate.showMyLocation(visible); - } - } - - - @Override - public void showMyLocation(View view) { - initDelegate(); - if (mDelegate != null) { - mDelegate.showMyLocation(view); - } - } - - - @Override - public float getScalePerPixel() { - initDelegate(); - if (mDelegate != null) { - return mDelegate.getScalePerPixel(); - } - return 0; - } - - @Override - public float getZoomLevel() { - initDelegate(); - if (mDelegate != null) { - return mDelegate.getZoomLevel(); - } - return 0; - } - - @Override - public float getRoadWidth(double lon, double lat, float angle, boolean isGpsLocation, boolean isRTK) { - initDelegate(); - if (mDelegate != null) { - return mDelegate.getRoadWidth(lon, lat, angle, isGpsLocation, isRTK); - } - - return 0; - } - - @Override - public MogoLatLng getCameraNorthEastPosition() { - initDelegate(); - if (mDelegate != null) { - return mDelegate.getCameraNorthEastPosition(); - } - return null; - } - - @Override - public MogoLatLng getCameraSouthWestPosition() { - initDelegate(); - if (mDelegate != null) { - return mDelegate.getCameraSouthWestPosition(); - } - return null; - } - - @Override - public MogoLatLng getWindowCenterLocation() { - initDelegate(); - if (mDelegate != null) { - return mDelegate.getWindowCenterLocation(); - } - return null; - } - - @Override - public void setPointToCenter(double mapCenterX, double mapCenterY) { - initDelegate(); - if (mDelegate != null) { - mDelegate.setPointToCenter(mapCenterX, mapCenterY); - } - } - - @Override - public Point getLocationPointInScreen(MogoLatLng latLng) { - initDelegate(); - if (mDelegate != null) { - return mDelegate.getLocationPointInScreen(latLng); - } - return null; - } - - @Override - public MogoLatLng getLocationMogoLatLngInScreen(Point point) { - initDelegate(); - if (mDelegate != null) { - return mDelegate.getLocationMogoLatLngInScreen(point); - } - return null; - } - - @Override - public void setRenderFps(int fps) { - initDelegate(); - if (mDelegate != null) { - mDelegate.setRenderFps(fps); - } - } - - @Override - public void showBounds(String tag, MogoLatLng carPosition, List lonLats, Rect bound, boolean lockCarPosition) { - initDelegate(); - if (mDelegate != null) { - mDelegate.showBounds(tag, carPosition, lonLats, bound, lockCarPosition); - } - } - - @Override - public void forceRender() { - initDelegate(); - if (mDelegate != null) { - mDelegate.forceRender(); - } - } - - @Override - public float calculateLineDistance(MogoLatLng p1, MogoLatLng p2) throws Exception { - initDelegate(); - if (mDelegate != null) { - return mDelegate.calculateLineDistance(p1, p2); - } - return 0; - } - - @Override - public boolean isCarLocked() { - initDelegate(); - if (mDelegate != null) { - return mDelegate.isCarLocked(); - } - return false; - } - - @Override - public void setCarCursorOption(CarCursorOption option) { - initDelegate(); - if (mDelegate != null) { - mDelegate.setCarCursorOption(option); - } - } - - @Override - public void setCarLightsType(int type, int time) { - initDelegate(); - if (mDelegate != null) { - mDelegate.setCarLightsType(type, time); - } - } - - @Override - public MapCameraPosition getMapCameraPosition() { - initDelegate(); - if (mDelegate != null) { - return mDelegate.getMapCameraPosition(); - } - return null; - } - - @Override - public void changeBearing(float bearing) { - initDelegate(); - if (mDelegate != null) { - mDelegate.changeBearing(bearing); - } - } - - @Override - public void changeMapViewAngle(int type) { - initDelegate(); - if (mDelegate != null) { - mDelegate.changeMapViewAngle(type); - } - } - - @Override - public void changeCurrentIcon(int iconId) { - initDelegate(); - if (mDelegate != null) { - mDelegate.changeCurrentIcon(iconId); - } - } - - @Override - public long getTileId(double lon, double lat) { - if (mDelegate != null) { - return mDelegate.getTileId(lon, lat); - } - return 0; - } - - @Override - public int getLimitSpeed(double lon, double lat, float angle) { - if (mDelegate != null) { - return mDelegate.getLimitSpeed(lon, lat, angle); - } - return 0; - } - - @Override - public CenterLine getCenterLineInfo(double lon, double lat, float angle) { - if (mDelegate != null) { - return mDelegate.getCenterLineInfo(lon, lat, angle); - } - return null; - } - - @Override - public void rtkEnable(boolean enable) { - initDelegate(); - if (mDelegate != null) { - mDelegate.rtkEnable(enable); - } - } - - @Override - public void destroy() { - mDelegate = null; - } - - @Override - public void stepInVrMode(boolean isDayMode) { - initDelegate(); - if (mDelegate != null) { - mDelegate.stepInVrMode(isDayMode); - } - } - - @Override - public String getMarkerInfoResName(String speedVal) { - initDelegate(); - if (mDelegate != null) { - return mDelegate.getMarkerInfoResName(speedVal); - } - return null; - } - - @Override - public void setMarkerInfoResName(String speedVal, String val) { - initDelegate(); - if (mDelegate != null) { - mDelegate.setMarkerInfoResName(speedVal, val); - } - } - - @Override - public void setMapDAngle(float angle) { - initDelegate(); - if (mDelegate != null) { - mDelegate.setMapDAngle(angle); - } - } - - @Override - public float getAngle(double startLon, double startLat, double endLon, double endLat) { - initDelegate(); - if (mDelegate != null) { - return mDelegate.getAngle(startLon, startLat, endLon, endLat); - } - return 0.0f; - } - - @Override - public Double getRoadAngle(Double lon, Double lat, float angle) { - if (mDelegate != null) { - return mDelegate.getRoadAngle(lon, lat, angle); - } - return 0.0; - } - - @Override - public void setLockMode(boolean isLock) { - initDelegate(); - if (mDelegate != null) { - mDelegate.setLockMode(isLock); - } - } - - @Override - public void setScrollGesturesEnable(boolean isEnable) { - initDelegate(); - if (mDelegate != null) { - mDelegate.setScrollGesturesEnable(isEnable); - } - } - - @Override - public void setAllGesturesEnabled(boolean isEnable) { - initDelegate(); - if (mDelegate != null) { - mDelegate.setAllGesturesEnabled(isEnable); - } - } - - @Override - public void setExtraGPSData(MogoLocation gnssInfo) { - initDelegate(); - if (mDelegate != null) { - mDelegate.setExtraGPSData(gnssInfo); - } - } - - @Override - public void setIsDrawPointCloud(Boolean isDrawPointCloud) { - initDelegate(); - if (mDelegate != null) { - mDelegate.setIsDrawPointCloud(isDrawPointCloud); - } - } - - @Override - public void setPointCloudSize(Float pointCloudSize) { - initDelegate(); - if (mDelegate != null) { - mDelegate.setPointCloudSize(pointCloudSize); - } - } - - @Override - public void setPointCloudColor(String color) { - initDelegate(); - if (mDelegate != null) { - mDelegate.setPointCloudColor(color); - } - } - - @Override - public void cacheHDDataByCity(IHdCacheListener listener) { - if (mDelegate != null) { - mDelegate.cacheHDDataByCity(listener); - } - } - - @Override - public void cacheHDDataByCity(IHdCacheListener listener, MogoLocation location) { - if (mDelegate != null) { - mDelegate.cacheHDDataByCity(listener, location); - } - } - - @Override - public boolean isCityDataCached() { - if (mDelegate != null) { - return mDelegate.isCityDataCached(); - } - return false; - } - - @Override - public void cancelDownloadCacheData() { - if (mDelegate != null) { - mDelegate.cancelDownloadCacheData(); - } - } - - @Override - public String getCityCode() { - if (mDelegate != null) { - return mDelegate.getCityCode(); - } - return null; - } - - @Override - public void animateTo(double lon, double lat, float rotateAngle, int duration, boolean isGps) { - if (mDelegate != null) { - mDelegate.animateTo(lon, lat, rotateAngle, duration, isGps); - } - } - - @Override - public void animateTo(double lon, double lat, float v1, float v2, float v3, float v4, int duration, boolean isGps) { - if (mDelegate != null) { - mDelegate.animateTo(lon, lat, v1, v2, v3, v4, duration, isGps); - } - } -}