UNPKG

leaflet

Version:

JavaScript library for mobile-friendly interactive maps

147 lines (146 loc) • 6.81 kB
import { FeatureGroup } from './FeatureGroup.js'; import { LatLng } from '../geo/LatLng.js'; import { latLngToCoords, latLngsToCoords, getFeature, asFeature } from './GeoJSONUtil.js'; import type { Feature, GeoJSON as GeoJSONData, Geometry, Position } from 'geojson'; import type { FeatureGroupEventMap, GeoJSONOptions, NestedCoords, PathOptions } from '../types.js'; import type { Layer } from './Layer.js'; import type { MemberLayer } from './LayerGroup.js'; export type StyledLayer = Layer & { defaultOptions: object; }; export type StyleFunction = (feature: Feature<Geometry, any>) => Partial<PathOptions>; export type GeoJSONEventProps = { /** * The layer for the GeoJSON feature that is being added to the map. */ layer: Layer; /** * GeoJSON properties of the feature. */ properties: { [name: string]: any; } | null; /** * GeoJSON geometry type of the feature. */ geometryType: string; /** * GeoJSON ID of the feature (if present). */ id?: string | number; }; /** @import {Feature, GeoJSON as GeoJSONData, Geometry, Point as GeoJSONPoint, Position} from 'geojson' */ /** @import {FeatureGroupEventMap, GeoJSONOptions, NestedCoords, PathOptions} from '../types.js' */ /** @import {Layer} from './Layer.js' */ /** @import {MemberLayer} from './LayerGroup.js' */ /** @typedef {Layer & {defaultOptions: object}} StyledLayer */ /** * A function returning the `Path` options for a GeoJSON feature. * @typedef {(feature: Feature<Geometry, any>) => Partial<PathOptions>} StyleFunction */ /** * @typedef {Object} GeoJSONEventProps * @property {Layer} layer The layer for the GeoJSON feature that is being added to the map. * @property {{[name: string]: any} | null} properties GeoJSON properties of the feature. * @property {string} geometryType GeoJSON geometry type of the feature. * @property {string | number} [id] GeoJSON ID of the feature (if present). */ /** * Represents a GeoJSON object or an array of GeoJSON objects. Allows you to * parse GeoJSON data and display it on the map. Extends `FeatureGroup`. * @example * ```js * new GeoJSON(data, { * style: function (feature) { * return {color: feature.properties.color}; * } * }).bindPopup(function (layer) { * return layer.feature.properties.description; * }).addTo(map); * ``` * @categoryDescription Methods * There are several static functions which can be called without instantiating GeoJSON: * @template {GeoJSONOptions} [O=GeoJSONOptions] * @template {FeatureGroupEventMap} [E=FeatureGroupEventMap] * @extends {FeatureGroup<Layer, O, E>} */ export declare class GeoJSON<O extends GeoJSONOptions = GeoJSONOptions, E extends FeatureGroupEventMap = FeatureGroupEventMap> extends FeatureGroup<Layer, O, E> { static initHooks: boolean; /** * Creates a GeoJSON layer. Optionally accepts an object in [GeoJSON format](https://tools.ietf.org/html/rfc7946) * to display on the map (you can alternatively add it later with `addData` method) and an `options` object. * @param {GeoJSONData | GeoJSONData[] | null} [geojson] * @param {NoInfer<Partial<O>>} [options] */ constructor(geojson?: GeoJSONData | GeoJSONData[] | null, options?: NoInfer<Partial<O>>); /** * Adds a GeoJSON object to the layer. * @param {GeoJSONData | GeoJSONData[]} geojson */ addData(geojson: GeoJSONData | GeoJSONData[]): this; /** * Resets the given vector layer's style to the original GeoJSON style, useful for resetting style after * hover events. If `layer` is omitted, the style of all features in the current layer is reset. * @param {Layer} [layer] */ resetStyle(layer?: Layer): this; /** * Changes styles of GeoJSON vector layers with the given style function. * @param {Partial<PathOptions> | StyleFunction} style */ setStyle(style: Partial<PathOptions> | StyleFunction): this; /** * @param {MemberLayer} layer * @param {Partial<PathOptions> | StyleFunction} [style] */ _setLayerStyle(layer: MemberLayer, style?: Partial<PathOptions> | StyleFunction): void; /** * Creates a `Layer` from a given GeoJSON feature. Can use a custom [`pointToLayer`](#geojson-pointtolayer) * and/or [`coordsToLatLng`](#geojson-coordstolatlng) functions if provided as options. Returns `null` for a * feature without a geometry. * @param {GeoJSONData} geojson * @param {Partial<GeoJSONOptions>} [options] * @returns {Layer | null} */ static geometryToLayer(geojson: GeoJSONData, options?: Partial<GeoJSONOptions>): Layer | null; /** * @param {GeoJSONOptions['pointToLayer']} pointToLayerFn * @param {GeoJSONData} geojson * @param {LatLng} latlng * @param {Partial<GeoJSONOptions>} [options] * @returns {Layer} */ static _pointToLayer(pointToLayerFn: GeoJSONOptions['pointToLayer'], geojson: GeoJSONData, latlng: LatLng, options?: Partial<GeoJSONOptions>): Layer; /** * Creates a `LatLng` object from an array of 2 numbers (longitude, latitude) * or 3 numbers (longitude, latitude, altitude) used in GeoJSON for points. * @param {Position} coords */ static coordsToLatLng(coords: Position): LatLng; /** * Creates a multidimensional array of `LatLng`s from a GeoJSON coordinates array. `levelsDeep` specifies * the nesting level (0 is for an array of points, 1 for an array of arrays of points, etc., 0 by * default). Can use a custom [`coordsToLatLng`](#geojson-coordstolatlng) function. * @param {NestedCoords<Position>} coords * @param {number} [levelsDeep] * @param {(coords: Position) => LatLng} [coordsToLatLng] * @returns {NestedCoords<LatLng>} */ static coordsToLatLngs(coords: NestedCoords<Position>, levelsDeep?: number, coordsToLatLng?: (coords: Position) => LatLng): NestedCoords<LatLng>; /** * Reverse of [`coordsToLatLng`](#geojson-coordstolatlng) Coordinates * values are rounded with [`formatNum`](#util-formatnum) function. */ static latLngToCoords: typeof latLngToCoords; /** * Reverse of [`coordsToLatLngs`](#geojson-coordstolatlngs), with the nesting detected from the array, so * `levelsDeep` is ignored. `close` determines whether the first point should be appended to the end of each * flat array to close the feature. False by default. Coordinates values are rounded with * [`formatNum`](#util-formatnum) function. */ static latLngsToCoords: typeof latLngsToCoords; /** Returns GeoJSON geometries/features of layer with new GeoJSON geometry. */ static getFeature: typeof getFeature; /** Normalize GeoJSON geometries/features into GeoJSON features. */ static asFeature: typeof asFeature; }