UNPKG

qwc2

Version:
89 lines (87 loc) 3.31 kB
/** * Copyright 2025 Sourcepole AG * All rights reserved. * * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ import axios from "axios"; import ConfigUtils from "./ConfigUtils"; /** * Interface for querying elevations/height profiles */ var ElevationInterface = { /** * Query the elevation at the specified position * * * `pos`: query position, as tuple `[x, y]` * * `crs`: CRS of the query position, as an EPSG string * * Returns: a promise which resolves to an elevation value (in meteres) * or an object with a `list` property containing an array of objects with * `elevation` and `dataset` properties, if multiple datasets are available. */ getElevation: function getElevation(pos, crs) { return new Promise(function (resolve, reject) { var serviceUrl = ConfigUtils.getConfigProp("elevationServiceUrl", null, "").replace(/\/$/, ''); if (!serviceUrl) { reject(null); return; } axios.get(serviceUrl + '/getelevation', { params: { pos: pos.join(","), crs: crs } }).then(function (response) { var _response$data$elevat; resolve((_response$data$elevat = response.data.elevation) !== null && _response$data$elevat !== void 0 ? _response$data$elevat : { list: response.data.elevation_list }); })["catch"](function (e) { reject(String(e)); }); }); }, /** * Query the elevation profile along the specified line * * * `coordinates`: line coordinates `[[x1, y1], [x2, y2], ...]` * * `distances`: distances of the line segments `[dist1, dist2, ...]` * * `crs`: CRS of the line coordinates, as an EPSG string * * `samples`: the number of samples * * Returns a promise which resolves to the elevation values `[z1, z2, ...]` * or an object with a `list` property containing an array of objects with * `elevations` and `dataset` properties, if multiple datasets are available. */ getProfile: function getProfile(coordinates, distances, crs, samples) { return new Promise(function (resolve, reject) { var serviceUrl = ConfigUtils.getConfigProp("elevationServiceUrl", null, "").replace(/\/$/, ''); if (!serviceUrl) { reject(null); return; } axios.post(serviceUrl + '/getheightprofile', { coordinates: coordinates, distances: distances, projection: crs, samples: samples }).then(function (response) { resolve(response.data.elevations || { list: response.data.elevations_list }); })["catch"](function (e) { var _e$response; var error = (_e$response = e.response) !== null && _e$response !== void 0 && (_e$response = _e$response.data) !== null && _e$response !== void 0 && _e$response.error ? e.response.data.error : e; /* eslint-disable-next-line */ console.log("Query failed: " + error); reject(String(error)); }); }); } }; export function getElevationInterface() { var _window$QWC2Elevation; return (_window$QWC2Elevation = window.QWC2ElevationInterface) !== null && _window$QWC2Elevation !== void 0 ? _window$QWC2Elevation : ElevationInterface; }