This commit is contained in:
wangcongtao
2020-12-08 14:08:53 +08:00
840 changed files with 31903 additions and 11168 deletions

View File

@@ -0,0 +1,55 @@
package com.mogo.module.common.constants;
public
/**
* @author congtaowang
* @since 2020/10/27
* <p>
* 描述
*/
enum AdasRecognizedType {
//背景
classIdBackground( "background", 0 ),
//人
classIdPerson( "person", 1 ),
//自行车
classIdBicycle( "bicycle", 2 ),
//小轿车
classIdCar( "car", 3 ),
//摩托车
classIdMoto( "moto", 4 ),
//红绿灯
classIdTrafficSign( "traffic_sign", 5 ),
//bus
classIdTrafficBus( "traffic_bus", 6 ),
//track
classIdTrafficTruck( "traffic_truck", 8 );
AdasRecognizedType( int code ) {
this.code = code;
}
private String res = "";
private int code = -1;
AdasRecognizedType( String res, int code ) {
this.res = res;
this.code = code;
}
public String getRes() {
return res;
}
public static AdasRecognizedType valueFrom( int code ) {
if ( code == 0 ) {
return classIdCar;
}
for ( AdasRecognizedType value : AdasRecognizedType.values() ) {
if ( value.code == code ) {
return value;
}
}
return null;
}
}

View File

@@ -0,0 +1,33 @@
package com.mogo.module.common.constants;
public
/**
* @author congtaowang
* @since 2020/10/29
*
* 车模型类型
*/
enum CarModelType {
Other( "other" ),
OtherLeft( "other_left" ),
OtherRight( "other_right" ),
OtherLeftReverse( "other_left_reverse" ),
OtherRightReverse( "other_right_reverse" ),
OtherReverse( "other_reverse" ),
Self( "self" ),
SelfLeft( "self_left" ),
SelfRight( "self_right" );
private String res;
CarModelType( String res ) {
this.res = res;
}
public String getRes() {
return res;
}
}

View File

@@ -0,0 +1,25 @@
package com.mogo.module.common.constants;
public
/**
* @author congtaowang
* @since 2020/10/28
*
* 描述
*/
class DataTypes {
/**
* adas识别数据
*/
public static final String TYPE_MARKER_ADAS = "TYPE_MARKER_ADAS";
/**
* 云端下发数据
*/
public static final String TYPE_MARKER_CLOUD_DATA = "TYPE_MARKER_CLOUD_DATA";
/**
* Push 事件场景 VR
*/
public static final String TYPE_MARKER_PUSH_DATA = "TYPE_MARKER_PUSH_DATA";
}

View File

@@ -0,0 +1,32 @@
package com.mogo.module.common.constants;
public
/**
* @author congtaowang
* @since 2020/10/29
*
* 描述
*/
enum SafeType {
Normal( "normal", "安全" ),
SpeedWarm( "warm", "注意/超速" ),
DistanceWarm( "warm", "注意/保持车距" ),
SpeedDangerous( "dangerous", "危险/严重超速" ),
DistanceDangerous( "dangerous", "危险/距离过近" );
private String msg;
private String res;
SafeType( String res, String msg ) {
this.msg = msg;
this.res = res;
}
public String getRes() {
return res;
}
public String getMsg() {
return msg;
}
}

View File

@@ -0,0 +1,24 @@
package com.mogo.module.common.constants;
public
/**
* @author congtaowang
* @since 2020/10/29
*
* 描述
*/
enum VisionMode {
Machine( "machine" ),
User( "user" );
private String res;
VisionMode( String res ) {
this.res = res;
}
public String getRes() {
return res;
}
}

View File

@@ -0,0 +1,202 @@
package com.mogo.module.common.drawer;
import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.map.MogoLatLng;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.marker.MogoMarkerOptions;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.R;
import com.mogo.module.common.constants.AdasRecognizedType;
import com.mogo.module.common.constants.DataTypes;
import com.mogo.module.common.constants.SafeType;
import com.mogo.module.common.constants.VisionMode;
import com.mogo.module.common.drawer.marker.MarkerResourceManager;
import com.mogo.module.common.utils.CoordinateUtils;
import com.mogo.service.adas.entity.ADASRecognizedListResult;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public
/**
* @author congtaowang
* @since 2020/10/28
*
* 绘制adas近景识别到的车辆
*/
class AdasRecognizedResultDrawer extends BaseDrawer {
private static volatile AdasRecognizedResultDrawer sInstance;
private Context mContext;
private AdasRecognizedResultDrawer() {
mContext = AbsMogoApplication.getApp();
}
public static AdasRecognizedResultDrawer getInstance() {
if ( sInstance == null ) {
synchronized ( AdasRecognizedResultDrawer.class ) {
if ( sInstance == null ) {
sInstance = new AdasRecognizedResultDrawer();
}
}
}
return sInstance;
}
public synchronized void release() {
sInstance = null;
}
private Object readResolve() {
// 阻止反序列化,必须实现 Serializable 接口
return sInstance;
}
// adas marker 缓存
private Map< String, IMogoMarker > mAdasRecognizedMarkersCaches = new ConcurrentHashMap<>();
public void renderAdasRecognizedResult( List< ADASRecognizedListResult > resultList, boolean machineVision, double curSpeed ) {
if ( resultList == null || resultList.isEmpty() ) {
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( mContext ).removeMarkers( DataTypes.TYPE_MARKER_ADAS );
return;
}
purgeAdasRecognizedData( resultList );
for ( ADASRecognizedListResult recognizedListResult : resultList ) {
if ( recognizedListResult == null ) {
continue;
}
IMogoMarker marker = null;
String uniqueKey = recognizedListResult.uuid;
if ( TextUtils.isEmpty( uniqueKey ) ) {
continue;
}
if ( mAdasRecognizedMarkersCaches.containsKey( uniqueKey ) ) {
marker = mAdasRecognizedMarkersCaches.get( uniqueKey );
}
if ( marker == null || marker.isDestroyed() ) {
marker = drawAdasRecognizedDataMarker( recognizedListResult, machineVision, curSpeed );
if ( marker == null ) {
continue;
}
mAdasRecognizedMarkersCaches.put( uniqueKey, marker );
}
if ( marker.getObject() instanceof MogoLatLng ) {
marker.setPosition( ( ( MogoLatLng ) marker.getObject() ).lat, ( ( MogoLatLng ) marker.getObject() ).lon );
}
List< MogoLatLng > points = new ArrayList<>();
MogoLatLng endLatLon = null;
if ( recognizedListResult.latLonList != null
&& recognizedListResult.latLonList.size() > 1 ) {
for ( int j = 0; j < recognizedListResult.latLonList.size(); j++ ) {
ADASRecognizedListResult.LatLon latLon = recognizedListResult.latLonList.get( j );
if ( latLon == null ) {
continue;
}
double targetPos[] = CoordinateUtils.transformFromWGSToGCJ( latLon.lat, latLon.lon );
points.add( endLatLon = new MogoLatLng( targetPos[POS_LAT], targetPos[POS_LON] ) );
}
} else if ( recognizedListResult.latLonList != null
&& recognizedListResult.latLonList.size() == 1 ) {
// 原来的点和新的点做一个数组进行平滑移动
MogoLatLng latLng = marker.getPosition();
ADASRecognizedListResult.LatLon latLon = recognizedListResult.latLonList.get( 0 );
if ( latLon == null ) {
continue;
}
points.add( latLng );
points.add( endLatLon = new MogoLatLng( latLng.lat, latLon.lon ) );
}
if ( endLatLon != null ) {
marker.setObject( endLatLon );
}
if ( points.size() >= 1 ) {
marker.startSmooth( points, 1 );
}
}
}
/**
* 过滤adas数据中不存在的 marker
*
* @param resultList
*/
private void purgeAdasRecognizedData( List< ADASRecognizedListResult > resultList ) {
if ( resultList == null || resultList.isEmpty() ) {
return;
}
if ( mAdasRecognizedMarkersCaches.isEmpty() ) {
return;
}
Map< String, IMogoMarker > existMarker = new HashMap<>();
for ( ADASRecognizedListResult recognizedListResult : resultList ) {
if ( recognizedListResult == null ) {
continue;
}
String uniqueKey = recognizedListResult.uuid;
if ( mAdasRecognizedMarkersCaches.containsKey( uniqueKey ) ) {
existMarker.put( uniqueKey, mAdasRecognizedMarkersCaches.get( uniqueKey ) );
}
}
if ( !existMarker.isEmpty() ) {
for ( String key : mAdasRecognizedMarkersCaches.keySet() ) {
if ( !existMarker.containsKey( key ) ) {
try {
IMogoMarker marker = mAdasRecognizedMarkersCaches.remove( key );
marker.destroy();
} catch ( Exception e ) {
e.printStackTrace();
}
}
}
}
}
private IMogoMarker drawAdasRecognizedDataMarker( ADASRecognizedListResult recognizedListResult,
boolean machineVision,
double curSpeed ) {
if ( recognizedListResult == null ) {
return null;
}
MogoMarkerOptions options = new MogoMarkerOptions()
.owner( DataTypes.TYPE_MARKER_ADAS )
.icon( inflateView( recognizedListResult, machineVision, curSpeed ) )
.gps( true )
.anchor( 0.5f, 0.5f )
.rotate( ( float ) recognizedListResult.heading )
.position( new MogoLatLng( recognizedListResult.latLonList.get( 0 ).lat, recognizedListResult.latLonList.get( 0 ).lon ) );
return MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( mContext ).addMarker( DataTypes.TYPE_MARKER_ADAS, options );
}
private View inflateView( ADASRecognizedListResult data, boolean machineVision, double curSpeed ) {
View rootView = LayoutInflater.from( AbsMogoApplication.getApp() ).inflate( R.layout.module_commons_layout_car, null );
// SafeType safeType = getSafeType( data.distanceX, data.distanceY, data.speed, curSpeed );
// TextView tv = rootView.findViewById( R.id.module_commons_marker_car_speed );
// tv.setText( safeType.getMsg() );
ImageView iv = rootView.findViewById( R.id.module_commons_marker_car_model );
// iv.setImageResource( MarkerResourceManager.getMarkerDrawableResId(
// machineVision ? VisionMode.Machine : VisionMode.User,
// AdasRecognizedType.valueFrom( data.type ),
// getCarModelType(),
// safeType
// ) );
iv.setImageResource( R.drawable.icon_map_marker_car_gray );
return rootView;
}
}

View File

@@ -0,0 +1,75 @@
package com.mogo.module.common.drawer;
import com.mogo.module.common.constants.CarModelType;
import com.mogo.module.common.constants.SafeType;
public
/**
* @author congtaowang
* @since 2020/10/30
* <p>
* 描述
*/
class BaseDrawer {
public static final int POS_LON = 1;
public static final int POS_LAT = 0;
public static final double BOUND_DISTANCE_DANGEROUS = 0.5;
public static final double BOUND_SPEED_DANGEROUS = 1.5;
public static final double BOUND_DISTANCE_WARM = 1;
public static final double BOUND_SPEED_WARM = 1.1;
/**
* 安全类型
*
* @param distance
* @param speed
* @param curSpeed
* @return
*/
protected SafeType getSafeType( double distance, double speed, double curSpeed ) {
if ( distance < BOUND_DISTANCE_DANGEROUS ) {
return SafeType.DistanceDangerous;
}
if ( speed > curSpeed * BOUND_SPEED_DANGEROUS ) {
return SafeType.SpeedDangerous;
}
if ( distance < BOUND_DISTANCE_WARM ) {
return SafeType.DistanceDangerous;
}
if ( speed > curSpeed * BOUND_SPEED_WARM ) {
return SafeType.DistanceWarm;
}
return SafeType.Normal;
}
protected SafeType getSafeType( double distanceX, double distanceY, double speed, double curSpeed ) {
if ( distanceX < BOUND_DISTANCE_DANGEROUS || distanceY < BOUND_DISTANCE_DANGEROUS ) {
return SafeType.DistanceDangerous;
}
if ( speed > curSpeed * BOUND_SPEED_DANGEROUS ) {
return SafeType.SpeedDangerous;
}
if ( distanceX < BOUND_DISTANCE_WARM || distanceY < BOUND_DISTANCE_WARM ) {
return SafeType.DistanceWarm;
}
if ( speed > curSpeed * BOUND_SPEED_WARM ) {
return SafeType.SpeedWarm;
}
return SafeType.Normal;
}
/**
* 车模
*
* @return
*/
protected CarModelType getCarModelType() {
// 根据车道、行驶方向等计算出选用哪个车模图片
return CarModelType.Other;
}
}

View File

@@ -0,0 +1,265 @@
package com.mogo.module.common.drawer;
import android.text.TextUtils;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.map.MogoLatLng;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.marker.IMogoMarkerClickListener;
import com.mogo.map.marker.MogoMarkerOptions;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.drawer.marker.IMarkerView;
import com.mogo.module.common.drawer.marker.MapMarkerAdapter;
import com.mogo.module.common.drawer.marker.OnlineCarMarkerView;
import com.mogo.module.common.entity.MarkerExploreWay;
import com.mogo.module.common.entity.MarkerNoveltyInfo;
import com.mogo.module.common.entity.MarkerOnlineCar;
import com.mogo.module.common.entity.MarkerShareMusic;
import com.mogo.module.common.entity.MarkerShowEntity;
import com.mogo.utils.logger.Logger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public
/**
* @author congtaowang
* @since 2020/10/28
* <p>
* 描述
*/
class MarkerDrawer {
public static final int MARKER_Z_INDEX_HIGH = 100;
public static final int MARKER_Z_INDEX_LOW = 2;
private static volatile MarkerDrawer sInstance;
private MarkerDrawer() {
}
public static MarkerDrawer getInstance() {
if ( sInstance == null ) {
synchronized ( MarkerDrawer.class ) {
if ( sInstance == null ) {
sInstance = new MarkerDrawer();
}
}
}
return sInstance;
}
public synchronized void release() {
sInstance = null;
}
private Object readResolve() {
// 阻止反序列化,必须实现 Serializable 接口
return sInstance;
}
public IMogoMarker drawMapMarkerImpl( MarkerShowEntity markerShowEntity, int zIndex, IMogoMarkerClickListener listener ) {
if ( markerShowEntity == null || markerShowEntity.getMarkerLocation() == null ) {
return null;
}
MogoMarkerOptions options = new MogoMarkerOptions().owner( markerShowEntity.getMarkerType() ).zIndex( zIndex ).object( markerShowEntity ).latitude( markerShowEntity.getMarkerLocation().getLat() ).longitude( markerShowEntity.getMarkerLocation().getLon() );
IMarkerView markerView = MapMarkerAdapter.getMarkerView( AbsMogoApplication.getApp(), markerShowEntity, options );
if ( markerView instanceof OnlineCarMarkerView ) {
try {
options.icon( markerView.getBitmap( ( ( MarkerOnlineCar ) markerShowEntity.getBindObj() ).getCarInfo().getVehicleType() ) );
} catch ( Exception e ) {
options.icon( markerView.getBitmap( 0 ) );
}
options.anchor( 0.5f, 0.5f );
} else {
options.icon( markerView.getView() );
}
IMogoMarker marker = MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( AbsMogoApplication.getApp() ).addMarker( markerShowEntity.getMarkerType(), options );
if ( marker != null ) {
marker.setOwner( markerShowEntity.getMarkerType() );
markerView.setMarker( marker );
marker.setOnMarkerClickListener( listener );
markerShowEntity.setMarker( marker );
}
return marker;
}
/**
* S = (A ∩ B) B
* A ∩ B)作为旧列表需要保留的部分
*
* @param newList
* @return
*/
public Map< String, IMogoMarker > purgeMarkerData( List newList, String markerType ) {
final long start = System.currentTimeMillis();
Map< String, IMogoMarker > existMap = new HashMap<>();
List< IMogoMarker > allCarsList = MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( AbsMogoApplication.getApp() ).getMarkers( markerType );
if ( allCarsList == null || allCarsList.isEmpty() ) {
return existMap;
}
if ( newList == null || newList.isEmpty() ) {
return existMap;
}
Map< String, IMogoMarker > allMap = new HashMap<>();
for ( IMogoMarker marker : allCarsList ) {
String sn = getPrimaryKeyFromMarker( marker );
allMap.put( sn, marker );
}
for ( Object entity : newList ) {
String sn = getPrimaryKeyFromEntity( entity );
if ( allMap.containsKey( sn ) ) {
if ( !isNewVehicleType( entity, allMap.get( sn ) ) ) {
existMap.put( sn, allMap.get( sn ) );
}
}
}
for ( String sn : allMap.keySet() ) {
if ( !existMap.containsKey( sn ) ) {
IMogoMarker dirtyMarker = allMap.get( sn );
allCarsList.remove( dirtyMarker );
if ( dirtyMarker != null ) {
dirtyMarker.destroy();
}
}
}
allMap.clear();
Logger.i( "timer", "purge data cost " + ( System.currentTimeMillis() - start ) + "ms" );
return existMap;
}
/**
* @param maxAmount 展示的最大数量
* @param list
* @return
*/
public int getAppropriateSize( int maxAmount, List list ) {
if ( list == null ) {
return 0;
}
return Math.min( maxAmount, list.size() );
}
private boolean isNewVehicleType( Object object, IMogoMarker marker ) {
if ( object instanceof MarkerOnlineCar
&& marker != null
&& marker.getObject() instanceof MarkerShowEntity
&& ( ( MarkerShowEntity ) marker.getObject() ).getBindObj() instanceof MarkerOnlineCar ) {
try {
return ( ( MarkerOnlineCar ) object ).getCarInfo().getVehicleType()
!= ( ( MarkerOnlineCar ) ( ( MarkerShowEntity ) marker.getObject() ).getBindObj() ).getCarInfo().getVehicleType();
} catch ( Exception e ) {
}
}
return false;
}
public String getPrimaryKeyFromEntity( Object entity ) {
if ( entity instanceof MarkerExploreWay ) {
String id = ( ( MarkerExploreWay ) entity ).getInfoId();
if ( !TextUtils.isEmpty( id ) ) {
return id;
}
}
return getCarSnFromEntity( entity );
}
private String getPrimaryKeyFromMarker( IMogoMarker marker ) {
if ( marker == null || marker.getObject() == null || marker.isDestroyed() ) {
return null;
}
if ( !( marker.getObject() instanceof MarkerShowEntity ) ) {
return null;
}
return getPrimaryKeyFromEntity( ( ( MarkerShowEntity ) marker.getObject() ).getBindObj() );
}
private String getCarSnFromEntity( Object entity ) {
try {
if ( entity instanceof MarkerOnlineCar ) {
return ( ( MarkerOnlineCar ) entity ).getUserInfo().getSn();
} else if ( entity instanceof MarkerShareMusic ) {
return ( ( MarkerShareMusic ) entity ).getUserInfo().getSn();
} else if ( entity instanceof MarkerNoveltyInfo ) {
return ( ( MarkerNoveltyInfo ) entity ).getSn();
} else if ( entity instanceof MarkerExploreWay ) {
return ( ( MarkerExploreWay ) entity ).getUserInfo().getSn();
}
} catch ( Exception e ) {
}
return "";
}
public String getCarSnFromMarker( IMogoMarker marker ) {
if ( marker == null || marker.getObject() == null || marker.isDestroyed() ) {
return null;
}
if ( !( marker.getObject() instanceof MarkerShowEntity ) ) {
return null;
}
return getCarSnFromEntity( ( ( MarkerShowEntity ) marker.getObject() ).getBindObj() );
}
/**
* 距离半径计算方式
*
* @param point1 点一坐标
* @param point2 点二坐标
* @return 两坐标的距离 单位M
*/
public static float calculateLineDistance( MogoLatLng point1, MogoLatLng point2 ) {
if ( point1 != null && point2 != null ) {
return calculateLineDistance( point1.lon, point1.lat, point2.lon, point2.lat );
} else {
return 0.0F;
}
}
/**
* @param lon1
* @param lat1
* @param lon2
* @param lat2
* @return 两坐标的距离 单位M
*/
public static float calculateLineDistance( double lon1, double lat1, double lon2, double lat2 ) {
try {
double var2 = lon1;
double var4 = lat1;
double var6 = lon2;
double var8 = lat2;
var2 *= 0.01745329251994329D;
var4 *= 0.01745329251994329D;
var6 *= 0.01745329251994329D;
var8 *= 0.01745329251994329D;
double var10 = Math.sin( var2 );
double var12 = Math.sin( var4 );
double var14 = Math.cos( var2 );
double var16 = Math.cos( var4 );
double var18 = Math.sin( var6 );
double var20 = Math.sin( var8 );
double var22 = Math.cos( var6 );
double var24 = Math.cos( var8 );
double[] var28 = new double[3];
double[] var29 = new double[3];
var28[0] = var16 * var14;
var28[1] = var16 * var10;
var28[2] = var12;
var29[0] = var24 * var22;
var29[1] = var24 * var18;
var29[2] = var20;
return ( float ) ( Math.asin( Math.sqrt( ( var28[0] - var29[0] ) * ( var28[0] - var29[0] ) + ( var28[1] - var29[1] ) * ( var28[1] - var29[1] ) + ( var28[2] - var29[2] ) * ( var28[2] - var29[2] ) ) / 2.0D ) * 1.27420015798544E7D );
} catch ( Throwable var26 ) {
var26.printStackTrace();
return 0.0F;
}
}
}

View File

@@ -0,0 +1,193 @@
package com.mogo.module.common.drawer;
import android.graphics.Rect;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.map.MogoLatLng;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.marker.IMogoMarkerClickListener;
import com.mogo.module.common.ModuleNames;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.entity.MarkerCarPois;
import com.mogo.module.common.entity.MarkerLocation;
import com.mogo.module.common.entity.MarkerOnlineCar;
import com.mogo.module.common.entity.MarkerShowEntity;
import com.mogo.utils.logger.Logger;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public
/**
* @author congtaowang
* @since 2020/10/28
*
* 描述
*/
class OnlineCarDrawer {
private static final String TAG = "OnlineCarDrawer";
// 平滑移动事件间隔(单位:秒)
private static final int SMOOTH_DURATION = 15;
private static volatile OnlineCarDrawer sInstance;
private OnlineCarDrawer() {
}
public static OnlineCarDrawer getInstance() {
if ( sInstance == null ) {
synchronized ( OnlineCarDrawer.class ) {
if ( sInstance == null ) {
sInstance = new OnlineCarDrawer();
}
}
}
return sInstance;
}
public synchronized void release() {
sInstance = null;
}
private Object readResolve() {
// 阻止反序列化,必须实现 Serializable 接口
return sInstance;
}
/**
* 绘制在线车辆marker
*
* @param onlineCarList
*/
public void drawOnlineCarMarkers( List< MarkerOnlineCar > onlineCarList,
int maxAmount,
boolean clearOld,
boolean showBounds,
Rect bound,
MogoLatLng centerPoint,
IMogoMarkerClickListener listener ) {
// 将数据同步给在线车辆,避免每次 perform 的时候去拉取,造成消耗
if ( onlineCarList == null || onlineCarList.isEmpty() ) {
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( AbsMogoApplication.getApp() ).removeMarkers( ModuleNames.CARD_TYPE_USER_DATA );
return;
}
if ( clearOld ) {
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( AbsMogoApplication.getApp() ).removeMarkers( ModuleNames.CARD_TYPE_USER_DATA );
}
int size = MarkerDrawer.getInstance().getAppropriateSize( maxAmount, onlineCarList );
Map< String, IMogoMarker > existCarMap = MarkerDrawer.getInstance().purgeMarkerData( onlineCarList, ModuleNames.CARD_TYPE_USER_DATA );
List< MogoLatLng > carPoints = new ArrayList<>();
for ( int i = 0; i < size; i++ ) {
MarkerOnlineCar markerOnlineCar = onlineCarList.get( i );
MarkerLocation markerLocation = markerOnlineCar.getLocation();
MarkerShowEntity markerShowEntity = new MarkerShowEntity();
markerShowEntity.setBindObj( markerOnlineCar );
markerShowEntity.setMarkerLocation( markerLocation );
markerShowEntity.setMarkerType( markerOnlineCar.getType() );
if ( markerOnlineCar.getCarInfo() != null ) {
markerShowEntity.setTextContent( markerOnlineCar.getUserInfo().getUserName() );
markerShowEntity.setIconUrl( markerOnlineCar.getUserInfo().getUserHead() );
}
if ( i <= 5 ) {
carPoints.add( new MogoLatLng( markerLocation.getLat(), markerLocation.getLon() ) );
}
String sn = MarkerDrawer.getInstance().getPrimaryKeyFromEntity( markerOnlineCar );
IMogoMarker mogoMarker = existCarMap.get( sn );
if ( mogoMarker == null || mogoMarker.isDestroyed() ) {
mogoMarker = MarkerDrawer.getInstance().drawMapMarkerImpl( markerShowEntity, MarkerDrawer.MARKER_Z_INDEX_LOW, listener );
}
if ( mogoMarker != null ) {
mogoMarker.setVisible( true );
}
startSmooth( mogoMarker, markerOnlineCar, markerLocation );
}
if ( showBounds && bound != null ) {
// 将前6个点显示在固定范围内
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController().showBounds( TAG, centerPoint, carPoints, bound, false );
}
}
// 平滑移动
private void startSmooth( IMogoMarker iMogoMarker, MarkerOnlineCar markerOnlineCar,
MarkerLocation markerLocation ) {
if ( iMogoMarker == null ) {
return;
}
List< MarkerCarPois > poiList = markerOnlineCar.getPois();
if ( filterErrorPoint( poiList ) ) {
return;
}
if ( poiList == null || poiList.size() < 2 ) {
return;
}
List< MogoLatLng > points = new ArrayList<>();
double lastLat = 0.0d;
double lastLon = 0.0d;
for ( int j = 0; j < poiList.size(); j++ ) {
MarkerCarPois poi = poiList.get( j );
if ( poi == null || poi.getCoordinates() == null && poi.getCoordinates().size() != 2 ) {
continue;
}
try {
double lat = Double.valueOf( poi.getCoordinates().get( 1 ) + "" );
double lng = Double.valueOf( poi.getCoordinates().get( 0 ) + "" );
float distance = MarkerDrawer.calculateLineDistance( lastLon, lastLat, lng, lat );
lastLon = lng;
lastLat = lat;
if ( distance < 0.2f ) {// 距离过短,认为静止不动
continue;
}
points.add( new MogoLatLng( lat, lng ) );
} catch ( Exception e ) {
}
}
if ( points.size() >= 1 ) {
iMogoMarker.startSmooth( points, SMOOTH_DURATION );
} else {
Logger.d( TAG, "静止小车,但是有相同的连续坐标" );
}
}
/**
* 有可能出现终点到起点跳跃的情况,需要用"500M"约束起点和终点
*
* @param poiList
*/
private boolean filterErrorPoint( List< MarkerCarPois > poiList ) {
if ( poiList == null || poiList.size() < 2 ) {
return false;
}
MarkerCarPois start = poiList.get( 0 );
MarkerCarPois end = poiList.get( poiList.size() - 1 );
try {
double lat1 = Double.valueOf( start.getCoordinates().get( 1 ) + "" );
double lng1 = Double.valueOf( start.getCoordinates().get( 0 ) + "" );
double lat2 = Double.valueOf( end.getCoordinates().get( 1 ) + "" );
double lng2 = Double.valueOf( end.getCoordinates().get( 0 ) + "" );
if ( MarkerDrawer.calculateLineDistance( new MogoLatLng( lat1, lng1 ), new MogoLatLng( lat2, lng2 ) ) >= 500 ) {
Logger.d( TAG, "filter point" );
return true;
}
} catch ( Exception e ) {
}
return false;
}
}

View File

@@ -0,0 +1,102 @@
package com.mogo.module.common.drawer;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.map.MogoLatLng;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.marker.MogoMarkerOptions;
import com.mogo.map.overlay.IMogoPolyline;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.constants.DataTypes;
import com.mogo.module.common.drawer.marker.MapVrMarkerView;
import com.mogo.module.common.entity.V2XPushMessageEntity;
import java.util.ArrayList;
import java.util.List;
/**
* @author donghongyu
* @since 2020/10/30
* TODO 推送路况信息绘制,用于演示
*/
public class PushRoadConditionDrawer {
private static final String TAG = "OnlineCarDrawer";
private static volatile PushRoadConditionDrawer sInstance;
private static IMogoPolyline mMogoPolyline;
private static IMogoMarker mMogoMarker;
private PushRoadConditionDrawer() {
}
public static PushRoadConditionDrawer getInstance() {
if (sInstance == null) {
synchronized (PushRoadConditionDrawer.class) {
if (sInstance == null) {
sInstance = new PushRoadConditionDrawer();
}
}
}
return sInstance;
}
public synchronized void release() {
clearMarker();
clearPolyline();
mMogoPolyline = null;
mMogoMarker = null;
sInstance = null;
}
private Object readResolve() {
// 阻止反序列化,必须实现 Serializable 接口
return sInstance;
}
/**
* 绘制路况事件Marker移动轨迹
*/
public void drawRoadConditionMarker(V2XPushMessageEntity entity) {
// 道路事件
MogoMarkerOptions options = new MogoMarkerOptions()
.object(entity)
.latitude(entity.getLat())
.longitude(entity.getLon());
options.anchor(0.5f, 0.5f);
options.icon(MapVrMarkerView.getInstance().getBitmap(entity.getSceneId()));
mMogoMarker =
MogoApisHandler
.getInstance()
.getApis()
.getMapServiceApi()
.getMarkerManager(AbsMogoApplication.getApp())
.addMarker(DataTypes.TYPE_MARKER_PUSH_DATA, options);
List<MogoLatLng> points = new ArrayList<>();
for (double[] doubles : entity.getMoveTrack()) {
points.add(new MogoLatLng(doubles[1], doubles[0]));
}
mMogoMarker.startSmooth(points, 10);
}
public void clearMarker() {
if (mMogoMarker != null) {
mMogoMarker.remove();
}
}
public void clearPolyline() {
if (mMogoPolyline != null) {
mMogoPolyline.remove();
mMogoPolyline = null;
}
}
}

View File

@@ -0,0 +1,128 @@
package com.mogo.module.common.drawer;
import android.view.animation.LinearInterpolator;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.marker.IMogoMarkerClickListener;
import com.mogo.map.marker.anim.OnMarkerAnimationListener;
import com.mogo.module.common.ModuleNames;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.entity.MarkerExploreWay;
import com.mogo.module.common.entity.MarkerLocation;
import com.mogo.module.common.entity.MarkerShowEntity;
import com.mogo.utils.WorkThreadHandler;
import com.mogo.utils.logger.Logger;
import java.util.List;
import java.util.Map;
public
/**
* @author congtaowang
* @since 2020/10/28
*
* 描述
*/
class RoadConditionDrawer {
private static final String TAG = "RoadConditionDrawer";
private static volatile RoadConditionDrawer sInstance;
private RoadConditionDrawer() {
}
public static RoadConditionDrawer getInstance() {
if ( sInstance == null ) {
synchronized ( RoadConditionDrawer.class ) {
if ( sInstance == null ) {
sInstance = new RoadConditionDrawer();
}
}
}
return sInstance;
}
public synchronized void release() {
sInstance = null;
}
private Object readResolve() {
// 阻止反序列化,必须实现 Serializable 接口
return sInstance;
}
/**
* 探路数据
*
* @param exploreWayList
*/
public void drawRoadConditionMarker( List< MarkerExploreWay > exploreWayList, int maxAmount, IMogoMarkerClickListener listener ) {
// 将数据同步给探路,避免探路每次 perform 的时候去拉取,造成消耗
if ( exploreWayList == null || exploreWayList.isEmpty() ) {
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( AbsMogoApplication.getApp() ).removeMarkers( ModuleNames.CARD_TYPE_ROAD_CONDITION );
return;
}
int size = MarkerDrawer.getInstance().getAppropriateSize( maxAmount, exploreWayList );
Map< String, IMogoMarker > existCarMap = MarkerDrawer.getInstance().purgeMarkerData( exploreWayList, ModuleNames.CARD_TYPE_ROAD_CONDITION );
Logger.i( TAG, "existCarMap: size = %d", existCarMap.size() );
for ( int i = 0; i < size; i++ ) {
MarkerExploreWay markerExploreWay = exploreWayList.get( i );
if ( !markerExploreWay.getCanLive() ) {
MarkerLocation markerLocation = markerExploreWay.getLocation();
MarkerShowEntity markerShowEntity = new MarkerShowEntity();
markerShowEntity.setBindObj( markerExploreWay );
markerShowEntity.setMarkerLocation( markerLocation );
markerShowEntity.setMarkerType( markerExploreWay.getType() );
markerShowEntity.setTextContent( markerExploreWay.getAddr() );
String sn = MarkerDrawer.getInstance().getPrimaryKeyFromEntity( markerExploreWay );
IMogoMarker mogoMarker = existCarMap.get( sn );
if ( mogoMarker == null || mogoMarker.isDestroyed() ) {
Logger.d( TAG, "draw road condition, sn = %s", sn );
try {
if ( DebugConfig.isRoadEventAnimated() ) {
post2AddAndStartAnimation( markerShowEntity, i * 100L, listener );
} else {
mogoMarker = MarkerDrawer.getInstance().drawMapMarkerImpl( markerShowEntity, MarkerDrawer.MARKER_Z_INDEX_HIGH, listener );
}
} catch ( Exception e ) {
e.printStackTrace();
}
}
}
}
}
private void post2AddAndStartAnimation( MarkerShowEntity entity, long delay, IMogoMarkerClickListener listener ) {
if ( entity == null ) {
return;
}
WorkThreadHandler.getInstance().postDelayed( () -> {
if ( entity == null ) {
return;
}
IMogoMarker marker = MarkerDrawer.getInstance().drawMapMarkerImpl( entity, MarkerDrawer.MARKER_Z_INDEX_HIGH, listener );
if ( marker == null ) {
return;
}
marker.startScaleAnimationWithAlpha( 0, 1.2f, 0, 1.2f, 0f, 1f, 300, new LinearInterpolator(), new OnMarkerAnimationListener() {
@Override
public void onAnimStart() {
Logger.d( TAG, " onAnimStart ---1----> " );
}
@Override
public void onAnimEnd() {
if ( marker == null || marker.isDestroyed() ) {
return;
}
marker.startScaleAnimation( 1.2f, 1, 1.2f, 1, 100, new LinearInterpolator(), null );
}
} );
}, delay );
}
}

View File

@@ -0,0 +1,251 @@
package com.mogo.module.common.drawer;
import android.content.Context;
import android.graphics.Bitmap;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.map.MogoLatLng;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.marker.MogoMarkerOptions;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.R;
import com.mogo.module.common.constants.AdasRecognizedType;
import com.mogo.module.common.constants.CarModelType;
import com.mogo.module.common.constants.DataTypes;
import com.mogo.module.common.constants.SafeType;
import com.mogo.module.common.constants.VisionMode;
import com.mogo.module.common.drawer.marker.MarkerResourceManager;
import com.mogo.module.common.entity.CloudLocationInfo;
import com.mogo.module.common.entity.CloudRoadData;
import com.mogo.module.common.entity.MogoSnapshotSetData;
import com.mogo.module.common.utils.CoordinateUtils;
import com.mogo.utils.UiThreadHandler;
import com.mogo.utils.logger.Logger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public
/**
* @author congtaowang
* @since 2020/10/28
*
* 云端数据绘制
*/
class SnapshotSetDataDrawer extends BaseDrawer {
private static final String TAG = "SnapshotSetDataDrawer";
private static volatile SnapshotSetDataDrawer sInstance;
private Context mContext;
private SnapshotSetDataDrawer() {
mContext = AbsMogoApplication.getApp();
}
public static SnapshotSetDataDrawer getInstance() {
if ( sInstance == null ) {
synchronized ( SnapshotSetDataDrawer.class ) {
if ( sInstance == null ) {
sInstance = new SnapshotSetDataDrawer();
}
}
}
return sInstance;
}
public synchronized void release() {
sInstance = null;
}
private Object readResolve() {
// 阻止反序列化,必须实现 Serializable 接口
return sInstance;
}
// 云端 marker 缓存
private Map< String, IMogoMarker > mCloudSnapshotMarkersCaches = new ConcurrentHashMap<>();
private int mPurseCounter = 0;
private Map< String, MogoLatLng > mLastPositions = new ConcurrentHashMap<>();
/**
* 其他车辆、rsu 车辆数据
*
* @param data
*/
public void renderSnapshotData( MogoSnapshotSetData data,
boolean machineVision ) {
if ( data == null || (
( data.getAllList() == null || data.getAllList().isEmpty() ) &&
( data.getNearList() == null || data.getNearList().isEmpty() )
) ) {
MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( AbsMogoApplication.getApp() ).removeMarkers( DataTypes.TYPE_MARKER_CLOUD_DATA );
return;
}
List< CloudRoadData > allDatumsList = new ArrayList<>();
allDatumsList.addAll( data.getAllList() );
// allDatumsList.addAll( data.getNearList() );
// if ( machineVision ) {
// allDatumsList.addAll( data.getAllList() );
// allDatumsList.addAll( data.getNearList() );
// } else {
// allDatumsList.addAll( data.getAllList() );
// }
mPurseCounter++;
if ( mPurseCounter >= 100 ) {
mPurseCounter = 0;
}
purgeCloudSnapshotData( allDatumsList );
for ( CloudRoadData cloudRoadData : allDatumsList ) {
if ( cloudRoadData == null ) {
continue;
}
IMogoMarker marker = null;
String uniqueKey = cloudRoadData.getUniqueKey();
if ( TextUtils.isEmpty( uniqueKey ) ) {
continue;
}
if ( mCloudSnapshotMarkersCaches.containsKey( uniqueKey ) ) {
marker = mCloudSnapshotMarkersCaches.get( uniqueKey );
}
MogoLatLng target = new MogoLatLng( cloudRoadData.getLat(), cloudRoadData.getLon() );
if ( marker == null || marker.isDestroyed() ) {
marker = drawSnapshotDataMarker( cloudRoadData, machineVision, data.curSpeed );
if ( marker == null ) {
continue;
}
mCloudSnapshotMarkersCaches.put( uniqueKey, marker );
} else {
marker.setGps( false );
MogoLatLng lastPosition = mLastPositions.get( uniqueKey );
double targetPos[] = CoordinateUtils.transformFromWGSToGCJ( target.lat, target.lon );
if ( lastPosition != null ) {
if ( lastPosition.equals( target ) ) {
marker.setRotateAngle( 360 - ( float ) cloudRoadData.getHeading() );
marker.setPosition( targetPos[POS_LAT], targetPos[POS_LON] );
} else {
List< MogoLatLng > points = new ArrayList<>();
double lastPos[] = CoordinateUtils.transformFromWGSToGCJ( lastPosition.lat, lastPosition.lon );
points.add( new MogoLatLng( lastPos[POS_LAT], lastPos[POS_LON] ) );
points.add( new MogoLatLng( targetPos[POS_LAT], targetPos[POS_LON] ) );
marker.startSmooth( points, 1 );
}
} else {
marker.setRotateAngle( 360 - ( float ) cloudRoadData.getHeading() );
marker.setPosition( targetPos[POS_LAT], targetPos[POS_LON] );
}
}
mLastPositions.put( uniqueKey, target );
}
}
/**
* 过滤本次数据中,不存在的 marker
*
* @param data
*/
private void purgeCloudSnapshotData( List< CloudRoadData > data ) {
if ( data == null || data.isEmpty() ) {
return;
}
if ( mCloudSnapshotMarkersCaches.isEmpty() ) {
return;
}
Map< String, IMogoMarker > existMarker = new HashMap<>();
for ( CloudRoadData cloudRoadData : data ) {
if ( cloudRoadData == null ) {
continue;
}
String uniqueKey = cloudRoadData.getUniqueKey();
if ( TextUtils.isEmpty( uniqueKey ) ) {
continue;
}
if ( mCloudSnapshotMarkersCaches.containsKey( uniqueKey ) ) {
existMarker.put( uniqueKey, mCloudSnapshotMarkersCaches.get( uniqueKey ) );
}
}
if ( !existMarker.isEmpty() ) {
for ( String key : mCloudSnapshotMarkersCaches.keySet() ) {
if ( !existMarker.containsKey( key ) ) {
mLastPositions.remove( key );
try {
IMogoMarker marker = mCloudSnapshotMarkersCaches.remove( key );
marker.destroy();
} catch ( Exception e ) {
e.printStackTrace();
}
}
}
}
}
private IMogoMarker drawSnapshotDataMarker( CloudRoadData data, boolean machineVision, double curSpeed ) {
if ( data == null ) {
return null;
}
Logger.d( TAG, "draw marker uniqueKey = %s", data.getUniqueKey() );
MogoMarkerOptions options = new MogoMarkerOptions()
.owner( DataTypes.TYPE_MARKER_CLOUD_DATA )
.icon( inflateView( data, machineVision, curSpeed ) )
.gps( true )
.anchor( 0.5f, 0.5f )
.rotate( ( float ) data.getHeading() )
.position( new MogoLatLng( data.getLat(), data.getLon() ) );
return MogoApisHandler.getInstance().getApis().getMapServiceApi().getMarkerManager( mContext ).addMarker( DataTypes.TYPE_MARKER_CLOUD_DATA, options );
}
private View inflateView( CloudRoadData data, boolean machineVision, double curSpeed ) {
View rootView = LayoutInflater.from( AbsMogoApplication.getApp() ).inflate( R.layout.module_commons_layout_car, null );
// SafeType safeType = getSafeType( data.getDistance(), data.getSpeed(), curSpeed );
// TextView tv = rootView.findViewById( R.id.module_commons_marker_car_speed );
// // 机器视觉展示速度,用户视觉展示安全类型
// tv.setText( machineVision ? String.valueOf( data.getSpeed() ) : safeType.getMsg() );
ImageView iv = rootView.findViewById( R.id.module_commons_marker_car_model );
// iv.setImageResource( MarkerResourceManager.getMarkerDrawableResId(
// machineVision ? VisionMode.Machine : VisionMode.User,
// AdasRecognizedType.valueFrom( data.getType() ),
// getCarModelType(),
// safeType
// ) );
iv.setImageResource( R.drawable.icon_map_marker_car_gray );
return rootView;
}
private 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 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

@@ -0,0 +1,23 @@
package com.mogo.module.common.drawer.marker;
import android.graphics.Bitmap;
import android.view.View;
import com.mogo.map.marker.IMogoMarker;
/**
* @author congtaowang
* @since 2020-02-15
* <p>
* 描述
*/
public interface IMarkerView {
View getView();
default Bitmap getBitmap( int type ){
return null;
}
void setMarker( IMogoMarker marker );
}

View File

@@ -0,0 +1,39 @@
package com.mogo.module.common.drawer.marker;
import android.content.Context;
import android.text.TextUtils;
import com.mogo.map.marker.MogoMarkerOptions;
import com.mogo.module.common.ModuleNames;
import com.mogo.module.common.entity.MarkerShowEntity;
/**
* author : donghongyu
* e-mail : 1358506549@qq.com
* date : 2020-01-1015:55
* desc : 地图Marker的适配器
* version: 1.0
*/
public class MapMarkerAdapter {
/**
* 获取 MarkerShowEntity 填充好的 MarkerView
*
* @param context 上下文
* @param markerShowEntity 要填充的数据
* @return MarkerView
*/
public static IMarkerView getMarkerView(Context context, MarkerShowEntity markerShowEntity, MogoMarkerOptions options) {
if ( TextUtils.equals( markerShowEntity.getMarkerType(), ModuleNames.CARD_TYPE_USER_DATA ) ) {
return OnlineCarMarkerView.getInstance();
} else {
if (markerShowEntity.isChecked()) {
return new MapMarkerInfoView(context, markerShowEntity, options);
} else {
return new MapMarkerView(context, markerShowEntity, options);
}
}
}
}

View File

@@ -0,0 +1,178 @@
package com.mogo.module.common.drawer.marker;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Looper;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.Nullable;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.marker.MogoMarkerOptions;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.R;
import com.mogo.module.common.entity.MarkerShowEntity;
import com.mogo.service.imageloader.IMogoImageLoaderListener;
import com.mogo.service.imageloader.MogoImageView;
import com.mogo.utils.UiThreadHandler;
import com.mogo.utils.WindowUtils;
import com.mogo.utils.logger.Logger;
/**
* author : donghongyu
* e-mail : 1358506549@qq.com
* date : 2020-01-1310:55
* desc : 地图上抽离的Marker的共性
* version: 1.0
*/
public abstract class MapMarkerBaseView extends LinearLayout implements IMarkerView {
private String TAG = "MapMarkerBaseView";
protected Context mContext;
protected MogoMarkerOptions mOptions;
protected MogoImageView ivUserHead;
protected MogoImageView ivIcon;
protected ImageView ivCar;
protected IMogoMarker mMarker;
public MapMarkerBaseView(Context context) {
super(context);
mContext = context;
initView(context);
}
public MapMarkerBaseView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
mContext = context;
initView(context);
}
public MapMarkerBaseView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mContext = context;
initView(context);
}
@Override
public void setMarker( IMogoMarker marker ) {
this.mMarker = marker;
}
protected abstract void initView( Context context);
public abstract void updateView(MarkerShowEntity markerShowEntity);
protected void loadImageWithMarker(final MarkerShowEntity markerShowEntity) {
if ( Looper.myLooper() != Looper.getMainLooper() ) {
UiThreadHandler.post( ()-> {
runOnUiThread( markerShowEntity );
});
} else {
runOnUiThread( markerShowEntity );
}
}
protected void loadPoiTypeIcon(String url,int res) {
ivIcon.setImageResource(res);
if ( Looper.myLooper() != Looper.getMainLooper() ) {
UiThreadHandler.post( ()-> loadPoiTypeIconInUiThread(url, res));
} else {
loadPoiTypeIconInUiThread(url, res);
}
}
private void loadPoiTypeIconInUiThread(String url,int res) {
if (!url.isEmpty()) {
ivIcon.setPlaceHolder(res);
ivIcon.setFailureHolder(res);
MogoApisHandler.getInstance().getApis().getImageLoaderApi().displayImage(url,
ivIcon, WindowUtils.dip2px(mContext, 50), WindowUtils.dip2px(mContext, 50),
new IMogoImageLoaderListener() {
@Override
public void onStart() {
}
@Override
public void onCompleted(Bitmap bitmap) {
// 使用view渲染地图marker刷新纹理的时候需要重新用view生成纹理然后在设置
if (mMarker != null) {
mMarker.setIcon(fromView(MapMarkerBaseView.this));
}
}
@Override
public void onFailure(Exception e) {
}
});
}
}
private void runOnUiThread(final MarkerShowEntity markerShowEntity){
if (!TextUtils.isEmpty(markerShowEntity.getIconUrl())) {
MogoApisHandler.getInstance().getApis().getImageLoaderApi().displayImage(markerShowEntity.getIconUrl(),
ivUserHead,
WindowUtils.dip2px(mContext, 50), WindowUtils.dip2px(mContext, 50),
new IMogoImageLoaderListener() {
@Override
public void onStart() {
}
@Override
public void onCompleted(Bitmap bitmap) {
Logger.d(TAG, "loadImageWithMarker loaded.");
// 使用view渲染地图marker刷新纹理的时候需要重新用view生成纹理然后在设置
if ( mMarker != null ) {
mMarker.setIcon( fromView( MapMarkerBaseView.this ) );
}
}
@Override
public void onFailure(Exception e) {
Logger.e(TAG, "loadImageWithMarker onFailure.");
}
});
} else {
ivUserHead.setBackgroundResource( R.drawable.icon_default_user_head);
}
}
private Bitmap fromView( View view ) {
view.setDrawingCacheEnabled( true );
processChildView( view );
view.destroyDrawingCache();
view.measure( MeasureSpec.makeMeasureSpec( 0, MeasureSpec.UNSPECIFIED ), MeasureSpec.makeMeasureSpec( 0, 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 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 ) );
}
}
}
@Override
public View getView() {
return this;
}
}

View File

@@ -0,0 +1,146 @@
package com.mogo.module.common.drawer.marker;
import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.mogo.map.marker.MogoMarkerOptions;
import com.mogo.module.common.ModuleNames;
import com.mogo.module.common.entity.MarkerExploreWay;
import com.mogo.module.common.entity.MarkerShareMusic;
import com.mogo.module.common.entity.MarkerShowEntity;
import com.mogo.module.common.marker.PoiWrapper;
import com.mogo.module.common.utils.CloudPoiManager;
import com.mogo.module.common.R;
import com.mogo.utils.logger.Logger;
/**
* author : donghongyu
* e-mail : 1358506549@qq.com
* date : 2020-01-0619:55
* desc : 地图Marker图标带文本信息
* version: 1.0
*/
public class MapMarkerInfoView extends MapMarkerBaseView {
private String TAG = "MapMarkerInfoView";
private TextView tvMarkerContent;
private ConstraintLayout clMarkerContent;
private ImageView ivReverseTriangle;
public MapMarkerInfoView( Context context ) {
super( context );
}
public MapMarkerInfoView( Context context, @Nullable AttributeSet attrs ) {
super( context, attrs );
}
public MapMarkerInfoView( Context context, @Nullable AttributeSet attrs, int defStyleAttr ) {
super( context, attrs, defStyleAttr );
}
public MapMarkerInfoView( Context context, MarkerShowEntity markerShowEntity, MogoMarkerOptions options ) {
super( context );
mOptions = options;
updateView( markerShowEntity );
}
@Override
protected void initView( Context context ) {
LayoutInflater.from( context ).inflate( R.layout.modudle_services_marker_layout_info, this );
ivUserHead = findViewById( R.id.ivUserHead );
// ivIcon = findViewById( R.id.ivIcon );
ivIcon = findViewById(R.id.ivIcon);
clMarkerContent = findViewById( R.id.clMarkerContent );
ivReverseTriangle = findViewById( R.id.ivReverseTriangle );
ivCar = findViewById( R.id.ivCar );
tvMarkerContent = findViewById( R.id.tvMarkerContent );
}
@Override
public void updateView( MarkerShowEntity markerShowEntity ) {
try {
Object bindObj = markerShowEntity.getBindObj();
ivCar.setImageResource( R.drawable.icon_map_marker_location_yellow );
clMarkerContent.setBackgroundResource( R.drawable.bg_map_marker_yellow_info );
ivReverseTriangle.setImageResource( R.drawable.bg_shape_reverse_yellow );
switch ( markerShowEntity.getMarkerType() ) {
case ModuleNames.CARD_TYPE_CARS_CHATTING:
case ModuleNames.CARD_TYPE_USER_DATA:
ivUserHead.setVisibility( View.VISIBLE );
ivIcon.setVisibility( View.INVISIBLE );
loadImageWithMarker( markerShowEntity );
ivCar.setImageResource( R.drawable.icon_map_marker_car_gray );
//ivCar.setRotation(new Random().nextInt(360));
ivCar.setRotation( ( float ) markerShowEntity.getMarkerLocation().getAngle() );
break;
case ModuleNames.CARD_TYPE_ROAD_CONDITION:
case ModuleNames.CARD_TYPE_NOVELTY:
ivUserHead.setVisibility( View.INVISIBLE );
ivIcon.setVisibility( View.VISIBLE );
if ( bindObj instanceof MarkerExploreWay && ( ( MarkerExploreWay ) bindObj ).getPoiType() != null ) {
// 根据poiType获取对应的图片
String poiType = ((MarkerExploreWay) bindObj).getPoiType();
PoiWrapper poiWrapper =
CloudPoiManager.getInstance().getWrapperByPoiType(poiType);
if (poiWrapper != null) {
// 加载图片
loadPoiTypeIcon(poiWrapper.getIconInfoUrl(),poiWrapper.getIconInfoRes());
}else{
Logger.e(TAG, "未能根据poiType获取对应poi信息无法渲染info marker====" + poiType);
}
}
break;
case ModuleNames.CARD_TYPE_SHARE_MUSIC:
ivUserHead.setVisibility( View.INVISIBLE );
ivIcon.setVisibility( View.VISIBLE );
if ( bindObj instanceof MarkerShareMusic ) {
// 2 为书籍听书3 为新闻,1 为qq音乐,int
switch ( ( ( MarkerShareMusic ) bindObj ).getShareType() ) {
case 1:
ivIcon.setImageResource( R.drawable.icon_map_marker_misic );
break;
case 2:
ivIcon.setImageResource( R.drawable.icon_map_marker_book );
break;
case 3:
ivIcon.setImageResource( R.drawable.icon_map_marker_news );
break;
default:
ivIcon.setImageResource( R.drawable.icon_map_marker_misic );
break;
}
}
break;
default:
break;
}
if ( !TextUtils.isEmpty( markerShowEntity.getTextContent() ) ) {
String content;
if ( markerShowEntity.getTextContent().length() > 8 ) {
content = markerShowEntity.getTextContent().substring( 0, 7 ) + "...";
} else {
content = markerShowEntity.getTextContent();
}
tvMarkerContent.setText( content );
}
} catch ( Exception e ) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,89 @@
package com.mogo.module.common.drawer.marker;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import androidx.annotation.Nullable;
import com.mogo.map.marker.MogoMarkerOptions;
import com.mogo.module.common.ModuleNames;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.module.common.R;
import com.mogo.module.common.entity.MarkerExploreWay;
import com.mogo.module.common.entity.MarkerShowEntity;
import com.mogo.module.common.marker.PoiWrapper;
import com.mogo.module.common.utils.CloudPoiManager;
import com.mogo.utils.logger.Logger;
/**
* author : donghongyu
* e-mail : 1358506549@qq.com
* date : 2020-01-0619:55
* desc : 地图Marker图标
* version: 1.0
*/
public class MapMarkerView extends MapMarkerBaseView {
private String TAG = "MapMarkerView";
public MapMarkerView( Context context ) {
super( context );
}
public MapMarkerView( Context context, @Nullable AttributeSet attrs ) {
super( context, attrs );
}
public MapMarkerView( Context context, @Nullable AttributeSet attrs, int defStyleAttr ) {
super( context, attrs, defStyleAttr );
}
public MapMarkerView( Context context, MarkerShowEntity markerShowEntity, MogoMarkerOptions options ) {
super( context );
mOptions = options;
updateView( markerShowEntity );
}
@Override
protected void initView( Context context ) {
LayoutInflater.from( context ).inflate( R.layout.modudle_services_marker_layout, this );
ivIcon = findViewById( R.id.ivIcon );
ivCar = findViewById( R.id.ivCar );
}
@Override
public void updateView( MarkerShowEntity markerShowEntity ) {
try {
Object bindObj = markerShowEntity.getBindObj();
if ( MogoApisHandler.getInstance().getApis().getMapFrameControllerApi().isVrMode() ) {
ivCar.setImageResource( R.drawable.icon_map_marker_location_yellow_vr );
} else {
ivCar.setImageResource( R.drawable.icon_map_marker_location_yellow );
}
switch ( markerShowEntity.getMarkerType() ) {
case ModuleNames.CARD_TYPE_ROAD_CONDITION:
case ModuleNames.CARD_TYPE_NOVELTY:
if ( bindObj instanceof MarkerExploreWay && ( ( MarkerExploreWay ) bindObj ).getPoiType() != null ) {
// 根据poiType获取对应的图片
String poiType = ((MarkerExploreWay) bindObj).getPoiType();
PoiWrapper poiWrapper =
CloudPoiManager.getInstance().getWrapperByPoiType(poiType);
if (poiWrapper != null) {
// 加载图片
loadPoiTypeIcon(poiWrapper.getIconUrl(),poiWrapper.getIconRes());
}else{
Logger.e(TAG, "未能根据poiType获取对应poi信息无法渲染marker====" + poiType);
}
}
break;
default:
break;
}
} catch ( Exception e ) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,88 @@
package com.mogo.module.common.drawer.marker;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.module.common.R;
import java.lang.ref.SoftReference;
import java.util.HashMap;
import java.util.Map;
/**
* VR 模式的Marker绘制
*/
public class MapVrMarkerView implements IMarkerView {
private String TAG = "MapVrMarkerView";
private static Map<String, SoftReference<Bitmap>> sRef = new HashMap<>();
private static Map<String, SoftReference<Bitmap>> sTypedRef = new HashMap<>();
private static final class InstanceHolder {
private static final MapVrMarkerView INSTANCE = new MapVrMarkerView();
}
public static MapVrMarkerView getInstance() {
return MapVrMarkerView.InstanceHolder.INSTANCE;
}
private Object readResolve() {
// 阻止反序列化,必须实现 Serializable 接口
return MapVrMarkerView.InstanceHolder.INSTANCE;
}
@Override
public View getView() {
return null;
}
@Override
public void setMarker(IMogoMarker marker) {
}
@Override
public Bitmap getBitmap(int vehicleType) {
return null;
}
/**
* TODO 都是模拟数据
* 获取VR道路事件
*/
public Bitmap getBitmap(String sceneId) {
sRef.put(sceneId, new SoftReference<>(BitmapFactory.decodeResource(AbsMogoApplication.getApp().getResources(), R.drawable.icon_map_marker_car_type_taxi)));
switch (sceneId) {
case "200001"://后方VIP车辆提示
// bitmap = ImageUtil.createBitmap(V2XUtils.getApp(),
// R.drawable.v2x_duixiang_laiche_che);
break;
case "200002"://前车急刹
break;
case "200003"://后方危险车辆预警
break;
case "200004"://逆向车辆路线预判
// bitmap = ImageUtil.createBitmap(V2XUtils.getApp(),
// R.drawable.v2x_duixiang_laiche_che);
break;
case "200005"://VIP变灯通行
break;
case "200006"://障碍物绕行
break;
case "200007"://行人预警,行人路线预测
break;
case "200008"://拥堵路线推荐
break;
case "200009"://双闪车辆,自动绕行
break;
}
return sRef.get(sceneId).get();
}
}

View File

@@ -0,0 +1,69 @@
package com.mogo.module.common.drawer.marker;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.module.common.R;
import com.mogo.module.common.constants.AdasRecognizedType;
import com.mogo.module.common.constants.CarModelType;
import com.mogo.module.common.constants.SafeType;
import com.mogo.module.common.constants.VisionMode;
import com.mogo.utils.logger.Logger;
public
/**
* @author congtaowang
* @since 2020/10/29
* <p>
* 描述 按照命名规则用字符串拼接成资源名称的方式拿到图片的id避免枚举
*/
class MarkerResourceManager {
private static final String TAG = "MarkerResourceManager";
/**
* @param mode
* @param adasRecognizedType
* @param type
* @return
*/
public static int getMarkerDrawableResId( VisionMode mode,
AdasRecognizedType adasRecognizedType,
CarModelType type,
SafeType safeType ) {
if ( mode == null ) {
mode = VisionMode.User;
}
if ( adasRecognizedType == null ) {
adasRecognizedType = AdasRecognizedType.classIdCar;
}
if ( type == null ) {
type = CarModelType.Other;
}
if ( safeType == null ) {
safeType = SafeType.Normal;
}
StringBuilder builder = new StringBuilder();
builder.append( "module_commons" )
.append( "_" ).append( mode.getRes() )
.append( "_" ).append( adasRecognizedType.getRes() )
.append( "_" ).append( type.getRes() )
.append( "_" ).append( safeType.getRes() );
Logger.d( TAG, "res name = %s", builder.toString() );
int id = AbsMogoApplication.getApp().getResources().getIdentifier(
builder.toString(),
"drawable",
AbsMogoApplication.getApp().getPackageName() );
if ( id == 0 ) {
if ( mode == VisionMode.User ) {
return R.drawable.module_commons_user_car_other_normal;
} else {
return R.drawable.module_commons_machine_car_other_normal;
}
}
return id;
}
}

View File

@@ -0,0 +1,93 @@
package com.mogo.module.common.drawer.marker;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.module.common.R;
import java.lang.ref.SoftReference;
import java.util.HashMap;
import java.util.Map;
/**
* @author congtaowang
* @since 2020-04-30
* <p>
* 描述
*/
public class OnlineCarMarkerView implements IMarkerView {
private static Map< Integer, SoftReference< Bitmap > > sRef = new HashMap<>();
private static Map< Integer, SoftReference< Bitmap > > sTypedRef = new HashMap<>();
private OnlineCarMarkerView() {
// private constructor
}
private static final class InstanceHolder {
private static final OnlineCarMarkerView INSTANCE = new OnlineCarMarkerView();
}
public static OnlineCarMarkerView getInstance() {
return InstanceHolder.INSTANCE;
}
private Object readResolve() {
// 阻止反序列化,必须实现 Serializable 接口
return InstanceHolder.INSTANCE;
}
@Override
public View getView() {
return null;
}
@Override
public Bitmap getBitmap( int vehicleType ) {
if ( sRef.get( vehicleType ) == null || sRef.get( vehicleType ).get() == null
|| sRef.get( vehicleType ).get().isRecycled() ) {
switch ( vehicleType ) {
case 5:
sRef.put( vehicleType, new SoftReference<>( BitmapFactory.decodeResource( AbsMogoApplication.getApp().getResources(), R.drawable.icon_map_marker_car_type_taxi ) ) );
break;
case 6:
sRef.put( vehicleType, new SoftReference<>( BitmapFactory.decodeResource( AbsMogoApplication.getApp().getResources(), R.drawable.icon_map_marker_car_type_bus ) ) );
break;
case 1:
sRef.put( vehicleType, new SoftReference<>( BitmapFactory.decodeResource( AbsMogoApplication.getApp().getResources(), R.drawable.icon_map_marker_car_type_110 ) ) );
break;
case 2:
sRef.put( vehicleType, new SoftReference<>( BitmapFactory.decodeResource( AbsMogoApplication.getApp().getResources(), R.drawable.icon_map_marker_car_type_120 ) ) );
break;
case 7:
sRef.put( vehicleType, new SoftReference<>( BitmapFactory.decodeResource( AbsMogoApplication.getApp().getResources(), R.drawable.icon_map_marker_car_type_119 ) ) );
break;
default:
sRef.put( vehicleType, new SoftReference<>( BitmapFactory.decodeResource( AbsMogoApplication.getApp().getResources(), R.drawable.icon_map_marker_car_gray ) ) );
}
}
return sRef.get( vehicleType ).get();
}
public Bitmap getSelectedBitmap( int vehicleType ) {
if ( sTypedRef.get( vehicleType ) == null || sTypedRef.get( vehicleType ).get() == null
|| sTypedRef.get( vehicleType ).get().isRecycled() ) {
switch ( vehicleType ) {
case 2:
sTypedRef.put( vehicleType, new SoftReference<>( BitmapFactory.decodeResource( AbsMogoApplication.getApp().getResources(), R.drawable.icon_map_marker_car_type2 ) ) );
break;
default:
sTypedRef.put( vehicleType, new SoftReference<>( BitmapFactory.decodeResource( AbsMogoApplication.getApp().getResources(), R.drawable.icon_map_marker_car_gray_selected ) ) );
}
}
return sTypedRef.get( vehicleType ).get();
}
@Override
public void setMarker( IMogoMarker marker ) {
}
}

View File

@@ -0,0 +1,164 @@
package com.mogo.module.common.entity;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.Objects;
/**
* 云端定位信息和自车定位信息
*
* @author tongchenfei
*/
public class CloudLocationInfo implements Parcelable {
private double lat;
private double lon;
private double heading;
private long systemTime;
private long satelliteTime;
private double alt;
private double speed;
public CloudLocationInfo() {
}
public CloudLocationInfo(CloudLocationInfo info) {
this.lat = info.getLat();
this.lon = info.getLon();
this.heading = info.getHeading();
this.systemTime = System.currentTimeMillis();
this.satelliteTime = System.currentTimeMillis();
this.alt = info.alt;
this.speed = info.speed;
}
protected CloudLocationInfo(Parcel in) {
lat = in.readDouble();
lon = in.readDouble();
heading = in.readDouble();
systemTime = in.readLong();
satelliteTime = in.readLong();
alt = in.readDouble();
speed = in.readDouble();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeDouble(lat);
dest.writeDouble(lon);
dest.writeDouble(heading);
dest.writeLong(systemTime);
dest.writeLong(satelliteTime);
dest.writeDouble(alt);
dest.writeDouble(speed);
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<CloudLocationInfo> CREATOR = new Creator<CloudLocationInfo>() {
@Override
public CloudLocationInfo createFromParcel(Parcel in) {
return new CloudLocationInfo(in);
}
@Override
public CloudLocationInfo[] newArray(int size) {
return new CloudLocationInfo[size];
}
};
public double getLat() {
return lat;
}
public void setLat(double lat) {
this.lat = lat;
}
public double getLon() {
return lon;
}
public void setLon(double lon) {
this.lon = lon;
}
public double getHeading() {
return heading;
}
public void setHeading(double heading) {
this.heading = heading;
}
public long getSystemTime() {
return systemTime;
}
public void setSystemTime(long systemTime) {
this.systemTime = systemTime;
}
public long getSatelliteTime() {
return satelliteTime;
}
public void setSatelliteTime(long satelliteTime) {
this.satelliteTime = satelliteTime;
}
public double getAlt() {
return alt;
}
public void setAlt(double alt) {
this.alt = alt;
}
public double getSpeed() {
return speed;
}
public void setSpeed(double speed) {
this.speed = speed;
}
@Override
public String toString() {
return "CloudLocationInfo{" +
"lat=" + lat +
", lon=" + lon +
", heading=" + heading +
", systemTime=" + systemTime +
", satelliteTime=" + satelliteTime +
", alt=" + alt +
", speed=" + speed +
'}';
}
public String print() {
return "CloudLocation{ lon: " + lon + " lat: " + lat + " heading: " + heading + " speed: "
+ speed+"}";
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
CloudLocationInfo that = (CloudLocationInfo) o;
return Double.compare(that.lat, lat) == 0 &&
Double.compare(that.lon, lon) == 0;
}
@Override
public int hashCode() {
return Objects.hash(lat, lon);
}
}

View File

@@ -0,0 +1,195 @@
package com.mogo.module.common.entity;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import java.util.List;
/**
* 云端道路数据
* @author tongchenfei
*/
public class CloudRoadData implements Parcelable {
/**物体类型*/
private int type = -1;
private double lat;
private double lon;
private String uuid;
private String sn;
private double speed;
private double heading;
private long systemTime;
/**红绿灯状态 1红 2绿 3黄*/
private int lightStatus;//
/**红绿灯剩余时间 读秒*/
private int lightLeftTime;
/**视频流直播地址*/
private String rtmpUrl;//
private double distance ;//距离
private List<CloudLocationInfo> coordinates;
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public double getLat() {
return lat;
}
public void setLat(double lat) {
this.lat = lat;
}
public double getLon() {
return lon;
}
public void setLon(double lon) {
this.lon = lon;
}
public double getSpeed() {
return speed;
}
public void setSpeed(double speed) {
this.speed = speed;
}
public long getSystemTime() {
return systemTime;
}
public void setSystemTime(long systemTime) {
this.systemTime = systemTime;
}
public int getLightStatus() {
return lightStatus;
}
public void setLightStatus(int lightStatus) {
this.lightStatus = lightStatus;
}
public int getLightLeftTime() {
return lightLeftTime;
}
public void setLightLeftTime(int lightLeftTime) {
this.lightLeftTime = lightLeftTime;
}
public String getRtmpUrl() {
return rtmpUrl;
}
public void setRtmpUrl(String rtmpUrl) {
this.rtmpUrl = rtmpUrl;
}
public double getDistance() {
return distance * 1000;
}
public void setDistance(double distance) {
this.distance = distance;
}
public List<CloudLocationInfo> getCoordinates() {
return coordinates;
}
public void setCoordinates(List<CloudLocationInfo> coordinates) {
this.coordinates = coordinates;
}
public String getUuid() {
return uuid;
}
public String getSn() {
return sn;
}
public double getHeading() {
return heading;
}
public void setHeading( double heading ) {
this.heading = heading;
}
public String getUniqueKey(){
if (! TextUtils.isEmpty( uuid ) ) {
return uuid;
}
return sn;
}
public CloudRoadData() {
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel( Parcel dest, int flags ) {
dest.writeInt( this.type );
dest.writeDouble( this.lat );
dest.writeDouble( this.lon );
dest.writeString( this.uuid );
dest.writeString( this.sn );
dest.writeDouble( this.speed );
dest.writeDouble( this.heading );
dest.writeLong( this.systemTime );
dest.writeInt( this.lightStatus );
dest.writeInt( this.lightLeftTime );
dest.writeString( this.rtmpUrl );
dest.writeDouble( this.distance );
dest.writeTypedList( this.coordinates );
}
protected CloudRoadData( Parcel in ) {
this.type = in.readInt();
this.lat = in.readDouble();
this.lon = in.readDouble();
this.uuid = in.readString();
this.sn = in.readString();
this.speed = in.readDouble();
this.heading = in.readDouble();
this.systemTime = in.readLong();
this.lightStatus = in.readInt();
this.lightLeftTime = in.readInt();
this.rtmpUrl = in.readString();
this.distance = in.readDouble();
this.coordinates = in.createTypedArrayList( CloudLocationInfo.CREATOR );
}
public static final Creator< CloudRoadData > CREATOR = new Creator< CloudRoadData >() {
@Override
public CloudRoadData createFromParcel( Parcel source ) {
return new CloudRoadData( source );
}
@Override
public CloudRoadData[] newArray( int size ) {
return new CloudRoadData[size];
}
};
}

View File

@@ -40,4 +40,6 @@ public interface MarkerPoiTypeEnum {
String FOURS_LIVING = "10015";
//违章停车
String ILLEGAL_PARK_LIVING = "10016";
//路面湿滑
String ROAD_SLIPPERY = "10021";
}

View File

@@ -0,0 +1,135 @@
package com.mogo.module.common.entity;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.List;
public
/**
* @author congtaowang
* @since 2020/10/26
*
* 描述
*/
class MogoSnapshotSetData implements Parcelable {
private String msgId;
private long time;
//过期时间
private long expire;
//总数据集合
private List<CloudRoadData> allList;
// 近景adas数据
private List<CloudRoadData> nearList;
//红绿灯
private CloudRoadData trafficLight;
// 自车速度 本地添加
public double curSpeed = 0.0;
@Override
public String toString() {
return "MogoSnapshotSetData{" +
"msgId='" + msgId + '\'' +
", time=" + time +
", expire=" + expire +
", allList=" + allList +
", trafficLight=" + trafficLight +
'}';
}
public String getMsgId() {
return msgId;
}
public void setMsgId(String msgId) {
this.msgId = msgId;
}
public long getTime() {
return time;
}
public void setTime(long time) {
this.time = time;
}
public long getExpire() {
return expire;
}
public void setExpire(long expire) {
this.expire = expire;
}
public List<CloudRoadData> getAllList() {
return allList;
}
public void setAllList(List<CloudRoadData> allList) {
this.allList = allList;
}
public CloudRoadData getTrafficLight() {
return trafficLight;
}
public void setTrafficLight(CloudRoadData trafficLight) {
this.trafficLight = trafficLight;
}
public List< CloudRoadData > getNearList() {
return nearList;
}
public void setNearList( List< CloudRoadData > nearList ) {
this.nearList = nearList;
}
public MogoSnapshotSetData() {
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel( Parcel dest, int flags ) {
dest.writeString( this.msgId );
dest.writeLong( this.time );
dest.writeLong( this.expire );
dest.writeTypedList( this.allList );
dest.writeTypedList( this.nearList );
dest.writeParcelable( this.trafficLight, flags );
dest.writeDouble( this.curSpeed );
}
protected MogoSnapshotSetData( Parcel in ) {
this.msgId = in.readString();
this.time = in.readLong();
this.expire = in.readLong();
this.allList = in.createTypedArrayList( CloudRoadData.CREATOR );
this.nearList = in.createTypedArrayList( CloudRoadData.CREATOR );
this.trafficLight = in.readParcelable( CloudRoadData.class.getClassLoader() );
this.curSpeed = in.readDouble();
}
public static final Creator< MogoSnapshotSetData > CREATOR = new Creator< MogoSnapshotSetData >() {
@Override
public MogoSnapshotSetData createFromParcel( Parcel source ) {
return new MogoSnapshotSetData( source );
}
@Override
public MogoSnapshotSetData[] newArray( int size ) {
return new MogoSnapshotSetData[size];
}
};
}

View File

@@ -139,8 +139,14 @@ public class V2XMessageEntity<T> implements Serializable {
int ALERT_ILLEGAL_PARK_WARNING = 1_008;
// 用户UGC反馈事件准确性弹窗
int ALERT_EVENT_UGC_WARNING = 1_009;
// 呼叫、请求直播事件
int ALERT_VOICE_CALL_FOR_LIVECAR_SHOW = 1_010;
// 推送VR消息展示
int ALERT_PUSH_VR_SHOW = 2_000;
// 自车求助
int ALERT_CAR_FOR_HELP = 8_000;
// obu事件
int ALERT_OBU_EVENT = 9_000;
}
@IntDef(value = {
@@ -155,6 +161,9 @@ public class V2XMessageEntity<T> implements Serializable {
V2XTypeEnum.ALERT_ILLEGAL_PARK_WARNING,
V2XTypeEnum.ALERT_EVENT_UGC_WARNING,
V2XTypeEnum.ALERT_CAR_FOR_HELP,
V2XTypeEnum.ALERT_VOICE_CALL_FOR_LIVECAR_SHOW,
V2XTypeEnum.ALERT_PUSH_VR_SHOW,
V2XTypeEnum.ALERT_OBU_EVENT,
})
@Target({
ElementType.PARAMETER,

View File

@@ -0,0 +1,35 @@
package com.mogo.module.common.entity;
/**
* obu事件封装
*
* @author tongchenfei
*/
public class V2XObuEventEntity {
private int type;
private String desc;
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
@Override
public String toString() {
return "V2XObuEventEntity{" +
"type=" + type +
", desc='" + desc + '\'' +
'}';
}
}

View File

@@ -3,6 +3,7 @@ package com.mogo.module.common.entity;
import android.text.TextUtils;
import java.io.Serializable;
import java.util.List;
import java.util.Objects;
/**
@@ -29,8 +30,7 @@ public class V2XPushMessageEntity implements Serializable {
private String videoChannel;
private int expireTime;
private long createTime;
private double lat;
private double lon;
private String sn;
private String headImgUrl;
private String msgImgUrl;
@@ -43,6 +43,15 @@ public class V2XPushMessageEntity implements Serializable {
private int sex;
private long userId;
private double lat;
private double lon;
private List<double[]> polyline;
private List<double[]> moveTrack;
private List<double[]> recommendPolyline;
public int getViewType() {
return viewType;
}
@@ -266,6 +275,30 @@ public class V2XPushMessageEntity implements Serializable {
this.userId = userId;
}
public List<double[]> getPolyline() {
return polyline;
}
public void setPolyline(List<double[]> polyline) {
this.polyline = polyline;
}
public List<double[]> getMoveTrack() {
return moveTrack;
}
public void setMoveTrack(List<double[]> moveTrack) {
this.moveTrack = moveTrack;
}
public List<double[]> getRecommendPolyline() {
return recommendPolyline;
}
public void setRecommendPolyline(List<double[]> recommendPolyline) {
this.recommendPolyline = recommendPolyline;
}
@Override
public boolean equals(Object o) {
if (this == o) {

View File

@@ -2,6 +2,7 @@ package com.mogo.module.common.map;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.map.uicontroller.IMogoMapUIController;
import com.mogo.module.common.MogoApisHandler;
import com.mogo.utils.UiThreadHandler;
import com.mogo.utils.logger.Logger;
@@ -18,7 +19,8 @@ public class MapCenterPointStrategy {
private static final String TAG = "MapCenterPointStrategy";
private static Map< Integer, Map< String, MapCenterPoint > > sStrategies = new HashMap<>();
private static Map< Integer, Map< String, MapCenterPoint > > sCommonStrategies = new HashMap<>();
private static Map< Integer, Map< String, MapCenterPoint > > sVrStrategies = new HashMap<>();
public static final MapCenterPoint DEFAULT = new MapCenterPoint( 0.677734D, 0.5733333D );
@@ -34,13 +36,12 @@ public class MapCenterPointStrategy {
choosePoint.put( "e8xx", point );
choosePoint.put( "f80x", point );
choosePoint.put( "f8xx", point );
sStrategies.put( Scene.CHOOSE_POINT, choosePoint );
sCommonStrategies.put( Scene.CHOOSE_POINT, choosePoint );
}
{
// 导航场景,定位视图右下角偏下
Map< String, MapCenterPoint > navi = new HashMap<>();
navi.put( "d80x", new MapCenterPoint( 0.669444444444444, 0.573333333333D ) );
final MapCenterPoint em4 = new MapCenterPoint( 0.734375D, 0.573333333333D );
navi.put( "em4", em4 );
navi.put( "em3", em4 );
@@ -48,13 +49,12 @@ public class MapCenterPointStrategy {
final MapCenterPoint f80x = new MapCenterPoint( 0.705208333D, 0.575D );
navi.put( "f80x", f80x );
navi.put( "f8xx", f80x );
sStrategies.put( Scene.NAVI, navi );
sCommonStrategies.put( Scene.NAVI, navi );
}
{
// 导航场景 vs 道路事件展示场景,定位视图右下角偏下
Map< String, MapCenterPoint > naviWithRoadEvent = new HashMap<>();
naviWithRoadEvent.put( "d80x", new MapCenterPoint( 0.669444444444444, 0.73936170212766D ) );
final MapCenterPoint em4 = new MapCenterPoint( 0.734375D, 0.73936170212766D );
naviWithRoadEvent.put( "em4", em4 );
naviWithRoadEvent.put( "em3", em4 );
@@ -62,13 +62,12 @@ public class MapCenterPointStrategy {
final MapCenterPoint f80x = new MapCenterPoint( 0.705208333D, 0.683333333333D );
naviWithRoadEvent.put( "f80x", f80x );
naviWithRoadEvent.put( "f8xx", f80x );
sStrategies.put( Scene.NAVI_WITH_ROAD_EVENT, naviWithRoadEvent );
sCommonStrategies.put( Scene.NAVI_WITH_ROAD_EVENT, naviWithRoadEvent );
}
{
// 巡航场景
Map< String, MapCenterPoint > aimless = new HashMap<>();
aimless.put( "d80x", new MapCenterPoint( 0.669444444444444, 0.5D ) );
final MapCenterPoint em4 = new MapCenterPoint( 0.734375D, 0.5D );
aimless.put( "em4", em4 );
aimless.put( "em3", em4 );
@@ -76,13 +75,12 @@ public class MapCenterPointStrategy {
final MapCenterPoint f80x = new MapCenterPoint( 0.705208333D, 0.5D );
aimless.put( "f80x", f80x );
aimless.put( "f8xx", f80x );
sStrategies.put( Scene.AIMLESS, aimless );
sCommonStrategies.put( Scene.AIMLESS, aimless );
}
{
// 巡航场景 vs 道路事件展示场景
Map< String, MapCenterPoint > aimlessWithRoadEvent = new HashMap<>();
aimlessWithRoadEvent.put( "d80x", new MapCenterPoint( 0.669444444444444, 0.68617 ) );
final MapCenterPoint em4 = new MapCenterPoint( 0.734375D, 0.68617 );
aimlessWithRoadEvent.put( "em4", em4 );
aimlessWithRoadEvent.put( "em3", em4 );
@@ -90,7 +88,7 @@ public class MapCenterPointStrategy {
final MapCenterPoint f80x = new MapCenterPoint( 0.705208333D, 0.599074074D );
aimlessWithRoadEvent.put( "f80x", f80x );
aimlessWithRoadEvent.put( "f8xx", f80x );
sStrategies.put( Scene.AIMLESS_WITH_ROAD_EVENT, aimlessWithRoadEvent );
sCommonStrategies.put( Scene.AIMLESS_WITH_ROAD_EVENT, aimlessWithRoadEvent );
}
{
@@ -104,7 +102,7 @@ public class MapCenterPointStrategy {
final MapCenterPoint f80x = new MapCenterPoint( 0.703125D, 0.6083333D );
calculatePath.put( "f80x", f80x );
calculatePath.put( "f8xx", f80x );
sStrategies.put( Scene.CALCULATE_PATH, calculatePath );
sCommonStrategies.put( Scene.CALCULATE_PATH, calculatePath );
}
{
@@ -118,7 +116,7 @@ public class MapCenterPointStrategy {
final MapCenterPoint f80x = new MapCenterPoint( 0.733594D, 0.5D );
categorySearch.put( "f80x", f80x );
categorySearch.put( "f8xx", f80x );
sStrategies.put( Scene.CATEGORY_SEARCH, categorySearch );
sCommonStrategies.put( Scene.CATEGORY_SEARCH, categorySearch );
}
{
@@ -132,19 +130,102 @@ public class MapCenterPointStrategy {
final MapCenterPoint f80x = new MapCenterPoint( 0.6963541D, 0.65D );
categoryV2XEvent.put( "f80x", f80x );
categoryV2XEvent.put( "f8xx", f80x );
sStrategies.put( Scene.CATEGORY_V2X_EVENT, categoryV2XEvent );
sCommonStrategies.put( Scene.CATEGORY_V2X_EVENT, categoryV2XEvent );
}
// --vr mode
{
// 选点场景,定位中心点
Map< String, MapCenterPoint > choosePoint = new HashMap<>();
choosePoint.put( "d80x", new MapCenterPoint( 0.5D, 0.5D ) );
choosePoint.put( "em4", new MapCenterPoint( 0.5D, 0.5D ) );
choosePoint.put( "e8xx", new MapCenterPoint( 0.5D, 0.5D ) );
choosePoint.put( "f80x", new MapCenterPoint( 0.5D, 0.5D ) );
choosePoint.put( "f8xx", new MapCenterPoint( 0.5D, 0.5D ) );
sVrStrategies.put( Scene.CHOOSE_POINT, choosePoint );
}
{
// 导航场景,定位视图右下角偏下
Map< String, MapCenterPoint > navi = new HashMap<>();
navi.put( "d80x", new MapCenterPoint( 0.5D, 0.573333333333D ) );
navi.put( "em4", new MapCenterPoint( 0.5D, 0.573333333333D ) );
navi.put( "e8xx", new MapCenterPoint( 0.5D, 0.573333333333D ) );
navi.put( "f80x", new MapCenterPoint( 0.5D, 0.575D ) );
navi.put( "f8xx", new MapCenterPoint( 0.5D, 0.575D ) );
sVrStrategies.put( Scene.NAVI, navi );
}
{
// 导航场景 vs 道路事件展示场景,定位视图右下角偏下
Map< String, MapCenterPoint > naviWithRoadEvent = new HashMap<>();
naviWithRoadEvent.put( "d80x", new MapCenterPoint( 0.5D, 0.73936170212766D ) );
naviWithRoadEvent.put( "em4", new MapCenterPoint( 0.5D, 0.73936170212766D ) );
naviWithRoadEvent.put( "e8xx", new MapCenterPoint( 0.5D, 0.73936170212766D ) );
naviWithRoadEvent.put( "f80x", new MapCenterPoint( 0.5D, 0.683333333333D ) );
naviWithRoadEvent.put( "f8xx", new MapCenterPoint( 0.5D, 0.683333333333D ) );
sVrStrategies.put( Scene.NAVI_WITH_ROAD_EVENT, naviWithRoadEvent );
}
{
// 巡航场景
Map< String, MapCenterPoint > aimless = new HashMap<>();
aimless.put( "d80x", new MapCenterPoint( 0.5D, 0.5D ) );
aimless.put( "em4", new MapCenterPoint( 0.5D, 0.5D ) );
aimless.put( "e8xx", new MapCenterPoint( 0.5D, 0.5D ) );
aimless.put( "f80x", new MapCenterPoint( 0.5D, 0.8D ) );
aimless.put( "f8xx", new MapCenterPoint( 0.5D, 0.8D ) );
sVrStrategies.put( Scene.AIMLESS, aimless );
}
{
// 巡航场景 vs 道路事件展示场景
Map< String, MapCenterPoint > aimlessWithRoadEvent = new HashMap<>();
aimlessWithRoadEvent.put( "d80x", new MapCenterPoint( 0.5D, 0.68617 ) );
aimlessWithRoadEvent.put( "em4", new MapCenterPoint( 0.5D, 0.68617 ) );
aimlessWithRoadEvent.put( "e8xx", new MapCenterPoint( 0.5D, 0.68617 ) );
aimlessWithRoadEvent.put( "f80x", new MapCenterPoint( 0.5D, 0.599074074D ) );
aimlessWithRoadEvent.put( "f8xx", new MapCenterPoint( 0.5D, 0.599074074D ) );
sVrStrategies.put( Scene.AIMLESS_WITH_ROAD_EVENT, aimlessWithRoadEvent );
}
{
// 规划路线,定位视图右边
Map< String, MapCenterPoint > calculatePath = new HashMap<>();
calculatePath.put( "d80x", new MapCenterPoint( 0.5D, 0.610833D ) );
calculatePath.put( "em4", new MapCenterPoint( 0.5D, 0.610833D ) );
calculatePath.put( "e8xx", new MapCenterPoint( 0.5D, 0.610833D ) );
calculatePath.put( "f80x", new MapCenterPoint( 0.5D, 0.6083333D ) );
calculatePath.put( "f8xx", new MapCenterPoint( 0.5D, 0.6083333D ) );
sVrStrategies.put( Scene.CALCULATE_PATH, calculatePath );
}
{
// 分类搜索,定位视图右边
Map< String, MapCenterPoint > categorySearch = new HashMap<>();
categorySearch.put( "d80x", new MapCenterPoint( 0.5D, 0.5D ) );
categorySearch.put( "em4", new MapCenterPoint( 0.5D, 0.5D ) );
categorySearch.put( "e8xx", new MapCenterPoint( 0.5D, 0.5D ) );
categorySearch.put( "f80x", new MapCenterPoint( 0.5D, 0.5D ) );
categorySearch.put( "f8xx", new MapCenterPoint( 0.5D, 0.5D ) );
sVrStrategies.put( Scene.CATEGORY_SEARCH, categorySearch );
}
{
// V2X场景视图右边
Map< String, MapCenterPoint > categoryV2XEvent = new HashMap<>();
categoryV2XEvent.put( "d80x", new MapCenterPoint( 0.5, 0.7D ) );
categoryV2XEvent.put( "em4", new MapCenterPoint( 0.5, 0.7D ) );
categoryV2XEvent.put( "e8xx", new MapCenterPoint( 0.5, 0.7D ) );
categoryV2XEvent.put( "f80x", new MapCenterPoint( 0.5, 0.65D ) );
categoryV2XEvent.put( "f8xx", new MapCenterPoint( 0.5, 0.65D ) );
sVrStrategies.put( Scene.CATEGORY_V2X_EVENT, categoryV2XEvent );
}
}
public static void addScene( int scene, Map< String, MapCenterPoint > config ) {
if ( sStrategies.containsKey( scene ) ) {
Logger.w( TAG, "scene has already defined, append config..." );
}
if ( sStrategies.get( scene ) != null ) {
sStrategies.get( scene ).putAll( config );
} else {
sStrategies.put( scene, config );
}
public static void resetByChangeMode(){
setMapCenterPointByScene( MogoApisHandler.getInstance().getApis().getMapServiceApi().getMapUIController(), Scene.AIMLESS);
}
/**
@@ -157,12 +238,16 @@ public class MapCenterPointStrategy {
if ( controller == null ) {
return;
}
if ( !sStrategies.containsKey( scene ) ) {
Map<Integer, Map<String, MapCenterPoint>> strategies = sCommonStrategies;
if ( MogoApisHandler.getInstance().getApis().getMapFrameControllerApi().isVrMode() ) {
strategies = sVrStrategies;
}
if ( !strategies.containsKey( scene ) ) {
Logger.w( TAG, "no strategy for scene: %s, use DEFAULT", scene );
controller.setPointToCenter( DEFAULT.x, DEFAULT.y );
return;
}
Map< String, MapCenterPoint > points = sStrategies.get( scene );
Map< String, MapCenterPoint > points = strategies.get( scene );
String car = DebugConfig.getProductFlavor();
if ( !points.containsKey( car ) ) {
Logger.w( TAG, "no strategy for series: %s, use DEFAULT", scene );

View File

@@ -0,0 +1,88 @@
package com.mogo.module.common.utils;
import java.math.BigDecimal;
/**
* 坐标系转化
*
* @author linyang
* @since 2020.10.21
*/
public class CoordinateSystemTransformationUtil {
private static final double x_PI = 52.35987755982988D;
private static final double PI = 3.141592653589793D;
private static final double a = 6378245.0D;
private static final double ee = 0.006693421622965943D;
public static final boolean outOfChina( double lat, double lng ) {
return lng <= 73.66D || lng >= 135.05D || lat <= 3.86D || lat >= 53.55D;
}
private static final double transformLat( double lng, double lat ) {
double ret = -100.0D + 2.0D * lng + 3.0D * lat + 0.2D * lat * lat + 0.1D * lng * lat + 0.2D * Math.sqrt( Math.abs( lng ) );
ret += ( 20.0D * Math.sin( 6.0D * lng * 3.141592653589793D ) + 20.0D * Math.sin( 2.0D * lng * 3.141592653589793D ) ) * 2.0D / 3.0D;
ret += ( 20.0D * Math.sin( lat * 3.141592653589793D ) + 40.0D * Math.sin( lat / 3.0D * 3.141592653589793D ) ) * 2.0D / 3.0D;
ret += ( 160.0D * Math.sin( lat / 12.0D * 3.141592653589793D ) + ( double ) 320 * Math.sin( lat * 3.141592653589793D / 30.0D ) ) * 2.0D / 3.0D;
return ret;
}
private static final double transformLon( double lng, double lat ) {
double ret = 300.0D + lng + 2.0D * lat + 0.1D * lng * lng + 0.1D * lng * lat + 0.1D * Math.sqrt( Math.abs( lng ) );
ret += ( 20.0D * Math.sin( 6.0D * lng * 3.141592653589793D ) + 20.0D * Math.sin( 2.0D * lng * 3.141592653589793D ) ) * 2.0D / 3.0D;
ret += ( 20.0D * Math.sin( lng * 3.141592653589793D ) + 40.0D * Math.sin( lng / 3.0D * 3.141592653589793D ) ) * 2.0D / 3.0D;
ret += ( 150.0D * Math.sin( lng / 12.0D * 3.141592653589793D ) + 300.0D * Math.sin( lng / 30.0D * 3.141592653589793D ) ) * 2.0D / 3.0D;
return ret;
}
public static final double[] transformWgsToGcj( double wgLat, double wgLon ) {
double[] point = new double[2];
if ( outOfChina( wgLat, wgLon ) ) {
point[0] = wgLon;
point[1] = wgLat;
return point;
} else {
double dLat = transformLat( wgLon - 105.0D, wgLat - 35.0D );
double dLon = transformLon( wgLon - 105.0D, wgLat - 35.0D );
double radLat = wgLat / 180.0D * 3.141592653589793D;
double magic = Math.sin( radLat );
magic = ( double ) 1 - 0.006693421622965943D * magic * magic;
double sqrtMagic = Math.sqrt( magic );
dLat = dLat * 180.0D / ( 6335552.717000426D / ( magic * sqrtMagic ) * 3.141592653589793D );
dLon = dLon * 180.0D / ( 6378245.0D / sqrtMagic * Math.cos( radLat ) * 3.141592653589793D );
double mgLat = wgLat + dLat;
double mgLon = wgLon + dLon;
point[0] = dealRound( mgLon );
point[1] = dealRound( mgLat );
return point;
}
}
public static final double[] transformGcj02toWgs84( double lat, double lng ) {
double[] var10000;
if ( outOfChina( lat, lng ) ) {
var10000 = new double[]{lng, lat};
} else {
double dlat = transformLat( lng - 105.0D, lat - 35.0D );
double dlng = transformLon( lng - 105.0D, lat - 35.0D );
double radlat = lat / 180.0D * 3.141592653589793D;
double magic = Math.sin( radlat );
magic = ( double ) 1 - 0.006693421622965943D * magic * magic;
double sqrtmagic = Math.sqrt( magic );
dlat = dlat * 180.0D / ( 6335552.717000426D / ( magic * sqrtmagic ) * 3.141592653589793D );
dlng = dlng * 180.0D / ( 6378245.0D / sqrtmagic * Math.cos( radlat ) * 3.141592653589793D );
double mglat = lat + dlat;
double mglng = lng + dlng;
var10000 = new double[]{dealRound( lng * ( double ) 2 - mglng ), dealRound( lat * ( double ) 2 - mglat )};
}
return var10000;
}
private static final double dealRound( double value ) {
BigDecimal bg = new BigDecimal( value );
double result = bg.setScale( 6, 4 ).doubleValue();
return result;
}
}

View File

@@ -0,0 +1,97 @@
package com.mogo.module.common.utils;
import com.amap.api.maps.model.LatLng;
/**
* @author donghongyu
*/
public class CoordinateUtils {
private static double a = 6378245.0;
private static double ee = 0.00669342162296594323;
/**
* 手机GPS坐标转火星坐标
*
* @param wgLoc
* @return
*/
public static double[] transformFromWGSToGCJ( double lat, double lon ) {
//如果在国外,则默认不进行转换
if ( outOfChina( lat, lon ) ) {
return new double[]{lat, lon};
}
double dLat = transformLat( lon - 105.0,
lat - 35.0 );
double dLon = transformLon( lon - 105.0,
lat - 35.0 );
double radLat = lat / 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 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 );
ret += ( 20.0 * Math.sin( 6.0 * x * Math.PI ) + 20.0 * Math.sin( 2.0 * x
* Math.PI ) ) * 2.0 / 3.0;
ret += ( 20.0 * Math.sin( y * Math.PI ) + 40.0 * Math.sin( y / 3.0
* Math.PI ) ) * 2.0 / 3.0;
ret += ( 160.0 * Math.sin( y / 12.0 * Math.PI ) + 320 * Math.sin( y
* Math.PI / 30.0 ) ) * 2.0 / 3.0;
return ret;
}
public static double transformLon( double x, double y ) {
double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1
* Math.sqrt( x > 0 ? x : -x );
ret += ( 20.0 * Math.sin( 6.0 * x * Math.PI ) + 20.0 * Math.sin( 2.0 * x
* Math.PI ) ) * 2.0 / 3.0;
ret += ( 20.0 * Math.sin( x * Math.PI ) + 40.0 * Math.sin( x / 3.0
* Math.PI ) ) * 2.0 / 3.0;
ret += ( 150.0 * Math.sin( x / 12.0 * Math.PI ) + 300.0 * Math.sin( x
/ 30.0 * Math.PI ) ) * 2.0 / 3.0;
return ret;
}
public static boolean outOfChina( double lat, double lon ) {
if ( lon < 72.004 || lon > 137.8347 )
return true;
if ( lat < 0.8293 || lat > 55.8271 )
return true;
return false;
}
}

View File

@@ -39,6 +39,10 @@ class DialogImpl implements IWindowManagerView {
dialog.show();
}
@Override
public void update(WindowManagerView.WMViewParams params) {
}
@Override
public void hide() {
/*

View File

@@ -27,6 +27,12 @@ interface IWindowManagerView {
*/
void show();
/**
* 更新界面位置或大小
* @param params 具体参数
*/
void update(WindowManagerView.WMViewParams params);
/**
* 隐藏
*/

View File

@@ -4,6 +4,7 @@ import android.content.Context;
import android.graphics.PixelFormat;
import android.os.Build;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
/**
@@ -16,6 +17,8 @@ class WindowManagerImpl implements IWindowManagerView {
private WindowManagerView.WMViewParams mParams;
private boolean isShowing;
private View rootView;
private float mLastX, mLastY;
private int mOldOffsetX, mOldOffsetY;
@@ -23,6 +26,10 @@ class WindowManagerImpl implements IWindowManagerView {
public void init( WindowManagerView.WMViewParams params ) {
mParams = params;
mWindowManager = ( WindowManager ) mParams.mContext.getApplicationContext().getSystemService( Context.WINDOW_SERVICE );
generateLayoutParams();
}
private void generateLayoutParams(){
mLayoutParams = new WindowManager.LayoutParams();
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ) {
mLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
@@ -80,10 +87,20 @@ class WindowManagerImpl implements IWindowManagerView {
public void show() {
if ( !isShowing ) {
isShowing = true;
rootView = mParams.mContentView;
mWindowManager.addView( mParams.mContentView, mLayoutParams );
}
}
@Override
public void update(WindowManagerView.WMViewParams params) {
if (isShowing) {
mParams = params;
generateLayoutParams();
mWindowManager.updateViewLayout(rootView,mLayoutParams);
}
}
@Override
public void hide() {
if ( isShowing && mParams != null ) {

View File

@@ -116,4 +116,15 @@ public class WindowManagerView {
public int mY;
public int mGravity;
}
public void exchangeSizeAndPosition(int width, int height, int x, int y) {
if (isShowing()) {
mParams.mX = x;
mParams.mY = y;
mParams.mWidth = width;
mParams.mHeight = height;
mManagerView.update(mParams);
}
}
}