【问题标题】:How do I draw a geodesic line through map edges in OpenLayers 3?如何在 OpenLayers 3 中通过地图边缘绘制测地线?
【发布时间】:2016-06-16 10:29:22
【问题描述】:

我正在尝试用arc.js 绘制测地线。当点的经度之间的差异小于 180 时,它可以正常工作。否则,例如经度是 179 和 -179,OpenLayers 绘制距离最大的线。

所以我找到了直线的解决方案:

  1. 检查经度差是否大于 180
  2. 计算所需线与地图边缘的交点(寻找经度180或-180的临时点)
  3. 使用数组[[firstPoint, temporaryPoint], [temporaryPoint, secondPoint]] 创建ol.geom.MultiLineString
  4. 用线创建特征

而且效果很好。但是用arc.js 来制作测地线这个技巧是相当复杂的。主要问题是交点的计算。

我应该在 OpenLayers 文档或 examples 中找到解决方案,但没有任何地图边缘交叉点的示例。

【问题讨论】:

  • 离题:为什么你的照片中充满敌意?
  • @JonatasWalker 不再 :)
  • 哈哈哈..好多了:-)

标签: javascript maps coordinates openlayers openlayers-3


【解决方案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之前将点移动到一个图块中。

我必须找到经度偏移量:

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});

然后您需要迭代生成的坐标并修复偏移量。在我的例子中,我使用了 ma​​p

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 将包含正确的坐标。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-17
    • 1970-01-01
    • 2016-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多