功能修改,要求在地图上有个类似雷达的水波纹扩散的动画,通过大半天时间的研究、查找,终于完成了这项任务,话不多说,下面直接贴出代码,供有需要的兄弟参考,

1、首先在地图上画个圆如下图

2、新建个JS

/*校验时间 End*/

var timeStart, timeEnd, time;//申明全局变量

var radius = 300 //水纹圆半径(300米)

var circles1; //探测出入口的水波圆

var circles2; //探测出入口的水波圆

var circles3; //探测出入口的水波圆

var bl_drag = false; //拖拽地图控制开关

function getTimeNow() {//获取此刻时间

var now = new Date();

return now.getTime();

}

/*地图水波扩散特效 Start*/

let requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame;

let cancelAnimationFrame = window.cancelAnimationFrame || window.webkitCancelAnimationFrame;

/**

* sos告警圆形范围绘制(只有存在map对象时才可以使用)

* @param radius 半径

* @param level 层数

* @param point BMap.Point对象,圆的中心点

* @param color 颜色对象,包含{fillColor,fillOpacity}

* @constructor

*/

function CircleShow(radius,level,point,color,icon){

console.log(radius);

if(!window.map || !window.BMap|| !window.BMap.Circle){

return undefined;

}

this.radius = radius;

this.level = new Number(level);

this.point = point;

this.color = color;

// 创建 AMap.Icon 实例:

var xinhao_icon = new AMap.Icon({

size: new AMap.Size(20, 20),

// 图标尺寸

image: icon, // Icon的图像

imageSize: new AMap.Size(20, 20) // 根据所设置的大小拉伸或压缩图片

});

new AMap.Marker({

map: map,

icon: xinhao_icon,

position: point,

offset: new AMap.Pixel(-14, -5)

});

if(Number.isNaN(this.level)){

this.level = 1;

}//至少1层

if(!this.color || !this.color.fillColor){

this.color = {

fillColor:"blue",//默认蓝色

fillOpacity:0.3 //默认初始透明度0.3

}

}

//计算平均每段扩展距离的透明度

this.endOpacity = 0.1; //终止透明度设置为0.1

this.speedOpacity = (this.color.fillOpacity - this.endOpacity)/this.radius; //每米的透明度

//先加一层红色的覆盖物,加在图片上表示覆盖范围

/*this.circle0 = new BMap.Circle(this.point,this.radius,{

fillColor:"white",

fillOpacity: 0.2,

strokeWeight: 1 ,

strokeColor:"white",

strokeOpacity: 0.2,

enableEditing:false

});

map.addOverlay(this.circle0);*/

//按层数循环构造覆盖物,并加在图片上

this.circles = new Array();

for(let i=1; i< this.level; i++){

var circle = new AMap.Circle({

center: point,

icon: 'direct.png',

radius: radius, //半径

fillColor:this.color.fillColor, //圆形填充颜色

fillOpacity: 0.2, //填充透明度

strokeWeight: 1 ,

strokeColor:"#FF4D50", //线条颜色,为了保证感觉无线条,和填充颜色一致即可

strokeOpacity: 0.2, //线条透明度,为了保证感觉无线条,和填充颜色透明度一致即可

zIndex: 50

});

this.circles.push(circle);

circle.setMap(map);

}

this.clock=new Array(this.level);

}

/**

* 动画启动

* @param distance 波纹间隔时间(单位ms)

* @param t0 扩散一次所需的时间

*/

CircleShow.prototype.start = function (distance,t0){

let _self = this;

/**

* 定义动画函数

* @param startTime 启动的初始时间

* @param circle 圆形覆盖物对象

* @param index 序号

*/

function animateStart(startTime,circle,index){

//计算时间差

let time = new Date().getTime()-startTime;

if(time<0){

circle.setRadius(0); //半径

// circle.setFillOpacity(_self.color.fillColor); //透明度

// circle.setStrokeOpacity(_self.color.fillOpacity); //透明度

//如果未达到执行实现则直接等待

_self.clock[index] = window.requestAnimationFrame(animateStart.bind(null,startTime,circle,index));

return;

}

//计算当前半径

//匀减速运动下,每隔t时间,应该扩散的半径:

//r=r0*(2*t*t0-t*t)/t0

//其中,r0为最终的扩散半径,即this.radius

let r = Math.floor(_self.radius*(2*time/t0-time*time/t0/t0));

let opacity = 0;

if(time >= t0){

//达到运行时间之后

//设置圆形覆盖物的样式

circle.setRadius(_self.radius); //半径

// circle.setFillOpacity(_self.endOpacity); //透明度

// circle.setStrokeOpacity(_self.endOpacity); //透明度

startTime = new Date().getTime() + distance; //起始时间设置为当前时间加上1倍的时间间隔

_self.clock[index] = window.requestAnimationFrame(animateStart.bind(null,startTime,circle,index));

}else{

//计算透明度

let opacity = _self.color.fillOpacity -

Number.parseFloat((_self.speedOpacity * r).toFixed(5)); //四舍五入小数点后5位

//设置圆形覆盖物的样式

circle.setRadius(r); //半径

// circle.setFillOpacity(opacity); //透明度

// circle.setStrokeOpacity(opacity); //透明度

_self.clock[index] = window.requestAnimationFrame(animateStart.bind(null,startTime,circle,index));

}

}

//循环每一层执行动画

for (let [index,circle] of this.circles.entries()) {

animateStart(new Date().getTime()+index*distance, circle, index);

}

};

/**

* 停止动画.

*/

CircleShow.prototype.stop = function(){

for(let caf of this.clock){

window.cancelAnimationFrame(caf);

}

//重置覆盖物样式

for(let circle of this.circles){

circle.setRadius(0); //半径

// circle.setFillOpacity(this.color.fillOpacity); //透明度

// circle.getStrokeOpacity(this.color.fillOpacity); //透明度

}

this.clock=null;

};

/**

* 移除覆盖物.

*/

CircleShow.prototype.remove = function(){

//停止动画

for(let caf of this.clock){

window.cancelAnimationFrame(caf);

}

map.remove(this.circle);

for(let circle of this.circles){

map.remove(circle);

}

};

/*地图水波扩散特效 End*/

3、页面初始化高德地图直接调用

水波纹扩散

效果如下

有一点需要注意一下:在这个循环的时候会显示entries未定义,也是纳闷了很久,但是我无意间导入了百度地图的JS后居然就可以了

导入文件

//百度地图JS

//高德地图

有关于那个循环问题有想法的大佬们,欢迎指教

参考文张:https://blog.csdn.net/yingjia11/article/details/86540150

Android百度地图水波纹动画,高德地图实现水波纹扩散相关推荐

  1. 高德地图去掉定位按钮_怎样修改百度地图店名怎么取消高德地图定位

    11月28日下午,**百度地图今天公布了与四个北欧旅游局的战略合作,并公布了本月将在非洲.欧洲和亚洲推出的106个国家. 今年4月,百度地图正式发布了*对外开放国际化战略,并在年底宣传完成150多个国 ...

  2. android高德地图获取海拔_高德地图如何查经纬度和海拔

    展开全部 高德地图测海拔的具体方法如下: 1.第一步打636f70793231313335323631343130323136353331333366306564开高德地图的网页,找到并点击下方那行小 ...

  3. react 逆地理 高德地图_react中使用高德地图的原生API

    干货,无话 1.react-create-app,创建新react项目: 2.npm install react-amap,引入高德地图的封装: 3.编写组件index.js: import Reac ...

  4. marker 头像 高德地图_高德地图头像怎么更换 高德地图更换头像图文教程

    相信绝大部分人都知道微信头像以及QQ头像怎么更换,而设置头像也是很多人喜欢做的一件事情.而对于经常使用高德地图的用户来说,头像该怎么设置呢?对于这群用户,下面百事网小编为大家带来详细的高德地图更换头像 ...

  5. Android 起调第三方导航,百度地图,高德地图,腾讯地图。起调高德地图导航

    主要工具类 /*** Created by meixi on 2018/6/29.* 使用第三方导航:高德.百度..........*/ public class AmapUtil {public s ...

  6. android 接百度SDK遇到的坑(百度地图BD09经纬度转高德地图GCJ02经纬度)

    百度转高德==> /*** 百度坐标系 (BD-09) 与 火星坐标系 (GCJ-02)的转换* 即 百度 转 谷歌.高德** @param latLng* @returns*/public s ...

  7. android仿高德地图首页,Android BottomSheet 的使用(仿高德地图的列表效果)

    最近项目中突然要实现高德地图中列表的效果,刚开始一筹莫展,以为是自定义控件还是通过手势进行判断 ,果断蒙了,百度谷歌了一下最后发现原来谷歌早就就出来了这样的效果--android.support.de ...

  8. 南邮Android实验报告三:基于高德地图的综合应用

    实验三 基于高德地图的综合应用 一.目的要求 1.学会安卓应用中涉及位置服务时的解决方案. 2.练习在使用第三方插件时,遇到版本不兼容时的处理步骤和方法. 二.实验环境 1.硬件配置:Intel Co ...

  9. 百度地图与腾讯/高德地图经纬度转换

    //将腾讯/高德地图经纬度转换为百度地图经纬度 //将腾讯/高德地图经纬度转换为百度地图经纬度 function qqMapTransBMap(lng, lat) {let x_pi = 3.1415 ...

最新文章

  1. android EditText 修改光标的颜色值
  2. uniapp处理IOS底部横条安全区域
  3. ob_start()失效与phpunit的非正常结束
  4. python中的类与对象
  5. python在for循环中不能删除正在循环的列表(问题已解决)
  6. Internationalization(i18n) support in SAP CRM,UI5 and Hybris
  7. js里的面向对象分析-(创建实例化对象)
  8. 平凡的世界电子书pdf下载_零基础彩铅画入门教程步骤图及全套PDF电子书教程下载!...
  9. 雷军:技术立业是小米血液里最重要的东西
  10. AutoCAD.net: 用于ObjectARX 开发的Visual Studio 智能感知文件
  11. 制作内网yum源 同步阿里的源
  12. C++11::lambda 的用法
  13. Java 中的 AQS 到底是什么?高级面试必问!
  14. Spring Boot 如何快速改造老项目?原来这么爽
  15. 什么叫做:离线下载?-by:nixs
  16. 大学计算机基础第五版习题和课后题答案
  17. BZOJ4198: [Noi2015]荷马史诗(哈夫曼树)
  18. 如何获取iphone的UUID
  19. python_open函数中newline参数详解
  20. Why the MonthCalendar.MinDate is 01/01/1753?

热门文章

  1. MQTT-java使用说明
  2. C语言:for循环用法 完全攻略
  3. 视频教程-PPT吸金大法 20+万年薪工作总结不用愁-Office/WPS
  4. iPad air2 充不进去电
  5. unity中3dUI或者模型始终面向摄像机,跟随摄像机视角旋转丨视角跟随丨固定视角
  6. python中size的用法.dim_【Numpy库学习笔记】Numpy中dim、shape和size的理解
  7. python时间索引_Python时间戳作为索引
  8. OpenCV中的神经网络
  9. 孙陶然:企业的方方面面皆可创新皆需要创新
  10. Hotmail Smtp邮箱发送的端口