UNPKG

sun-horizon

Version:

Horizon profile and sun path form a lat lng point

61 lines (60 loc) 2.52 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const location_1 = require("./location"); const types_1 = require("./types"); const cache_1 = require("./cache"); function getAltitude(latLng) { return __awaiter(this, void 0, void 0, function* () { return new Promise((resolve, reject) => { cache_1.getTiles().getElevation([latLng.lat, latLng.lng], (err, altitude) => { if (err) reject(err); resolve(altitude); }); }); }); } exports.getAltitude = getAltitude; function highestPointInAzimuth(origin, azimuth, options = {}) { return __awaiter(this, void 0, void 0, function* () { let highestPoint = { latLng: origin, altitude: yield getAltitude(origin), angle: 0, azimuth }; const parametes = new types_1.HighestPointParams(options); let distance = parametes.distanceTick; while (distance <= parametes.distanceMax) { const location = location_1.getLocationDestination(origin, azimuth, distance); const altitude = yield getAltitude(location); const angle = getAngle(highestPoint.altitude, altitude, distance); if (angle > highestPoint.angle) { highestPoint = { latLng: location, altitude, angle, azimuth }; } distance += parametes.distanceTick; } return highestPoint; }); } exports.highestPointInAzimuth = highestPointInAzimuth; function getAngle(fromAltitude, toAltitude, distance) { return radToDeg(Math.atan((toAltitude - fromAltitude) / distance)); } function radToDeg(rad) { return rad * 180 / Math.PI; }