UNPKG

leaflet

Version:

JavaScript library for mobile-friendly interactive maps

76 lines (75 loc) • 3.45 kB
import { Polyline } from './Polyline.js'; import { Point } from '../../geometry/Point.js'; import type { Feature, MultiPolygon, Polygon as GeoJSONPolygon } from 'geojson'; import type { LatLng } from '../../geo/LatLng.js'; import type { Defaults, InteractiveLayerEventMap, LatLngExpression, NestedCoords, PolylineOptions } from '../../types.js'; /** * A class for drawing polygon overlays on a map. Extends `Polyline`. * * Note that points you pass when creating a polygon shouldn't have an additional * last point equal to the first one — it's better to filter out such points. * @constructorDescription Instantiates a polygon given an array of geographical points (or arrays of rings, as * shown below) and optionally an options object. * @example * ```js * // create a red polygon from an array of LatLng points * const latlngs = [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]]; * * const polygon = new Polygon(latlngs, {color: 'red'}).addTo(map); * * // zoom the map to the polygon * map.fitBounds(polygon.getBounds()); * ``` * * You can also pass an array of arrays of latlngs, with the first array representing the outer shape and the other arrays representing holes in the outer shape: * * ```js * const latlngs = [ * [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring * [[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole * ]; * ``` * * Additionally, you can pass a multi-dimensional array to represent a MultiPolygon shape. * * ```js * const latlngs = [ * [ // first polygon * [[37, -109.05],[41, -109.03],[41, -102.05],[37, -102.04]], // outer ring * [[37.29, -108.58],[40.71, -108.58],[40.71, -102.50],[37.29, -102.50]] // hole * ], * [ // second polygon * [[41, -111.03],[45, -111.04],[45, -104.05],[41, -104.05]] * ] * ]; * ``` * @template {PolylineOptions} [O=PolylineOptions] * @template {InteractiveLayerEventMap} [E=InteractiveLayerEventMap] * @extends {Polyline<O, E, GeoJSONPolygon | MultiPolygon>} */ export declare class Polygon<O extends PolylineOptions = PolylineOptions, E extends InteractiveLayerEventMap = InteractiveLayerEventMap> extends Polyline<O, E, GeoJSONPolygon | MultiPolygon> { /** @type {LatLng[][] | LatLng[][][]} */ _latlngs: LatLng[][] | LatLng[][][]; /** @type {Defaults<PolylineOptions>} */ static defaultOptions: Defaults<PolylineOptions>; isEmpty(): boolean; /** Returns the center ([centroid](http://en.wikipedia.org/wiki/Centroid)) of the Polygon. */ getCenter(): LatLng; /** * Coordinates values are rounded with [`formatNum`](#util-formatnum) function with given * `precision`. Returns a [`GeoJSON`](https://en.wikipedia.org/wiki/GeoJSON) representation * of the polygon (as a GeoJSON `Polygon` or `MultiPolygon` Feature). * @param {number | false} [precision] * @returns {Feature<GeoJSONPolygon | MultiPolygon>} */ toGeoJSON(precision?: number | false): Feature<GeoJSONPolygon | MultiPolygon>; /** @param {NestedCoords<LatLngExpression>} latlngs */ _convertLatLngs(latlngs: NestedCoords<LatLngExpression>): NestedCoords<LatLng>; /** @param {NestedCoords<LatLngExpression>} latlngs */ _setLatLngs(latlngs: NestedCoords<LatLngExpression>): void; _defaultShape(): LatLng[]; _clipPoints(): void; _updatePath(): void; /** @param {Point} p */ _containsPoint(p: Point): boolean; }