Leaflet实现动态线路
程序员文章站
2022-04-11 20:11:54
一、引用Leaflet脚本样式,和Leaflet Ant Path 插件 下载地址: Leaflet:https://leafletjs.com/download.html Leaflet Ant Path:https://github.com/rubenspgcavalcante/leaflet- ......
一、引用leaflet脚本样式,和leaflet ant path 插件
下载地址:
leaflet:
使用leaflet ant path 插件要求leaflet的版本大于等于1.0
<link href="~/scripts/leafletjs/1.4.0/leaflet.css" rel="stylesheet" /> <script src="~/scripts/leafletjs/1.4.0/leaflet.js"></script> <script src="~/scripts/leafletjs/1.4.0/leaflet-ant-path.js"></script>
二、地图初始化
/** * 地图初始化 */ function mapinit() { var amapnormalurl = '/api/map/getmap?type=783085212&zoom={z}&x={x}&y={y}'; var amapnormallayer = new l.tilelayer(amapnormalurl, { minzoom: 1, maxzoom: 18, attribution: '' }); var mapcenter = new l.latlng(****,****); gmap = new l.map('mapcontainer', { center: mapcenter, zoom: 16, minzoom: 1, maxzoom: 18, layers: [amapnormallayer] }); }
三、画动态线段
//清楚上一次画的线段 if (gpath) { gmap.removelayer(gpath); } var longlatlist =[[****,****],[*****,****]];//经纬度数组 var antpath = l.polyline.antpath; gpath = antpath(longlatlist, { "paused": false, //暂停 初始化状态 "reverse": false, //方向反转 "delay": 3000, //延迟,数值越大效果越缓慢 "dasharray": [10, 20], //间隔样式 "weight": 3, //线宽 "opacity": 0.5, //透明度 //"color": "#0000ff", //颜色 //"pulsecolor": "#ffffff" //块颜色 }); gpath.addto(gmap); // 缩放地图到折线所在区域 gmap.fitbounds(gpath.getbounds());
上一篇: 千里之外领导的学习小组正在进行野外调研
下一篇: 倒霉人的倒霉相,倒霉糗图片