2015-12-22 99 views
0

我下面的代碼如何沿着地圖的路徑繪製多段線,知道地圖中存在的點將只給出直線如何沿着路徑車道在openlayer3中沿着地圖的路徑繪製折線

<!DOCTYPE html> 
    <html> 
    <head> 
     <title>Rotation example</title> 
    </head> 
    <body> 
    <div style="width:80%; height:80%; position:fixed; border: 1px solid;" id="map"></div> 
    <script src="http://openlayers.org/en/v3.11.2/build/ol.js"></script> 
    <script> 

     var lineString = new ol.geom.LineString([ 
      [103.986083, 1.350349], 
      [103.985097, 1.349067] 
     ]); 
     lineString.transform('EPSG:4326', 'EPSG:3857'); 

     var lineLayer = new ol.layer.Vector({ 
      source: new ol.source.Vector({ 
       features: [new ol.Feature({ 
        geometry: lineString, 
        name: 'Line' 
       })] 
      }), 
      style: new ol.style.Style({ 
       stroke: new ol.style.Stroke({ 
        color: [255, 255, 0, 0.5], 
        width: 10 
       }) 
      }) 
     }); 

     var view = new ol.View({ 
      center: ol.proj.transform([103.986908, 1.353199], 'EPSG:4326','EPSG:3857'), 
      zoom: 18, 
      rotation: 68*Math.PI/180 
     }); 

     var map = new ol.Map({ 
      layers: [ 
       new ol.layer.Tile({ 
        source: new ol.source.OSM() 
       }), 
       lineLayer 
      ], 
      target: 'map', 
      controls: ol.control.defaults({ 
       attributionOptions: /** @type {olx.control.AttributionOptions} */ ({ 
        collapsible: false 
       }) 
      }), 
      view: view 
     }); 



    </script> 

    </body> 
    </html> 

是否存在被openlayer3提供請點樣來完成它

回答

0

如果你有沿車道座標,你可以使用MultiLineString代替LineString的任何方向的服務。

+0

請指出一些演示或示例代碼,這將有助於要做到這一點 – DhanaLaxshmi

+0

我想這樣http://gis.stackexchange.com/questions/174876/how-to-draw-coordinates-along-the-lanes-using-multilinestring-instead-of-linestr但是折線是沒有顯示可以ü請說出了什麼問題 – DhanaLaxshmi

0

您需要爲此類操作使用路由服務。您可以設置自己的服務,也可以使用任何可用的在線服務。 here你可以找到一個免費的在線路由器列表,並根據你的需要決定哪一條最好。 一旦你從你選擇的服務中得到根多義線,你就可以解碼(如果編碼)並在你的ol3地圖中畫出你的線。 也是cosider,根據你將要使用的服務,ol3提供了一個讀取和寫入數據的編碼折線算法格式描述的類here

+0

請指向一些示例代碼或演示 – DhanaLaxshmi

+0

我想這樣http://gis.stackexchange.com/questions/174876/how-to-draw-coordinates-along-the-使用multilinestring-instead-of-linestr,但折線不顯示可以請你說出了什麼問題 – DhanaLaxshmi

+0

我有回答d回答您提供的問題。或許它可以幫助你的情況 – pavlos