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++) {

View File

@@ -20,6 +20,11 @@ android {
}
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
dependencies {

View File

@@ -6,6 +6,7 @@ import android.graphics.Point;
import android.view.animation.Interpolator;
import com.mogo.map.MogoLatLng;
import com.mogo.map.marker.anim.OnMarkerAnimationListener;
import java.util.ArrayList;
import java.util.List;
@@ -247,6 +248,38 @@ public interface IMogoMarker {
int duration,
Interpolator interpolator );
/**
* 缩放动画
*
* @param fromX
* @param toX
* @param fromY
* @param toY
* @param duration
* @param interpolator
* @param listener
*/
void startScaleAnimation( float fromX,
float toX,
float fromY,
float toY,
int duration,
Interpolator interpolator,
OnMarkerAnimationListener listener );
/**
* 弹跳动画
* @param high
* @param duration
* @param interpolator
* @param listener
*/
void startJumpAnimation( float high,
long duration,
Interpolator interpolator,
OnMarkerAnimationListener listener);
/**
* 是否是否可点击
*
@@ -257,8 +290,8 @@ public interface IMogoMarker {
/**
* 开始平滑移动
*
* @param points 坐标点
* @param duration 时长
* @param points 坐标点
* @param duration 时长
*/
void startSmooth(List<MogoLatLng> points, int duration);
void startSmooth( List< MogoLatLng > points, int duration );
}

View File

@@ -0,0 +1,16 @@
package com.mogo.map.marker.anim;
/**
* @author congtaowang
* @since 2020-04-22
* <p>
* marker 动画监听
*/
public interface OnMarkerAnimationListener {
default void onAnimStart() {
}
default void onAnimEnd() {
}
}

View File

@@ -11,6 +11,7 @@ import androidx.annotation.Nullable;
import com.mogo.map.MogoLatLng;
import com.mogo.map.marker.IMogoMarker;
import com.mogo.map.marker.anim.OnMarkerAnimationListener;
import java.util.List;
@@ -141,12 +142,15 @@ public interface IMogoMapUIController {
/**
* marker 跳跃动画
* <p>
* Deprecated, instead of by {@link IMogoMarker#startJumpAnimation(float, long, Interpolator, OnMarkerAnimationListener)}
*
* @param marker 跳跃的 marker
* @param high 跳跃的高度
* @param interpolator 插值器
* @param duration 动画时间
*/
@Deprecated
void startJumpAnimation( IMogoMarker marker, float high, Interpolator interpolator,
long duration );