This commit is contained in:
wangcongtao
2020-12-07 16:30:37 +08:00
parent 1557af276b
commit e1082ac994
15 changed files with 197 additions and 72 deletions

View File

@@ -1,7 +1,6 @@
package com.mogo.module.common.drawer;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
@@ -9,19 +8,17 @@ import android.widget.ImageView;
import android.widget.TextView;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.commons.data.BaseData;
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.CloudRoadData;
import com.mogo.module.common.utils.CoordinateUtils;
import com.mogo.service.adas.entity.ADASRecognizedListResult;
import java.util.ArrayList;
@@ -108,7 +105,8 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
if ( latLon == null ) {
continue;
}
points.add( endLatLon = new MogoLatLng( latLon.lat, latLon.lon ) );
double targetPos[] = CoordinateUtils.transformFromWGSToGCJ( latLon.lat, latLon.lon );
points.add( endLatLon = new MogoLatLng( targetPos[POS_LAT], targetPos[POS_LON] ) );
}
} else if ( recognizedListResult.latLonList != null
@@ -176,24 +174,28 @@ class AdasRecognizedResultDrawer extends BaseDrawer {
MogoMarkerOptions options = new MogoMarkerOptions()
.owner( DataTypes.TYPE_MARKER_ADAS )
.gps( true )
.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() );
// 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( 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

@@ -12,6 +12,9 @@ public
*/
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;

View File

@@ -24,6 +24,8 @@ 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;
@@ -74,6 +76,9 @@ class SnapshotSetDataDrawer extends BaseDrawer {
// 云端 marker 缓存
private Map< String, IMogoMarker > mCloudSnapshotMarkersCaches = new ConcurrentHashMap<>();
private int mPurseCounter = 0;
private Map< String, MogoLatLng > mLastPositions = new ConcurrentHashMap<>();
/**
* 其他车辆、rsu 车辆数据
@@ -82,16 +87,25 @@ class SnapshotSetDataDrawer extends BaseDrawer {
*/
public void renderSnapshotData( MogoSnapshotSetData data,
boolean machineVision ) {
if ( data == null || data.getAllList() == null || data.getAllList().isEmpty() ) {
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<>();
if ( machineVision ) {
allDatumsList.addAll( data.getAllList() );
allDatumsList.addAll( data.getNearList() );
} else {
allDatumsList.addAll( data.getAllList() );
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 ) {
@@ -106,6 +120,7 @@ class SnapshotSetDataDrawer extends BaseDrawer {
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 ) {
@@ -113,35 +128,26 @@ class SnapshotSetDataDrawer extends BaseDrawer {
}
mCloudSnapshotMarkersCaches.put( uniqueKey, marker );
} else {
marker.setIcon( fromView( inflateView( cloudRoadData, machineVision, data.curSpeed ) ) );
}
if ( marker.getObject() instanceof MogoLatLng ) {
marker.setPosition( ( ( MogoLatLng ) marker.getObject() ).lat, ( ( MogoLatLng ) marker.getObject() ).lon );
}
MogoLatLng endLatLon = null;
List< MogoLatLng > points = new ArrayList<>();
if ( cloudRoadData.getCoordinates() != null
&& cloudRoadData.getCoordinates().size() > 1 ) {
points.add( new MogoLatLng( cloudRoadData.getLat(), cloudRoadData.getLon() ) );
for ( int j = 0; j < cloudRoadData.getCoordinates().size(); j++ ) {
CloudLocationInfo poi = cloudRoadData.getCoordinates().get( j );
if ( poi == null ) {
continue;
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 );
}
double lat = poi.getLat();
double lng = poi.getLon();
points.add( endLatLon = new MogoLatLng( lat, lng ) );
} else {
marker.setRotateAngle( 360 - ( float ) cloudRoadData.getHeading() );
marker.setPosition( targetPos[POS_LAT], targetPos[POS_LON] );
}
} else {
points.add( marker.getPosition() );
points.add( endLatLon = new MogoLatLng( cloudRoadData.getLat(), cloudRoadData.getLon() ) );
}
if ( endLatLon != null ) {
marker.setObject( endLatLon );
}
if ( points.size() >= 1 ) {
marker.startSmooth( points, 1 );
}
mLastPositions.put( uniqueKey, target );
}
}
@@ -174,6 +180,7 @@ class SnapshotSetDataDrawer extends BaseDrawer {
if ( !existMarker.isEmpty() ) {
for ( String key : mCloudSnapshotMarkersCaches.keySet() ) {
if ( !existMarker.containsKey( key ) ) {
mLastPositions.remove( key );
try {
IMogoMarker marker = mCloudSnapshotMarkersCaches.remove( key );
marker.destroy();
@@ -195,6 +202,8 @@ class SnapshotSetDataDrawer extends BaseDrawer {
.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 );
}

View File

@@ -21,6 +21,7 @@ public class CloudRoadData implements Parcelable {
private String sn;
private double speed;
private double heading;
private long systemTime;
@@ -124,6 +125,14 @@ public class CloudRoadData implements Parcelable {
return sn;
}
public double getHeading() {
return heading;
}
public void setHeading( double heading ) {
this.heading = heading;
}
public String getUniqueKey(){
if (! TextUtils.isEmpty( uuid ) ) {
return uuid;
@@ -131,6 +140,9 @@ public class CloudRoadData implements Parcelable {
return sn;
}
public CloudRoadData() {
}
@Override
public int describeContents() {
return 0;
@@ -144,6 +156,7 @@ public class CloudRoadData implements Parcelable {
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 );
@@ -152,9 +165,6 @@ public class CloudRoadData implements Parcelable {
dest.writeTypedList( this.coordinates );
}
public CloudRoadData() {
}
protected CloudRoadData( Parcel in ) {
this.type = in.readInt();
this.lat = in.readDouble();
@@ -162,6 +172,7 @@ public class CloudRoadData implements Parcelable {
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();