2017-09-13 171 views

回答

0

您可以使用此插件:http://hgoebl.github.io/Leaflet.MultiOptionsPolyline/demo/

你必須定義的速度在您的GeoJSON屬性各點。

然後你只需要後添加以下代碼:

var myPolyline = L.multiOptionsPolyline(YourGeoJSONHere, { 
    multiOptions: { 
     optionIdxFn: function (latLng) { 
      var i, 
       speedThresholds = [5, 10, 15, 30]; 

      for (i = 0; i < speedThresholds.length; ++i) { 
       if (latLng.alt <= speedThresholds[i]) { 
        return i; 
       } 
      } 
      return speedThresholds.length; 
     }, 
     options: [ 
      {color: '#0000FF'}, {color: '#0040FF'}, 
      {color: '#0080FF'}, {color: '#00FFB0'} 
     ] 
    }, 
    weight: 5, 
    opacity: 0.9, 
    smoothFactor: 1 
}).addTo(layerTrace); 

對於速度:https://github.com/hgoebl/Leaflet.MultiOptionsPolyline/blob/master/demo/js/demo.js#L59-L80

相關問題