2015-12-22 103 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