This commit is contained in:
wangcongtao
2020-04-22 20:22:47 +08:00
parent a9cbb82420
commit c6378cfc07
7 changed files with 295 additions and 153 deletions

View File

@@ -16,6 +16,7 @@ import com.amap.api.maps.model.animation.Animation;
import com.amap.api.maps.model.animation.ScaleAnimation;
import com.amap.api.maps.model.animation.TranslateAnimation;
import com.amap.api.maps.utils.overlay.MovingPointOverlay;
import com.mogo.commons.AbsMogoApplication;
import com.mogo.map.MogoLatLng;
import com.mogo.map.impl.amap.AMapWrapper;
import com.mogo.map.impl.amap.utils.ObjectUtils;
@@ -24,6 +25,7 @@ import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.marker.IMogoMarkerClickListener;
import com.mogo.map.marker.IMogoMarkerIconViewCreator;
import com.mogo.map.marker.MogoMarkerOptions;
import com.mogo.map.marker.anim.OnMarkerAnimationListener;
import com.mogo.utils.WindowUtils;
import com.mogo.utils.logger.Logger;
@@ -85,6 +87,11 @@ public class AMapMarkerWrapper implements IMogoMarker, Observer {
mMarker = null;
}
if (mMovingPointOverlay != null){
try {
mMovingPointOverlay.destroy();
} catch ( Exception e ) {
e.printStackTrace();
}
mMovingPointOverlay = null;
}
mMogoInfoWindowAdapter = null;
@@ -340,6 +347,86 @@ public class AMapMarkerWrapper implements IMogoMarker, Observer {
mMarker.startAnimation();
}
@Override
public void startScaleAnimation( float fromX, float toX, float fromY, float toY, int duration, Interpolator interpolator, OnMarkerAnimationListener listener ) {
if ( isDestroyed() ) {
return;
}
ScaleAnimation animationScale = new ScaleAnimation( fromX, toX, fromY, toY );
animationScale.setDuration( duration );
animationScale.setFillMode( Animation.FILL_MODE_FORWARDS );
animationScale.setInterpolator( interpolator );
animationScale.setAnimationListener( new Animation.AnimationListener() {
@Override
public void onAnimationStart() {
if ( isDestroyed() ) {
return;
}
if ( listener != null ) {
listener.onAnimStart();
}
}
@Override
public void onAnimationEnd() {
if ( isDestroyed() ) {
return;
}
if ( listener != null ) {
listener.onAnimEnd();
}
}
} );
mMarker.setAnimation( animationScale );
mMarker.startAnimation();
}
@Override
public void startJumpAnimation( float high, long duration, Interpolator interpolator, OnMarkerAnimationListener listener ) {
if ( isDestroyed() || high <= 0.0f || interpolator == null || duration < 0 ) {
return;
}
try {
final LatLng latLng = ObjectUtils.fromMogo2( getPosition() );
Point point = AMapWrapper.getAMap().getProjection().toScreenLocation( latLng );
point.y -= WindowUtils.dip2px( AbsMogoApplication.getApp(), high );
LatLng target = AMapWrapper.getAMap().getProjection().fromScreenLocation( point );
//使用TranslateAnimation,填写一个需要移动的目标点
Animation animation = new TranslateAnimation( target );
animation.setInterpolator( interpolator );
animation.setAnimationListener( new Animation.AnimationListener() {
@Override
public void onAnimationStart() {
if ( isDestroyed() ) {
return;
}
if ( listener != null ) {
listener.onAnimStart();
}
}
@Override
public void onAnimationEnd() {
if ( isDestroyed() ) {
return;
}
if ( listener != null ) {
listener.onAnimEnd();
}
}
} );
//整个移动所需要的时间
animation.setDuration( duration );
//设置动画
mMarker.setAnimation( animation );
mMarker.startAnimation();
} catch ( Exception e ) {
Logger.e( TAG, e, "error." );
}
}
@Override
public void setClickable( boolean clickable ) {
if ( mMarker != null ) {
@@ -349,6 +436,11 @@ public class AMapMarkerWrapper implements IMogoMarker, Observer {
@Override
public void startSmooth(List<MogoLatLng> points,int duration) {
if ( isDestroyed() ) {
return;
}
if (mMarker != null && points.size() > 0){
List<LatLng> p = new ArrayList<>();
for (int i = 0; i < points.size(); i++) {