2016-06-16 99 views
0

我正在試圖用arc.js繪製測地線。當點的經度差小於180時,它可以正常工作。經度爲179和-179,OpenLayers繪製最大距離的線。如何通過OpenLayers 3中的地圖邊界繪製測地線?

所以,我發現對於直線的溶液:

  1. 察看經度之間差值大於180
  2. 計算所需的線的交叉點和映射邊緣(尋找臨時點與經度180或-180)
  3. 與陣列[[firstPoint, temporaryPoint], [temporaryPoint, secondPoint]]
  4. 與線創建特徵創建ol.geom.MultiLineString

它工作正常。但使用arc.js爲測地線製作這個技巧是相當複雜的。主要問題是計算交集。

enter image description here

我應該找到在文檔的OpenLayers或examples解決方案,但存在與地圖邊緣相交沒有任何例子。

+0

OFF-TOPIC:爲什麼你的照片中的敵意? –

+0

@JonatasWalker不再:) :) –

+0

哈哈哈..好多了:-) –

回答

1

經過數小時的調查,我找到了解決方案。這看起來像一個技巧,但它工作正常。

的一切都在這裏首先是從arc.js documentation原始代碼:

var start = { x: currentPoint.longitude, y: currentPoint.latitude }, 
    end = { x: nextPoint.longitude, y: nextPoint.latitude }, 
    generator = new arc.GreatCircle(start, end), 
    arcLine = generator.Arc(1000 ,{offset:10}); 

的主要問題是arc.js不能計算相交International Date Line線座標。所以我決定在計算Great Circle之前將點移到一個tile中。

我必須找到經度偏差:

var dateLineOffset = 180 - currentPoint.longitude; 

它也可能是nextPoint.longitude。取決於左側的位置。

後,您可以使用arc.js生成座標:

var start = { x: -180, y: currentPoint.latitude }, 
    end = { x: nextPoint.longitude + dateLineOffset, y: nextPoint.latitude }, 
    generator = new arc.GreatCircle(start, end), 
    arcLine = generator.Arc(1000 ,{offset:10}); 

然後,你需要重複生成的座標和修復所抵消。在我的情況下,我用地圖

var coordinatesWithOffset = arcLine.geometries[0].coords, 
    geodesicLineCoordinates = coordinatesWithOffset.map(function(coord) { 
     return ol.proj.fromLonLat([coord[0] - dateLineOffset, coord[1]]); 
    }), 
    geodesicLine = ol.geom.LineString(geodesicLineCoordinates); 

就是這樣。 geodesicLine將包含適當的座標。

enter image description here

相關問題