地图依赖重构

This commit is contained in:
wangcongtao
2020-12-13 11:04:44 +08:00
parent 6fee5deaca
commit 564b1356a1
59 changed files with 1033 additions and 626 deletions

View File

@@ -6,12 +6,13 @@ import android.graphics.drawable.Drawable;
import android.os.Looper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
@@ -97,11 +98,34 @@ public class MyLocationUtil {
if (res == null) {
throw new IllegalArgumentException("inflate myLocation bitmap can not be null!");
}
View root =
LayoutInflater.from(context).inflate(R.layout.module_common_my_location, null, false);
ImageView iv =
root.findViewById(R.id.module_map_amap_my_location_iv);
View root = LayoutInflater.from(context).inflate(R.layout.module_common_my_location, null, false);
ImageView iv = root.findViewById(R.id.module_map_amap_my_location_iv);
iv.setImageBitmap(res);
return BitmapDescriptorFactory.fromView(root).getBitmap();
return fromView(root);
}
private static Bitmap fromView( View view ) {
view.setDrawingCacheEnabled( true );
processChildView( view );
view.destroyDrawingCache();
view.measure( View.MeasureSpec.makeMeasureSpec( 0, View.MeasureSpec.UNSPECIFIED ), View.MeasureSpec.makeMeasureSpec( 0, View.MeasureSpec.UNSPECIFIED ) );
view.layout( 0, 0, view.getMeasuredWidth(), view.getMeasuredHeight() );
Bitmap bitmap = null;
return ( bitmap = view.getDrawingCache() ) != null ? bitmap.copy( Bitmap.Config.ARGB_8888, false ) : null;
}
private static void processChildView( View view ) {
if ( !( view instanceof ViewGroup ) ) {
if ( view instanceof TextView ) {
( ( TextView ) view ).setHorizontallyScrolling( false );
}
} else {
for ( int var1 = 0; var1 < ( ( ViewGroup ) view ).getChildCount(); ++var1 ) {
processChildView( ( ( ViewGroup ) view ).getChildAt( var1 ) );
}
}
}
}

View File

@@ -1,7 +1,5 @@
package com.mogo.module.common.utils;
import com.amap.api.maps.model.LatLng;
/**
* @author donghongyu
*/
@@ -13,7 +11,6 @@ public class CoordinateUtils {
/**
* 手机GPS坐标转火星坐标
*
* @param wgLoc
* @return
*/
public static double[] transformFromWGSToGCJ( double lat, double lon ) {
@@ -36,32 +33,6 @@ public class CoordinateUtils {
return new double[]{lat + dLat, lon + dLon};
}
/**
* 手机GPS坐标转火星坐标
*
* @param wgLoc
* @return
*/
public static LatLng transformFromWGSToGCJ( LatLng wgLoc ) {
//如果在国外,则默认不进行转换
if ( outOfChina( wgLoc.latitude, wgLoc.longitude ) ) {
return new LatLng( wgLoc.latitude, wgLoc.longitude );
}
double dLat = transformLat( wgLoc.longitude - 105.0,
wgLoc.latitude - 35.0 );
double dLon = transformLon( wgLoc.longitude - 105.0,
wgLoc.latitude - 35.0 );
double radLat = wgLoc.latitude / 180.0 * Math.PI;
double magic = Math.sin( radLat );
magic = 1 - ee * magic * magic;
double sqrtMagic = Math.sqrt( magic );
dLat = ( dLat * 180.0 ) / ( ( a * ( 1 - ee ) ) / ( magic * sqrtMagic ) * Math.PI );
dLon = ( dLon * 180.0 ) / ( a / sqrtMagic * Math.cos( radLat ) * Math.PI );
return new LatLng( wgLoc.latitude + dLat, wgLoc.longitude + dLon );
}
public static double transformLat( double x, double y ) {
double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y
+ 0.2 * Math.sqrt( x > 0 ? x : -x );

View File

@@ -3,7 +3,6 @@ package com.mogo.module.extensions.navi;
import android.widget.ImageView;
import android.widget.TextView;
import com.mogo.map.impl.amap.utils.IconTypeUtils;
import com.mogo.map.navi.MogoNaviInfo;
import java.text.SimpleDateFormat;
@@ -21,10 +20,6 @@ public abstract class BaseNaviInfoView {
}
protected void fillNextCrossTurning( TextView target, int nextIconType ) {
target.setText( "" + IconTypeUtils.getNameByIconType( nextIconType ) );
}
protected void fillNextCrossIconType( ImageView target, int iconId ) {
if ( iconId > 0 ) {
target.setImageResource( iconId );

View File

@@ -59,33 +59,31 @@ public class MapFragment extends MvpFragment< MapView, MapPresenter > implements
@Override
public void changeTo2dMode() {
if ( !isVrMode() ) {
return;
}
mMogoMapView.display2DMap( false, true );
afterMapModeChanged();
MogoApisHandler.getInstance().getApis().getAdasControllerApi().showADAS();
MogoApisHandler.getInstance().getApis().getStatusManagerApi().setVrMode( TAG, false );
// if ( !isVrMode() ) {
// return;
// }
// afterMapModeChanged();
// MogoApisHandler.getInstance().getApis().getAdasControllerApi().showADAS();
// MogoApisHandler.getInstance().getApis().getStatusManagerApi().setVrMode( TAG, false );
}
@Override
public void changeToVRMode() {
if ( isVrMode() ) {
return;
}
mMogoMapView.displayVRMap( mIsFirstLoadCustomMap, true );
if ( mIsFirstLoadCustomMap ) {
// initMapView();
// mMogoMap = mMogoMapView.getMap();
// if ( mMogoMap.getUIController() != null ) {
// mMogoMap.getUIController().showMyLocation( true );
// mMogoMap.getUIController().recoverLockMode();// 启动锁车
// }
// mIsFirstLoadCustomMap = false;
}
afterMapModeChanged();
MogoApisHandler.getInstance().getApis().getAdasControllerApi().closeADAS();
MogoApisHandler.getInstance().getApis().getStatusManagerApi().setVrMode( TAG, true );
// if ( isVrMode() ) {
// return;
// }
// if ( mIsFirstLoadCustomMap ) {
//// initMapView();
//// mMogoMap = mMogoMapView.getMap();
//// if ( mMogoMap.getUIController() != null ) {
//// mMogoMap.getUIController().showMyLocation( true );
//// mMogoMap.getUIController().recoverLockMode();// 启动锁车
//// }
//// mIsFirstLoadCustomMap = false;
// }
// afterMapModeChanged();
// MogoApisHandler.getInstance().getApis().getAdasControllerApi().closeADAS();
// MogoApisHandler.getInstance().getApis().getStatusManagerApi().setVrMode( TAG, true );
}
private void afterMapModeChanged() {
@@ -111,10 +109,12 @@ public class MapFragment extends MvpFragment< MapView, MapPresenter > implements
mMogoMapView = findViewById( R.id.module_map_id_map );
mMogoMapView.onCreate( savedInstanceState );
mMogoMap = mMogoMapView.getMap();
mMogoMap.getUIController().showMyLocation( true );
mMogoMap.getUIController().recoverLockMode();// 启动锁车
if ( mMogoMap != null ) {
mMogoMap.getUIController().showMyLocation( true );
mMogoMap.getUIController().recoverLockMode();// 启动锁车
}
// 根据本地配置设置自车图标
MyLocationUtil.setMyLocationIconUrl(getContext(), SharedPrefsMgr.getInstance(getContext()).getString("MY_LOCATION_CONFIG", ""));
MyLocationUtil.setMyLocationIconUrl( getContext(), SharedPrefsMgr.getInstance( getContext() ).getString( "MY_LOCATION_CONFIG", "" ) );
}
@NonNull

View File

@@ -1,7 +1,5 @@
package com.mogo.module.navi.bean;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.services.geocoder.RegeocodeAddress;
import com.mogo.map.MogoLatLng;
import com.mogo.map.search.inputtips.MogoTip;
import com.mogo.module.navi.constants.DataConstants;
@@ -93,36 +91,6 @@ public class EntityConvertUtils {
MogoTip.getTypeCode() );
}
//public static SearchPoi aMapLocation2Poi( AMapLocation location ) {
// if ( location == null || location.getErrorCode() != AMapLocation.LOCATION_SUCCESS ) {
// return null;
// }
// return new SearchPoi( System.currentTimeMillis() + "",
// location.getPoiName(),
// location.getAddress(),
// location.getLatitude(),
// location.getLongitude(),
// location.getDistrict(),
// location.getAdCode(),
// location.getCoordType() );
//}
public static SearchPoi geocodeAddress2Poi( RegeocodeAddress address, CameraPosition position ) {
if ( address == null || position == null ) {
return null;
}
return new SearchPoi( System.currentTimeMillis() + "",
address.getFormatAddress(),
address.getFormatAddress(),
position.target.latitude,
position.target.longitude,
address.getDistrict(),
address.getAdCode(),
"" );
}
public static SearchPoi geoToPoi( double latitude, double longitude, int type ) {
SearchPoi searchPoi = new SearchPoi( System.currentTimeMillis() + "",
null,

View File

@@ -5,7 +5,6 @@ import android.location.Location;
import androidx.annotation.NonNull;
import androidx.lifecycle.LifecycleOwner;
import com.amap.api.maps.model.LatLng;
import com.mogo.commons.mvp.Presenter;
import com.mogo.map.MogoLatLng;
import com.mogo.map.location.MogoLocation;

View File

@@ -15,7 +15,6 @@ import android.view.MotionEvent;
import androidx.annotation.NonNull;
import com.amap.api.maps.model.MarkerOptions;
import com.alibaba.android.arouter.launcher.ARouter;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.commons.network.ParamsProvider;
@@ -46,7 +45,6 @@ import com.mogo.module.common.entity.MarkerResponse;
import com.mogo.module.common.map.MapCenterPointStrategy;
import com.mogo.module.common.map.Scene;
import com.mogo.module.common.utils.CoordinateSystemTransformationUtil;
import com.mogo.module.common.utils.CoordinateUtils;
import com.mogo.module.service.autopilot.AutoPilotRemoteController;
import com.mogo.module.service.intent.IntentHandlerFactory;
import com.mogo.module.service.launchercard.LauncherCardRefresher;
@@ -62,12 +60,11 @@ import com.mogo.module.service.refresh.AutoRefreshStrategy;
import com.mogo.module.service.refresh.CustomRefreshStrategy;
import com.mogo.module.service.refresh.RefreshObject;
import com.mogo.module.service.strategy.CarIconDisplayStrategy;
import com.mogo.module.service.utils.LocationParseUtil;
import com.mogo.module.service.ttsConfig.TtsConfigModleData;
import com.mogo.module.service.utils.SimpleLocationCorrectStrategy;
import com.mogo.module.service.vrmode.VrModeController;
import com.mogo.module.service.websocket.LocationResult;
import com.mogo.module.service.websocket.OnePerSecondSendContent;
import com.mogo.module.service.ttsConfig.TtsConfigModleData;
import com.mogo.service.adas.IMogoADASController;
import com.mogo.service.adas.entity.ADASRecognizedResult;
import com.mogo.service.connection.IMogoOnWebSocketMessageListener;

View File

@@ -1,14 +1,10 @@
package com.mogo.module.share;
import android.content.Context;
import android.nfc.Tag;
import android.util.Log;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.facade.template.IProvider;
import com.amap.api.services.nearby.UploadInfoCallback;
import com.google.gson.JsonObject;
import com.mogo.map.MogoLatLng;
import com.mogo.map.navi.IMogoAimlessModeListener;
import com.mogo.map.navi.MogoCongestionInfo;
import com.mogo.map.navi.MogoCongestionLink;
@@ -20,6 +16,7 @@ import com.mogo.module.common.entity.UploadTrafficEntity;
import com.mogo.module.share.net.TrafficModelData;
import com.mogo.service.MogoServicePaths;
import com.mogo.utils.network.utils.GsonUtil;
import java.util.ArrayList;
import java.util.List;

View File

@@ -9,13 +9,12 @@ import android.util.ArrayMap;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.amap.api.maps.CoordinateConverter;
import com.amap.api.maps.model.LatLng;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.map.location.MogoLocation;
import com.mogo.module.common.entity.V2XMessageEntity;
import com.mogo.module.common.entity.V2XObuEventEntity;
import com.mogo.module.common.entity.V2XPushMessageEntity;
import com.mogo.module.common.utils.CoordinateUtils;
import com.mogo.module.v2x.listener.V2XLocationListener;
import com.mogo.module.v2x.scenario.scene.obu.V2XObuEventScenario;
import com.mogo.module.v2x.utils.ADASUtils;
@@ -260,14 +259,10 @@ public class V2XObuManager implements IObuCallback, Handler.Callback {
if (ObuConfig.useObuLocation) {
MogoLocation currentLocation = new MogoLocation();
CoordinateConverter converter = new CoordinateConverter(getContext());
converter.from(CoordinateConverter.CoordType.GPS);
LatLng latLng = new LatLng(locationInfo.getLat(), locationInfo.getLon());
converter.coord(latLng);
LatLng convert = converter.convert();
double coor[] = CoordinateUtils.transformFromWGSToGCJ( locationInfo.getLat(), locationInfo.getLon() );
currentLocation.setLatitude(convert.latitude);
currentLocation.setLongitude(convert.longitude);
currentLocation.setLatitude(coor[0]);
currentLocation.setLongitude(coor[1]);
currentLocation.setBearing(computeCarAngle(currentLocation));
V2XObuEventScenario.getInstance().updateLocation(currentLocation);

View File

@@ -1,18 +1,11 @@
package com.mogo.module.machine.vision;
import android.annotation.TargetApi;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import androidx.annotation.Nullable;
import com.mogo.map.IMogoMapView;
import com.mogo.map.MogoBaseMapView;
import com.mogo.map.MogoMap;
import com.mogo.map.impl.custom.CustomMapView;
import com.mogo.utils.logger.Logger;
public
@@ -39,33 +32,7 @@ class MachineVisionMapView extends MogoBaseMapView {
}
@Override
protected void addDleMaps() {
IMogoMapView machineMapView = new CustomMapView().create( getContext() );
if ( machineMapView != null ) {
final View mapView = machineMapView.getMapView();
if ( mapView != null ) {
addView( mapView, new FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT ) );
} else {
Logger.e( TAG, "create MapView instance failed." );
}
} else {
Logger.e( TAG, "create IMogoMapView instance failed." );
}
mMapView = machineMapView;
MogoMap.getInstance().init( getContext(), mMapView.getMap() );
onCreate( null );
postDelayed( ()->{
getMap().getUIController().showMyLocation( true );
}, 1000 );
}
@Override
public void display2DMap( boolean invokeCreateAuto, boolean invokeResumeAuto ) {
}
@Override
public void displayVRMap( boolean invokeCreateAuto, boolean invokeResumeAuto ) {
protected void addMapView( Context context ) {
Logger.d(TAG, "addMapView");
}
}