@vtx/cs-map
Version:
React components for Vortex
66 lines (64 loc) • 2.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _cesium = require("cesium");
/**
* @description: 抛物线构造函数(方程 y=-(4h/L^2)*x^2+h h:顶点高度 L:横纵间距较大者)
* @param {*} startPosition: 起点
* @param {*} endPosition: 终点
* @param {*} height: 高度
* @param {*} count: 数量
* @return {*}
*/
var parabola = function parabola(_ref) {
var startPosition = _ref.startPosition,
endPosition = _ref.endPosition,
_ref$height = _ref.height,
height = _ref$height === void 0 ? 0 : _ref$height,
_ref$count = _ref.count,
count = _ref$count === void 0 ? 50 : _ref$count;
if (!height) {
return [new _cesium.Cartesian3.fromDegrees(startPosition[0], startPosition[1], startPosition[2] || 0), new _cesium.Cartesian3.fromDegrees(endPosition[0], endPosition[1], endPosition[2] || 0)];
}
var minHeight = startPosition[2] || endPosition[2] || 0;
var result = [];
height = Math.max(+height, 100);
count = Math.max(+count, 50);
var diffLon = Math.abs(startPosition[0] - endPosition[0]);
var diffLat = Math.abs(startPosition[1] - endPosition[1]);
var L = Math.max(diffLon, diffLat);
var dlt = L / count;
if (diffLon > diffLat) {
//base on lon
var delLat = (endPosition[1] - startPosition[1]) / count;
if (startPosition[0] - endPosition[0] > 0) {
dlt = -dlt;
}
for (var i = 0; i < count; i++) {
var h = height - Math.pow(-0.5 * L + Math.abs(dlt) * i, 2) * 4 * height / Math.pow(L, 2);
var lon = startPosition[0] + dlt * i;
var lat = startPosition[1] + delLat * i;
var point = new _cesium.Cartesian3.fromDegrees(lon, lat, h + minHeight);
result.push(point);
}
} else {
//base on lat
var delLon = (endPosition[0] - startPosition[0]) / count;
if (startPosition[1] - endPosition[1] > 0) {
dlt = -dlt;
}
for (var _i = 0; _i < count; _i++) {
var _h = height - Math.pow(-0.5 * L + Math.abs(dlt) * _i, 2) * 4 * height / Math.pow(L, 2);
var _lon = startPosition[0] + delLon * _i;
var _lat = startPosition[1] + dlt * _i;
var _point = new _cesium.Cartesian3.fromDegrees(_lon, _lat, _h + minHeight);
result.push(_point);
}
}
result.push(new _cesium.Cartesian3.fromDegrees(endPosition[0], endPosition[1], endPosition[2] || 0));
return result;
};
var _default = exports["default"] = parabola;
//# sourceMappingURL=parabola.js.map