优化显示逻辑

This commit is contained in:
wangcongtao
2021-03-09 10:05:49 +08:00
parent 76f0095dd7
commit 731ffde5aa
12 changed files with 219 additions and 110 deletions

View File

@@ -8,6 +8,7 @@ import android.graphics.Typeface;
import android.location.Location;
import android.os.Bundle;
import android.os.Trace;
import android.text.TextUtils;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
@@ -25,6 +26,7 @@ import com.mogo.map.impl.custom.navi.NaviClient;
import com.mogo.map.impl.custom.utils.MogoMapUtils;
import com.mogo.map.impl.custom.utils.ObjectUtils;
import com.mogo.map.impl.custom.utils.PointInterpolatorUtil;
import com.mogo.map.impl.custom.utils.ResIdCache;
import com.mogo.map.listener.MogoMapListenerHandler;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.uicontroller.CarCursorOption;
@@ -67,7 +69,9 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class AMapViewWrapper implements IMogoMapView,
IMogoMapUIController,
@@ -770,7 +774,6 @@ public class AMapViewWrapper implements IMogoMapView,
showSelfSpeed( location.getSpeed() );
}
private float mLastSpeed = 0;
private TextView mSpeedView = null;
private void showSelfSpeed( float speed ) {
@@ -786,19 +789,28 @@ public class AMapViewWrapper implements IMogoMapView,
mSelfMarker.hideInfoWindow();
return;
}
if ( Math.abs( mLastSpeed - speed ) > 0 ) {
int speedIntVal = ( int ) ( speed * 3.6 );
if ( speedIntVal <= 0 ) {
mSelfMarker.hideInfoWindow();
return;
}
String speedVal = String.valueOf( speedIntVal );
String infoResName = ResIdCache.getVal( speedVal );
if ( TextUtils.isEmpty( infoResName ) ) {
if ( mSpeedView == null ) {
mSpeedView = new TextView( mMapView.getContext() );
mSpeedView.setTextColor( Color.WHITE );
mSpeedView.setTypeface( Typeface.defaultFromStyle( Typeface.BOLD ) );
// mSpeedView.setShadowLayer( 10f, 5F, 5F, Color.BLACK );
mSpeedView.setLayoutParams( new ViewGroup.LayoutParams( ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT ) );
}
mSpeedView.setText( String.valueOf( ( ( int ) ( speed * 3.6 ) ) ) );
mSpeedView.setText( speedVal );
mSelfMarker.setInfoWindowOffset( 0, 20 );
mSelfMarker.setInfoWindowView( mSpeedView );
ResIdCache.putVal( speedVal, mSelfMarker.getMarkeOptions().getMarkerInfoName() );
} else {
mSelfMarker.hideInfoWindow();
mSelfMarker.setMarkerInfoName( infoResName );
}
}
@@ -1021,44 +1033,31 @@ public class AMapViewWrapper implements IMogoMapView,
e.printStackTrace();
}
}
private float lastRoadId;
@Override
public double[] matchRoad( double lon, double lat, double angle, boolean isGpsLocation, boolean isRTK ) {
double wgs[] = new double[]{lon, lat};//CoordinateUtils.transformGcj02toWgs84( lat, lon );
double wgs[] = new double[]{lon, lat};
long start = System.currentTimeMillis();
SinglePointRoadInfo singlePointRoadInfo = MapDataApi.INSTANCE.getSinglePointMatchRoad( ( ( float ) wgs[0] ), ( ( float ) wgs[1] ), ( ( float ) angle ), isGpsLocation, isRTK );
Log.i("timer-matchRoad-1", "cost " + (System.currentTimeMillis() - start) + "ms");
if ( singlePointRoadInfo != null
&& singlePointRoadInfo.getCoords() != null
&& !singlePointRoadInfo.getCoords().isEmpty() ) {
start = System.currentTimeMillis();
double matchedPoint[] = PointInterpolatorUtil.mergeToRoad( wgs[0], wgs[1], singlePointRoadInfo.getCoords() );
// return CoordinateUtils.transformWgsToGcj( matchedPoint[1], matchedPoint[0] );
// double[] trans = CoordinateUtils.transformWgsToGcj(matchedPoint[1], matchedPoint[0]);
// matchedPoint[0] = trans[0];
// matchedPoint[1] = trans[1];
// MarkerOptions options
// = new MarkerOptions();
// options.markerIcon( R.drawable.red )
// .position( new LonLatPoint( matchedPoint[0], matchedPoint[1] ) )
// .setGps( false );
// mMapView.getMapAutoViewHelper().addMarker( options );
//
// MarkerOptions options2 = new MarkerOptions();
// options2.markerIcon( R.drawable.blue )
// .position( new LonLatPoint( lon, lat ) )
// .setGps( true );
// mMapView.getMapAutoViewHelper().addMarker( options2 );
// if(lastRoadId != singlePointRoadInfo.getRoadId()) {
// lastRoadId = singlePointRoadInfo.getRoadId();
// PolylineOptions lineOptions = new PolylineOptions();
// lineOptions.setGps(true)
// .lonLatPoints(singlePointRoadInfo.getCoords())
// .color(Color.RED)
// .lineWidth(10);
// mMapView.getMapAutoViewHelper().drawLine(lineOptions);
// }
Log.i("timer-matchRoad-2", "cost " + (System.currentTimeMillis() - start) + "ms");
return matchedPoint;
}
return null;
}
@Override
public String getMarkerInfoResName( String speedVal ) {
return null;
}
@Override
public void setMarkerInfoResName( String speedVal, String val ) {
ResIdCache.putVal( speedVal, val );
}
}

View File

@@ -7,6 +7,7 @@ import android.view.animation.Interpolator;
import com.mogo.map.MogoLatLng;
import com.mogo.map.impl.custom.utils.ObjectUtils;
import com.mogo.map.impl.custom.utils.ResIdCache;
import com.mogo.map.marker.IMogoInfoWindowAdapter;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.marker.IMogoMarkerClickListener;
@@ -543,6 +544,15 @@ public class AMapMarkerWrapper implements IMogoMarker, Observer {
}
}
@Override
public void updateInfoWindowView( String viewResName ) {
try {
mMarker.setMarkerInfoName( viewResName );
} catch ( Exception e ) {
Logger.e( TAG, e, "error." );
}
}
@Override
public void setInfoWindowOffset( int offsetX, int offsetY ) {
try {
@@ -571,4 +581,15 @@ public class AMapMarkerWrapper implements IMogoMarker, Observer {
}
return "";
}
@Override
public String getMarkerInfoResName() {
if ( mMarker != null ) {
try {
return mMarker.getMarkeOptions().getMarkerInfoName();
} catch ( Exception e ) {
}
}
return "";
}
}

View File

@@ -321,4 +321,19 @@ public class AMapUIController implements IMogoMapUIController {
}
return null;
}
@Override
public String getMarkerInfoResName( String speedVal ) {
if ( mClient != null ) {
return mClient.getMarkerInfoResName( speedVal );
}
return null;
}
@Override
public void setMarkerInfoResName( String speedVal, String val ) {
if ( mClient != null ) {
mClient.setMarkerInfoResName( speedVal, val );
}
}
}

View File

@@ -0,0 +1,24 @@
package com.mogo.map.impl.custom.utils;
import java.util.HashMap;
import java.util.Map;
public
/**
* @author congtaowang
* @since 2021/3/8
*
* 描述
*/
class ResIdCache {
public static Map< String, String > sMarkerCachesResMd5Values = new HashMap<>();
public static String getVal( String name ) {
return sMarkerCachesResMd5Values.get( name );
}
public static void putVal( String name, String val ) {
sMarkerCachesResMd5Values.put( name, val );
}
}