leaflet
Version:
JavaScript library for mobile-friendly interactive maps
98 lines (97 loc) • 4.16 kB
TypeScript
import { Point } from './Point.js';
import { LatLng } from '../geo/LatLng.js';
import type { Bounds } from './Bounds.js';
import type { CRS } from '../geo/crs/CRS.js';
import type { LatLngExpression } from '../types.js';
/**
* @import {Bounds} from './Bounds.js'
* @import {CRS} from '../geo/crs/CRS.js'
* @import {LatLngExpression} from '../types.js'
*/
/**
* Various utility functions for polyline points processing, used by Leaflet internally to make polylines
* lightning-fast.
* @module LineUtil
*/
/**
* Dramatically reduces the number of points in a polyline while retaining its shape and returns a new
* array of simplified points, using the [Ramer-Douglas-Peucker
* algorithm](https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm). Used for a huge performance
* boost when processing/displaying Leaflet polylines for each zoom level and also reducing visual noise.
* tolerance affects the amount of simplification (lesser value means higher quality but slower and with
* more points). Also released as a separated micro-library
* [Simplify.js](https://mourner.github.io/simplify-js/).
* @param {Point[]} points
* @param {number} tolerance
*/
export declare function simplify(points: Point[], tolerance: number): Point[];
/**
* Returns the distance between point `p` and segment `p1` to `p2`.
* @param {Point} p
* @param {Point} p1
* @param {Point} p2
*/
export declare function pointToSegmentDistance(p: Point, p1: Point, p2: Point): number;
/**
* Returns the closest point from a point `p` on a segment `p1` to `p2`.
* @param {Point} p
* @param {Point} p1
* @param {Point} p2
*/
export declare function closestPointOnSegment(p: Point, p1: Point, p2: Point): Point;
/**
* Clips the segment a to b by rectangular bounds with the [Cohen-Sutherland
* algorithm](https://en.wikipedia.org/wiki/Cohen%E2%80%93Sutherland_algorithm). Used by Leaflet to only show
* polyline points that are on the screen or near, increasing performance. Returns the clipped endpoints (new points
* where clipped, rounded with `round`), or `false` if the segment is entirely outside the bounds. `useLastCode`
* reuses the bit code of `b` from the previous call as the code of `a`, for clipping consecutive segments of a line.
* @param {Point} a
* @param {Point} b
* @param {Bounds} bounds
* @param {boolean} [useLastCode]
* @param {boolean} [round]
* @returns {[Point, Point] | false}
*/
export declare function clipSegment(a: Point, b: Point, bounds: Bounds, useLastCode?: boolean, round?: boolean): [Point, Point] | false;
/**
* @param {Point} a
* @param {Point} b
* @param {number} code
* @param {Bounds} bounds
* @param {boolean} [round]
*/
export declare function _getEdgeIntersection(a: Point, b: Point, code: number, bounds: Bounds, round?: boolean): Point;
/**
* @param {Point} p
* @param {Bounds} bounds
*/
export declare function _getBitCode(p: Point, bounds: Bounds): number;
export declare function _sqClosestPointOnSegment(p: Point, p1: Point, p2: Point, sqDist: true): number;
export declare function _sqClosestPointOnSegment(p: Point, p1: Point, p2: Point, sqDist?: false): Point;
export type NestedCoords<T> = T[] | T[][] | T[][][];
/**
* An array of `T`s, nested up to 3 levels deep, like the points of a line, the rings of a polygon or the polygons
* of a multipolygon.
* @template T
* @typedef {T[] | T[][] | T[][][]} NestedCoords
*/
/**
* Returns true if `latlngs` is a flat array, false is nested.
* @template {object} T
* @param {NestedCoords<T>} latlngs
* @returns {latlngs is T[]}
*/
export declare function isFlat<T extends object>(latlngs: NestedCoords<T>): latlngs is T[];
/**
* Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid))
* of the passed LatLngs (first ring) from a polyline.
* @param {LatLngExpression[]} latlngs
* @param {typeof CRS} crs
*/
export declare function polylineCenter(latlngs: LatLngExpression[], crs: typeof CRS): LatLng;
/**
* @param {NestedCoords<LatLngExpression>} latlngs
* @param {typeof CRS} crs
* @returns {Point[]}
*/
export declare function _projectRing(latlngs: NestedCoords<LatLngExpression>, crs: typeof CRS): Point[];