【问题标题】:OpenLayers compute offset coordinatesOpenLayers 计算偏移坐标
【发布时间】:2015-07-28 15:25:17
【问题描述】:

我需要一种基于纬度/经度坐标、旋转和长度(以米为单位)的 openLayers 绘制多边形的方法。

示例:“我想从点 1(纬度、经度)到点 2 画一条线,其中点 2 的计算基于它位于 115 米处,从点 1 旋转 115 度”

谷歌地图有一个简单的方法来计算坐标,使用球面.computeOffset() 方法。 OpenLayers 有类似的东西吗?或者是否有其他不错的开源库的建议可以帮助我?

【问题讨论】:

    标签: openlayers-3


    【解决方案1】:

    看看https://github.com/openlayers/ol3/blob/master/src/ol/sphere/sphere.js#L256

    它不是 api,但应该很容易复制和修改到您的代码。

    /**
     * Returns the coordinate at the given distance and bearing from `c1`.
     *
     * @param {ol.Coordinate} c1 The origin point (`[lon, lat]` in degrees).
     * @param {number} distance The great-circle distance between the origin
     *     point and the target point.
     * @param {number} bearing The bearing (in radians).
     * @return {ol.Coordinate} The target point.
     */
    ol.Sphere.prototype.offset = function(c1, distance, bearing) {
      var lat1 = goog.math.toRadians(c1[1]);
      var lon1 = goog.math.toRadians(c1[0]);
      var dByR = distance / this.radius;
      var lat = Math.asin(
          Math.sin(lat1) * Math.cos(dByR) +
          Math.cos(lat1) * Math.sin(dByR) * Math.cos(bearing));
      var lon = lon1 + Math.atan2(
          Math.sin(bearing) * Math.sin(dByR) * Math.cos(lat1),
          Math.cos(dByR) - Math.sin(lat1) * Math.sin(lat));
      return [goog.math.toDegrees(lon), goog.math.toDegrees(lat)];
    };
    

    【讨论】:

    • 谢谢!我很快就会检查出来。你有任何迹象表明做这个客户端的成本吗?假设每 30 秒计算 500 次纬度/经度偏移值。由于潜在的性能问题,我正在考虑将计算移动到服务器端...
    • 上面的函数不是很重,与你的ol3实例所做的大多数其他事情相比,它是超轻量级的。
    猜你喜欢
    • 2021-08-04
    • 1970-01-01
    • 2014-01-11
    • 1970-01-01
    • 2011-12-20
    • 2021-08-07
    • 2018-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多