UNPKG

leaflet

Version:

JavaScript library for mobile-friendly interactive maps

147 lines (146 loc) • 6.07 kB
import { Path } from './Path.js'; import { LatLng } from '../../geo/LatLng.js'; import { LatLngBounds } from '../../geo/LatLngBounds.js'; import { Bounds } from '../../geometry/Bounds.js'; import { Point } from '../../geometry/Point.js'; import type { Feature, Geometry, LineString, MultiLineString } from 'geojson'; import type { Defaults, InteractiveLayerEventMap, LatLngExpression, NestedCoords, PolylineDefaults, PolylineOptions } from '../../types.js'; /** @import {Feature, Geometry, LineString, MultiLineString} from 'geojson' */ /** @import {Defaults, InteractiveLayerEventMap, LatLngExpression, NestedCoords, PolylineDefaults, PolylineOptions} from '../../types.js' */ declare const defaultOptions: { /** * How much to simplify the polyline on each zoom level (Douglas–Peucker epsilon, in pixels). Higher values * mean faster rendering but less accuracy; lower values mean more accuracy but slower rendering. */ smoothFactor: number; /** Disable polyline clipping. */ noClip: boolean; }; export type PolylineDefaultsValues = typeof defaultOptions; /** @typedef {typeof defaultOptions} PolylineDefaultsValues */ /** * A class for drawing polyline overlays on a map. Extends `Path`. * @example * ```js * // create a red polyline from an array of LatLng points * const latlngs = [ * [45.51, -122.68], * [37.77, -122.43], * [34.04, -118.2] * ]; * * const polyline = new Polyline(latlngs, {color: 'red'}).addTo(map); * * // zoom the map to the polyline * map.fitBounds(polyline.getBounds()); * ``` * * You can also pass a multi-dimensional array to represent a `MultiPolyline` shape: * * ```js * // create a red polyline from an array of arrays of LatLng points * const latlngs = [ * [[45.51, -122.68], * [37.77, -122.43], * [34.04, -118.2]], * [[40.78, -73.91], * [41.83, -87.62], * [32.76, -96.72]] * ]; * ``` * @template {PolylineOptions} [O=PolylineOptions] * @template {InteractiveLayerEventMap} [E=InteractiveLayerEventMap] * @template {Geometry} [G=LineString | MultiLineString] the geometry `toGeoJSON` returns * @extends {Path<O & PolylineDefaults, E>} */ export declare class Polyline<O extends PolylineOptions = PolylineOptions, E extends InteractiveLayerEventMap = InteractiveLayerEventMap, G extends Geometry = LineString | MultiLineString> extends Path<O & PolylineDefaults, E> { /** @type {LatLngBounds} */ _bounds: LatLngBounds; /** @type {NestedCoords<LatLng>} */ _latlngs: NestedCoords<LatLng>; /** @type {Point[][]} */ _rings: Point[][]; /** @type {Bounds | undefined} */ _rawPxBounds: Bounds | undefined; _pxBounds: Bounds | undefined; /** @type {Point[][]} */ _parts: Point[][]; static initHooks: boolean; /** @type {Defaults<PolylineOptions>} */ static defaultOptions: Defaults<PolylineOptions>; /** * Instantiates a polyline object given an array of geographical points and optionally an options object. You * can create a `Polyline` object with multiple separate lines (`MultiPolyline`) by passing an array of arrays * of geographic points. * @param {NestedCoords<LatLngExpression>} latlngs * @param {NoInfer<Partial<O>>} [options] */ constructor(latlngs: NestedCoords<LatLngExpression>, options?: NoInfer<Partial<O>>); /** * Returns an array of the points in the path, or nested arrays of points in case of multi-polyline. * @returns {NestedCoords<LatLng>} */ getLatLngs(): NestedCoords<LatLng>; /** * Replaces all the points in the polyline with the given array of geographical points. * @param {NestedCoords<LatLngExpression>} latlngs */ setLatLngs(latlngs: NestedCoords<LatLngExpression>): this; /** Returns `true` if the Polyline has no LatLngs. */ isEmpty(): boolean; /** * Returns the point closest to `p` on the Polyline, with its `distance` to `p`, or `null` when the polyline * has no points on the screen. * @param {Point} p */ closestLayerPoint(p: Point): (Point & { distance: number; }) | null; /** Returns the center ([centroid](https://en.wikipedia.org/wiki/Centroid)) of the polyline. */ getCenter(): LatLng; /** Returns the `LatLngBounds` of the path. */ getBounds(): LatLngBounds; /** * Adds a given point to the polyline. By default, adds to the first ring of the polyline * in case of a multi-polyline, but can be overridden by passing a specific ring as a LatLng * array (that you can earlier access with [`getLatLngs`](#polyline-getlatlngs)). * @param {LatLngExpression} latlng * @param {LatLng[]} [latlngs] */ addLatLng(latlng: LatLngExpression, latlngs?: LatLng[]): this; /** * Coordinates values are rounded with [`formatNum`](#util-formatnum) function with given * `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON) representation * of the polyline (as a GeoJSON `LineString` or `MultiLineString` Feature). * @param {number | false} [precision] * @returns {Feature<G>} */ toGeoJSON(precision?: number | false): Feature<G>; /** @param {NestedCoords<LatLngExpression>} latlngs */ _setLatLngs(latlngs: NestedCoords<LatLngExpression>): void; /** @returns {LatLng[]} */ _defaultShape(): LatLng[]; /** * @param {NestedCoords<LatLngExpression>} latlngs * @returns {NestedCoords<LatLng>} */ _convertLatLngs(latlngs: NestedCoords<LatLngExpression>): NestedCoords<LatLng>; _project(): void; _updateBounds(): void; /** * @param {NestedCoords<LatLng>} latlngs * @param {Point[][]} result * @param {Bounds} projectedBounds */ _projectLatlngs(latlngs: NestedCoords<LatLng>, result: Point[][], projectedBounds: Bounds): void; _clipPoints(): void; _simplifyPoints(): void; _update(): void; _updatePath(): void; /** * @param {Point} p * @param {boolean} [closed] */ _containsPoint(p: Point, closed?: boolean): boolean; } export {};