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.MogoLatLng; 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.utils.logger.Logger; import org.json.JSONObject; 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(); } public static MogoMapUIController getInstance() { if (sInstance == null) { synchronized (MogoMapUIController.class) { if (sInstance == null) { sInstance = new MogoMapUIController(); } } } return sInstance; } public void setDelegate(IMogoMapUIController mDelegate) { this.mDelegate = mDelegate; } public static synchronized void release() { sInstance = null; } @Override public void setTrafficEnabled(boolean visible) { initDelegate(); if (mDelegate != null) { mDelegate.setTrafficEnabled(visible); } } @Override public MapControlResult changeZoom(boolean zoom) { initDelegate(); if (mDelegate != null) { return mDelegate.changeZoom(zoom); } return MapControlResult.ERROR; } @Override public MapControlResult changeZoom(float zoom) { initDelegate(); if (mDelegate != null) { return mDelegate.changeZoom(zoom); } return MapControlResult.ERROR; } @Override public void changeMapMode(EnumMapUI mode) { initDelegate(); if (mDelegate != null) { Logger.d(TAG, "set type: %s", mode.name()); mDelegate.changeMapMode(mode); } } @Override public void changeMapVisualAngle(VisualAngleMode angelMode, MogoLatLng mogoLatLng) { initDelegate(); if (mDelegate != null) { Logger.d(TAG, "set VisualAngle: %s", angelMode.name()); mDelegate.changeMapVisualAngle(angelMode, mogoLatLng); } } @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 void showMyLocation(boolean visible) { initDelegate(); if (mDelegate != null) { mDelegate.showMyLocation(visible); } } @Override public void emphasizeMyLocation() { initDelegate(); if (mDelegate != null) { mDelegate.emphasizeMyLocation(); } } @Override public void showMyLocation(View view) { initDelegate(); if (mDelegate != null) { mDelegate.showMyLocation(view); } } @Override public void recoverLockMode() { initDelegate(); if (mDelegate != null) { mDelegate.recoverLockMode(); } } @Override public void loseLockMode() { initDelegate(); if (mDelegate != null) { mDelegate.loseLockMode(); } } @Override public void setLockZoom(int var1) { initDelegate(); if (mDelegate != null) { mDelegate.setLockZoom(var1); } } @Override public void displayOverview(Rect bounds) { initDelegate(); if (mDelegate != null) { mDelegate.displayOverview(bounds); } } @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 EnumMapUI getCurrentUiMode() { initDelegate(); if (mDelegate != null) { return mDelegate.getCurrentUiMode(); } return null; } @Override public void changeMyLocation(Location location) { initDelegate(); if (mDelegate != null) { mDelegate.changeMyLocation(location); } } @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 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 long getTileId(double lon, double lat) { return mDelegate.getTileId(lon, lat); } @Override public int getSpeedLimmit(double lon, double lat, float angle) { return mDelegate.getSpeedLimmit(lon,lat,angle); } @Override public void rtkEnable(boolean enable) { initDelegate(); if (mDelegate != null) { mDelegate.rtkEnable(enable); } } @Override public void syncLocation2Map(JSONObject data) { initDelegate(); if (mDelegate != null) { mDelegate.syncLocation2Map(data); } } @Override public void destroy() { mDelegate = null; } private void initDelegate() { if (mDelegate == null) { mDelegate = MogoMapDelegateFactory.getMapUIControllerDelegate(); } } @Override public void openVrMode(boolean zoomGestureEnable) { initDelegate(); if (mDelegate != null) { mDelegate.openVrMode(zoomGestureEnable); } } @Override public double[] matchRoad(String id, double lon, double lat, double angle, boolean isGpsLocation, boolean isRTK) { initDelegate(); if (mDelegate != null) { return mDelegate.matchRoad(id, lon, lat, angle, isGpsLocation, isRTK); } return null; } @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 clearRoadCacheById(String id) { initDelegate(); if (mDelegate != null) { mDelegate.clearRoadCacheById(id); } } }