我需要一种基于纬度/经度坐标,旋转和长度(以米为单位)的openLayers绘制多边形的方法。
示例:"我想从点1(纬度,长度)到点2绘制一条线,其中点2的计算基于它位于115米处,距离点1的旋转角度为115度#34;
谷歌地图有一种使用spherical.computeOffset()方法计算坐标的简便方法。 OpenLayers有类似的东西吗?或者是否有其他好的开源库的建议可以帮助我?
答案 0 :(得分: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)];
};