leaflet 动态线渲染

可以采用leaflet插件 leaflet-ant-path

...
<script src="js/leaflet-ant-path.js" type="text/javascript" charset="utf-8"></script>
...

  //坐标反转,注:antPath为路径数组,坐标格式为[lon,lat]

  //格式示例:var coords=[[-3.65358, -38.71431],[-3.66402, -38.71528],[-3.66861, -38.71573]]

  var coords = [];
  route.forEach(function(e, i) {
    coords.push(e.reverse())
  });

  var antPath = L.polyline.antPath;
  var path = antPath(coords, {
    "paused": false,
    "reverse": false,
    "delay": 3000,
    "dashArray": [10, 20],
    "weight": 5,
    "opacity": 0.5,
    "color": "#0000FF",
    "pulseColor": "#FFFFFF"
  });
  path.addTo(map); 

//源地址 https://rubenspgcavalcante.github.io/leaflet-ant-path/

效果图如下

L.polyline.antPath参数和方法

 

猜你喜欢

转载自www.cnblogs.com/viczcj/p/9438870.html