@terrestris/ol-util
Version:
A set of helper classes for working with openLayers
136 lines (135 loc) • 6.09 kB
TypeScript
import OlGeomCircle from 'ol/geom/Circle';
import OlGeomLineString from 'ol/geom/LineString';
import OlGeomPolygon from 'ol/geom/Polygon';
import OlMap from 'ol/Map';
/**
* This class provides some static methods which might be helpful when working
* with measurements.
*
* @class MeasureUtil
*/
declare class MeasureUtil {
/**
* Get the length of a OlGeomLineString.
*
* @param {OlGeomLineString} line The drawn line.
* @param {OlMap} map An OlMap.
* @param {boolean} geodesic Is the measurement geodesic (default is true).
* @param {number} radius Sphere radius. By default, the radius of the earth
* is used (Clarke 1866 Authalic Sphere, 6371008.8).
* @param {number} decimalPrecision Set the decimal precision on length value
* for non-geodesic map (default value 6)
*
* @return {number} The length of line in meters.
*/
static getLength(line: OlGeomLineString, map: OlMap, geodesic?: boolean, radius?: number, decimalPrecision?: number): number;
/**
* Format length output for the tooltip.
*
* @param {OlGeomLineString} line The drawn line.
* @param {OlMap} map An OlMap.
* @param {number} decimalPlacesInToolTips How many decimal places will be
* allowed for the measure tooltips
* @param {boolean} geodesic Is the measurement geodesic (default is true).
*
* @return {string} The formatted length of the line (units: km, m or mm).
*/
static formatLength(line: OlGeomLineString, map: OlMap, decimalPlacesInToolTips: number, geodesic?: boolean): string;
/**
* Get the area of an OlGeomPolygon.
*
* @param {OlGeomPolygon} polygon The drawn polygon.
* @param {OlMap} map An OlMap.
* @param {boolean} geodesic Is the measurement geodesic (default is true).
* @param {number} radius Sphere radius. By default, the radius of the earth
* is used (Clarke 1866 Authalic Sphere, 6371008.8).
*
* @return {number} The area of the polygon in square meter.
*/
static getArea(polygon: OlGeomPolygon, map: OlMap, geodesic?: boolean, radius?: number): number;
/**
* Get the estimated area of an OlGeomCircle.
*
* @param {OlGeomCircle} circleGeom The drawn circle.
* @param {OlMap} map An OlMap.
*
* @return {number} The area of the circle in square meter.
*/
static getAreaOfCircle(circleGeom: OlGeomCircle, map: OlMap): number;
/**
* Format area output for the tooltip.
*
* @param {OlGeomPolygon | OlGeomCircle} geom The drawn geometry (circle or polygon).
* @param {OlMap} map An OlMap.
* @param {number} decimalPlacesInToolTips How many decimal places will be
* allowed for the measure tooltips.
* @param {boolean} geodesic Is the measurement geodesic.
*
* @return {string} The formatted area of the polygon.
*/
static formatArea(geom: OlGeomPolygon | OlGeomCircle, map: OlMap, decimalPlacesInToolTips: number, geodesic?: boolean): string;
/**
* Determine the angle between two coordinates. The angle will be between
* -180° and 180°, with 0° being in the east. The angle will increase
* counter-clockwise.
*
* Inspired by https://stackoverflow.com/a/31136507
*
* @param {Array<number>} start The start coordinates of the line with the
* x-coordinate being at index `0` and y-coordinate being at index `1`.
* @param {Array<number>} end The end coordinates of the line with the
* x-coordinate being at index `0` and y-coordinate being at index `1`.
*
* @return {number} the angle in degrees, ranging from -180° to 180°.
*/
static angle(start: number[], end: number[]): number;
/**
* Determine the angle between two coordinates. The angle will be between
* 0° and 360°, with 0° being in the east. The angle will increase
* counter-clockwise.
*
* Inspired by https://stackoverflow.com/a/31136507
*
* @param {Array<number>} start The start coordinates of the line with the
* x-coordinate being at index `0` and y-coordinate being at index `1`.
* @param {Array<number>} end The end coordinates of the line with the
* x-coordinate being at index `0` and y-coordinate being at index `1`.
*
* @return {number} the angle in degrees, ranging from 0° and 360°.
*/
static angle360(start: number[], end: number[]): number;
/**
* Given an angle between 0° and 360° this angle returns the exact opposite
* of the angle, e.g. for 90° you'll get back 270°. This effectively turns
* the direction of the angle from counter-clockwise to clockwise.
*
* @param {number} angle360 The input angle obtained counter-clockwise.
*
* @return {number} The clockwise angle.
*/
static makeClockwise(angle360: number): number;
/**
* This methods adds an offset of 90° to an counter-clockwise increasing
* angle of a line so that the origin (0°) lies at the top (in the north).
*
* @param {number} angle360 The input angle obtained counter-clockwise, with
* 0° degrees being in the east.
*
* @return {number} The adjusted angle, with 0° being in the north.
*/
static makeZeroDegreesAtNorth(angle360: number): number;
/**
* Returns the angle of the passed linestring in degrees, with 'N' being the
* 0°-line and the angle increases in clockwise direction.
*
* @param {OlGeomLineString} line The linestring to get the
* angle from. As this line is coming from our internal draw
* interaction, we know that it will only consist of two points.
* @param {number} decimalPlacesInToolTips How many decimal places will be
* allowed for the measure tooltips.
*
* @return {string} The formatted angle of the line.
*/
static formatAngle(line: OlGeomLineString, decimalPlacesInToolTips?: number): string;
}
export default MeasureUtil;