的OpenLayers计算偏移坐标(OpenLayers compute offset coordi

2019-11-03 22:54发布

我需要绘图基于纬度/经度坐标,旋转和lenght(以米为单位)的OpenLayers多边形的方式。

例如:“我要绘制从点1(纬度,经度)的线点2是基于这样的事实,它位于115米的115度从点1的旋转计算,其中点2”

谷歌地图使用spherical.computeOffset()方法计算坐标的一种简单的方法。 是否具有的OpenLayers类似的事情? 还是有其他不错的开源库的建议,包括能帮助我吗?

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


文章来源: OpenLayers compute offset coordinates