一、引用Leaflet腳本樣式,和Leaflet Ant Path 插件 下載地址: Leaflet:https://leafletjs.com/download.html Leaflet Ant Path:https://github.com/rubenspgcavalcante/leaflet- ...
一、引用Leaflet腳本樣式,和Leaflet Ant Path 插件
下載地址:
Leaflet:https://leafletjs.com/download.html
Leaflet Ant Path:https://github.com/rubenspgcavalcante/leaflet-ant-path
使用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());