OpenLayers计算偏移量坐标 [英] OpenLayers compute offset coordinates
问题描述
我需要一种基于经纬度,旋转和长度(以米为单位)的openLayers绘制多边形的方法.
示例:我想绘制一条从点1(经度,纬度)到点2的线,其中,点2的计算依据是它位于115米处,并且从点1开始旋转115度." >
Google地图通过使用spherical.computeOffset()方法,可以轻松地计算坐标. OpenLayers是否有类似的东西?还是有其他不错的开源库的建议可以包括在内,对我有帮助?
看看
Google maps has an easy way of calculating coordinates by using spherical.computeOffset() method. Does OpenLayers has anything similar? Or are there suggestions of other nice open source libraries to include that can help me? Have a look at https://github.com/openlayers/ol3/blob/master/src/ol/sphere/sphere.js#L256 It's not api, but should be easy to copy and modify to your code.
这篇关于OpenLayers计算偏移量坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!/**
* 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)];
};