优化显示逻辑

This commit is contained in:
wangcongtao
2021-03-16 10:06:48 +08:00
parent 100edfcd54
commit 5e0d18dbc2
21 changed files with 265 additions and 151 deletions

View File

@@ -17,6 +17,7 @@ import android.view.ViewGroup;
import android.view.animation.Interpolator;
import android.widget.TextView;
import com.autonavi.nge.map.LonLat;
import com.mogo.commons.debug.DebugConfig;
import com.mogo.map.IMogoMap;
import com.mogo.map.IMogoMapView;
@@ -56,6 +57,7 @@ import com.zhidaoauto.map.sdk.open.location.RTKAutopilotLocationBean;
import com.zhidaoauto.map.sdk.open.marker.BitmapDescriptorFactory;
import com.zhidaoauto.map.sdk.open.marker.Marker;
import com.zhidaoauto.map.sdk.open.marker.OnMarkClickListener;
import com.zhidaoauto.map.sdk.open.poyline.PolylineOptions;
import com.zhidaoauto.map.sdk.open.query.LonLatPoint;
import com.zhidaoauto.map.sdk.open.tools.MapTools;
import com.zhidaoauto.map.sdk.open.view.MapAutoView;
@@ -65,8 +67,13 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import static java.lang.Math.PI;
public class AMapViewWrapper implements IMogoMapView,
IMogoMapUIController,
@@ -731,15 +738,6 @@ public class AMapViewWrapper implements IMogoMapView,
sysLocation.setBearing(location.getHeading());
sysLocation.setSpeed(location.getSpeed());
if (sysLocation.getSpeed() > 0) {
mLastDriveLocationShadow = sysLocation;
} else {
if ((int) sysLocation.getBearing() == 0
&& mLastDriveLocationShadow != null) {
// TODO: 2020/12/12 停车时自车图标方向调整
}
}
NaviClient.getInstance(getContext()).syncCarLocation(sysLocation);
if (checkAMapView() && mMapLoaded) {
// 地图初始化完成后每隔5s自动判断当前地图的模式
@@ -1042,42 +1040,68 @@ public class AMapViewWrapper implements IMogoMapView,
private double[] matchRoad(String id, double lon, double lat, double angle, boolean isGpsLocation, boolean isRTK, boolean usdCache) {
double wgs[] = new double[]{lon, lat};
long start = System.currentTimeMillis();
RoadCacheWrapper roadCache = roadCacheMap.get(id);
if (roadCache == null) {
SinglePointRoadInfo singlePointRoadInfo = MapDataApi.INSTANCE.getSinglePointMatchRoad(((float) wgs[0]), ((float) wgs[1]), ((float) angle), isGpsLocation, isRTK);
if (singlePointRoadInfo != null && singlePointRoadInfo.getCoords() != null && !singlePointRoadInfo.getCoords().isEmpty()) {
Log.i("timer-matchRoad-4", "cost " + (System.currentTimeMillis() - start) + "ms roadId: " + singlePointRoadInfo.getRoadId());
roadCache = new RoadCacheWrapper(singlePointRoadInfo.getCoords());
}
}
Log.i("timer-matchRoad-1", "cost " + (System.currentTimeMillis() - start) + "ms");
if (roadCache != null
&& roadCache.getRoad() != null
&& !roadCache.getRoad().isEmpty()) {
start = System.currentTimeMillis();
double matchedPoint[] = PointInterpolatorUtil.mergeToRoad(wgs[0], wgs[1], roadCache.getRoad());
if (matchedPoint[2] > 0 && matchedPoint[2] < 1.5) {
// if (roadCache.inCache(matchedPoint[0], matchedPoint[1])) {
roadCacheMap.put(id, roadCache);
Log.i("timer-matchRoad-3", "cost " + (System.currentTimeMillis() - start) + "ms");
return matchedPoint;
// }
// roadCacheMap.put(id, null);
// Log.i("timer-matchRoad-2", "cost " + (System.currentTimeMillis() - start) + "ms roadId: "+roadCache.getLastLat());
// return matchRoad(id, lon, lat, angle, isGpsLocation, isRTK,false);
}else{
roadCacheMap.put(id, null);
Log.i("timer-matchRoad-2", "cost " + (System.currentTimeMillis() - start) + "ms roadId: " + roadCache.getLastLat());
if(usdCache) {
return matchRoad(id, lon, lat, angle, isGpsLocation, isRTK, false);
}else{
return null;
}
}
//
// try {
// PolylineOptions options = new PolylineOptions( );
// options.setColor( Color.WHITE );
// options.setId( "test-line"+new Random( ).nextLong() );
// options.setGps( true );
// options.setLineWidth( 3 );
// List<LonLatPoint> points = singlePointRoadInfo.getCoords();
// ArrayList< LonLat > lonLats = new ArrayList<>( );
// for ( LonLatPoint point : points ) {
// lonLats.add( new LonLat( point.getLongitude(), point.getLatitude() ) );
// }
// options.setLonLats( lonLats );
// mMapView.getMapAutoViewHelper().drawThickLine( options );
// } catch( Exception e ){
// e.printStackTrace();
// }
SinglePointRoadInfo singlePointRoadInfo = MapDataApi.INSTANCE.getSinglePointMatchRoad(((float) wgs[0]), ((float) wgs[1]), ((float) angle), isGpsLocation, isRTK);
if ( singlePointRoadInfo == null || singlePointRoadInfo.getCoords() == null || singlePointRoadInfo.getCoords().isEmpty() ) {
return null;
}
roadCacheMap.put(id, null);
return null;
double matchedPoint[] = PointInterpolatorUtil.mergeToRoad(wgs[0], wgs[1], singlePointRoadInfo.getCoords());
return matchedPoint;
// RoadCacheWrapper roadCache = roadCacheMap.get(id);
// if (roadCache == null) {
// SinglePointRoadInfo singlePointRoadInfo = MapDataApi.INSTANCE.getSinglePointMatchRoad(((float) wgs[0]), ((float) wgs[1]), ((float) angle), isGpsLocation, isRTK);
// if (singlePointRoadInfo != null && singlePointRoadInfo.getCoords() != null && !singlePointRoadInfo.getCoords().isEmpty()) {
// Log.i("timer-matchRoad-4", "cost " + (System.currentTimeMillis() - start) + "ms roadId: " + singlePointRoadInfo.getRoadId());
// roadCache = new RoadCacheWrapper(singlePointRoadInfo.getCoords());
// }
// }
//
// Log.i("timer-matchRoad-1", "cost " + (System.currentTimeMillis() - start) + "ms");
// if (roadCache != null
// && roadCache.getRoad() != null
// && !roadCache.getRoad().isEmpty()) {
// start = System.currentTimeMillis();
// double matchedPoint[] = PointInterpolatorUtil.mergeToRoad(wgs[0], wgs[1], roadCache.getRoad());
// if (matchedPoint[2] > 0 && matchedPoint[2] < 1.5) {
//// if (roadCache.inCache(matchedPoint[0], matchedPoint[1])) {
// roadCacheMap.put(id, roadCache);
// Log.i("timer-matchRoad-3", "cost " + (System.currentTimeMillis() - start) + "ms");
// return matchedPoint;
//// }
//// roadCacheMap.put(id, null);
//// Log.i("timer-matchRoad-2", "cost " + (System.currentTimeMillis() - start) + "ms roadId: "+roadCache.getLastLat());
//// return matchRoad(id, lon, lat, angle, isGpsLocation, isRTK,false);
// }else{
// roadCacheMap.put(id, null);
// Log.i("timer-matchRoad-2", "cost " + (System.currentTimeMillis() - start) + "ms roadId: " + roadCache.getLastLat());
//// if(usdCache) {
//// return matchRoad(id, lon, lat, angle, isGpsLocation, isRTK, false);
//// }else{
//// return null;
//// }
// return null;
// }
// }
// roadCacheMap.put(id, null);
// return null;
}
@Override

View File

@@ -2,6 +2,7 @@ package com.mogo.map.impl.custom.marker;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.text.TextUtils;
import android.view.View;
import android.view.animation.Interpolator;
@@ -58,6 +59,9 @@ public class AMapMarkerWrapper implements IMogoMarker, Observer {
if ( marker != null ) {
// 设置自研 marker 的object对象为 IMogoMarker 实例。!!!!
marker.setMObject( this );
if ( !TextUtils.isEmpty( mogoMarkerOptions.getAnchorColor() ) ) {
marker.setAnchorColor( mogoMarkerOptions.getAnchorColor() );
}
MarkerWrapperClickHelper.getInstance().setMogoMarkerMap( marker.getId(), this );
}
setObject( mogoMarkerOptions.getObject() );
@@ -592,9 +596,9 @@ public class AMapMarkerWrapper implements IMogoMarker, Observer {
}
@Override
public void addDynamicAnchorPosition( MogoLatLng latLng, long duration ) {
public void addDynamicAnchorPosition( MogoLatLng latLng, float angle, long duration ) {
try {
mMarker.addDynamicAnchorPostion( new LonLatPoint( latLng.lon, latLng.lat ), System.currentTimeMillis(), ( int ) duration );
mMarker.addDynamicAnchorPostion( new LonLatPoint( latLng.lon, latLng.lat, angle ), System.currentTimeMillis(), ( int ) duration );
} catch ( Exception e ) {
e.printStackTrace();
}

View File

@@ -90,6 +90,7 @@ public class ObjectUtils {
// }
MarkerOptions markerOptions = new MarkerOptions()
.setGps( opt.isGps() )
.position( new LonLatPoint( opt.getLongitude(), opt.getLatitude() ) )
.anchor( opt.getU(), opt.getV() )
.icons( descriptors )
@@ -100,13 +101,17 @@ public class ObjectUtils {
.visible( opt.isVisible() )
.infoWindowEnable( opt.isInifoWindowEnable() )
.alpha( opt.getAlpha() )
.setGps( opt.isGps() )
// .draggable( opt.isDraggable() )
.setInfoWindowOffset( opt.getOffsetX(), opt.getOffsetY() )
.zIndex( opt.getzIndex() );
try {
Color.parseColor( opt.getAnchorColor() );
markerOptions.anchorColor( opt.getAnchorColor() );
} catch ( Exception e ) {
}
markerOptions.vrEnable( opt.is3DMode() );
if ( !TextUtils.isEmpty( opt.getResName() ) ) {
markerOptions.setMarkerIconName( opt.getResName() );
markerOptions.vrEnable( opt.is3DMode() );
} else {
BitmapDescriptor descriptor = getBitmapDescriptorFromMogo( opt );
if ( descriptor != null ) {
@@ -114,11 +119,6 @@ public class ObjectUtils {
}
if ( opt.getIcon3DRes() != 0 ) {
markerOptions.marker3DIcon( opt.getIcon3DRes() );
try {
Color.parseColor( opt.getAnchorColor() );
markerOptions.anchorColor( opt.getAnchorColor() );
} catch ( Exception e ) {
}
}
}
if ( !TextUtils.isEmpty( opt.getTitle() ) ) {