安卓实现marker上下反复弹跳
安卓没找到可以方便实现我的需求的方法, 找到了一个自定义的方法
/**
* 屏幕中心marker 跳动
*/
public void startJumpAnimation(LatLng latLng, Marker locationMarker) {
if (locationMarker != null) {
//根据屏幕距离计算需要移动的目标点
Point point = aMap.getProjection().toScreenLocation(latLng);
point.y -= dip2px(getContext(), 10);
LatLng target = aMap.getProjection()
.fromScreenLocation(point);
//使用TranslateAnimation,填写一个需要移动的目标点
Animation animation = new TranslateAnimation(target);
animation.setInterpolator(new Interpolator() {
@Override
public float getInterpolation(float input) {
// 模拟重加速度的interpolator
if (input <= 0.5) {
return (float) (0.5f - 2 * (0.5 - input) * (0.5 - input));
} else {
return (float) (0.5f - Math.sqrt((input - 0.5f) * (1.5f - input)));
}
}
});
//整个移动所需要的时间
animation.setDuration(1500);
animation.setRepeatCount(Animation.INFINITE);
//设置动画
locationMarker.setAnimation(animation);
//开始动画
locationMarker.startAnimation();
} else {
Log.e("ama", "screenMarker is null");
}
}
//dip和px转换
private int dip2px(Context context, float dpValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}
web端实现高德marker 上下反复弹跳
将这段代码写在具体的方法中,实现对应功能.
主要就是这句代码 ele
就是具体的marker对象
ele.setAnimation('AMAP_ANIMATION_BOUNCE');
// 遍历所有marker将点击选择的marker添加跳动动画
let markers = map.getAllOverlays('marker');
markers.forEach((ele) => {
if (ele.getExtData().deviceSerial == record.deviceSerial) {
ele.setAnimation('AMAP_ANIMATION_BOUNCE');
}
});
marker的setAnimation()
方法给marker添加动画效果
'AMAP_ANIMATION_BOUNCE'
这个参数就是实现marker上下反复弹跳效果