Class GeoJSON

L.Class powers the OOP facilities of Leaflet and is used to create almost all of the Leaflet classes documented.

Hierarchy

Index

Constructor methods

Methods

Constructor methods

constructor(geojson?: any, options?: GeoJSONOptions): GeoJSON

Creates a GeoJSON layer. Optionally accepts an object in GeoJSON format to display on the map (you can alternatively add it later with addData method) and an options object.

Parameters

Returns

GeoJSON

Methods

public addData(data: any): boolean

Adds a GeoJSON object to the layer.

Parameters

  • data: any

Returns

boolean

public addEventListener(type: string, fn: (e: L.LeafletEvent) => void, context?: any): FeatureGroup

Parameters

  • type: string
  • fn: (e: L.LeafletEvent) => void
  • context?: any optional

Returns

FeatureGroup

public addEventListener(eventMap: any, context?: any): FeatureGroup

Parameters

  • eventMap: any
  • context?: any optional

Returns

FeatureGroup

public addLayer(layer: T in L.LayerGroup<T extends ILayer>): LayerGroup

Adds a given layer to the group.

Parameters

  • layer: T in L.LayerGroup<T extends ILayer>

Returns

LayerGroup

public addLayer(layer: T in L.LayerGroup<T extends ILayer>): LayerGroup

Adds a given layer to the group.

Parameters

  • layer: T in L.LayerGroup<T extends ILayer>

Returns

LayerGroup

public addOneTimeEventListener(type: string, fn: (e: L.LeafletEvent) => void, context?: any): FeatureGroup

Parameters

  • type: string
  • fn: (e: L.LeafletEvent) => void
  • context?: any optional

Returns

FeatureGroup

public addTo(map: Map): LayerGroup

Adds the group of layers to the map.

Parameters

Returns

LayerGroup

public addTo(map: Map): LayerGroup

Adds the group of layers to the map.

Parameters

Returns

LayerGroup

public bindPopup(htmlContent: string, options?: PopupOptions): FeatureGroup

Binds a popup with a particular HTML content to a click on any layer from the group that has a bindPopup method.

Parameters

Returns

FeatureGroup

public bringToBack(): FeatureGroup

Brings the layer group to the bottom of all other layers.

Returns

FeatureGroup

public bringToFront(): FeatureGroup

Brings the layer group to the top of all other layers.

Returns

FeatureGroup

public clearAllEventListeners(): FeatureGroup

Returns

FeatureGroup

public clearLayers(): LayerGroup

Removes all the layers from the group.

Returns

LayerGroup

public clearLayers(): LayerGroup

Removes all the layers from the group.

Returns

LayerGroup

public static coordsToLatlng(coords: Array<number>, reverse?: boolean): LatLng

Creates a LatLng object from an array of 2 numbers (latitude, longitude) used in GeoJSON for points. If reverse is set to true, the numbers will be interpreted as (longitude, latitude).

Parameters

  • coords: Array<number>
  • reverse?: boolean optional

Returns

LatLng

public static coordsToLatlngs(coords: Array<number>, levelsDeep?: number, reverse?: boolean): LatLng[]

Creates a multidimensional array of LatLng objects 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). If reverse is set to true, the numbers will be interpreted as (longitude, latitude).

Parameters

  • coords: Array<number>
  • levelsDeep?: number optional
  • reverse?: boolean optional

Returns

LatLng[]

public eachLayer(fn: (layer: T) => void, context?: any): LayerGroup

Iterates over the layers of the group, optionally specifying context of the iterator function.

Parameters

  • fn: (layer: T) => void
  • context?: any optional

Returns

LayerGroup

public eachLayer(fn: (layer: T) => void, context?: any): LayerGroup

Iterates over the layers of the group, optionally specifying context of the iterator function.

Parameters

  • fn: (layer: T) => void
  • context?: any optional

Returns

LayerGroup

public fire(type: string, data?: any): FeatureGroup

Parameters

  • type: string
  • data?: any optional

Returns

FeatureGroup

public fireEvent(type: string, data?: any): FeatureGroup

Parameters

  • type: string
  • data?: any optional

Returns

FeatureGroup

public static geometryToLayer(featureData: GeoJSON, pointToLayer?: (featureData: any, latlng: L.LatLng) => L.ILayer): ILayer

Creates a layer from a given GeoJSON feature.

Parameters

  • featureData: GeoJSON
  • pointToLayer?: (featureData: any, latlng: L.LatLng) => L.ILayer optional

Returns

ILayer

public getBounds(): LatLngBounds

Returns the LatLngBounds of the Feature Group (created from bounds and coordinates of its children).

Returns

LatLngBounds

public getLayer(id: string): T in L.LayerGroup<T extends ILayer>

Returns the layer with the given id.

Parameters

  • id: string

Returns

T in L.LayerGroup<T extends ILayer>

public getLayer(id: string): T in L.LayerGroup<T extends ILayer>

Returns the layer with the given id.

Parameters

  • id: string

Returns

T in L.LayerGroup<T extends ILayer>

public getLayers(): Array<T extends L.ILayer>

Returns an array of all the layers added to the group.

Returns

Array<T extends L.ILayer>

public getLayers(): Array<T extends L.ILayer>

Returns an array of all the layers added to the group.

Returns

Array<T extends L.ILayer>

public hasEventListeners(type: string): boolean

Parameters

  • type: string

Returns

boolean

public hasLayer(layer: T in L.LayerGroup<T extends ILayer>): boolean

Returns true if the given layer is currently added to the group.

Parameters

  • layer: T in L.LayerGroup<T extends ILayer>

Returns

boolean

public hasLayer(layer: T in L.LayerGroup<T extends ILayer>): boolean

Returns true if the given layer is currently added to the group.

Parameters

  • layer: T in L.LayerGroup<T extends ILayer>

Returns

boolean

public off(type: string, fn?: (e: L.LeafletEvent) => void, context?: any): FeatureGroup

Parameters

  • type: string
  • fn?: (e: L.LeafletEvent) => void optional
  • context?: any optional

Returns

FeatureGroup

public off(eventMap?: any, context?: any): FeatureGroup

Parameters

  • eventMap?: any optional
  • context?: any optional

Returns

FeatureGroup

public on(type: string, fn: (e: L.LeafletEvent) => void, context?: any): FeatureGroup

Parameters

  • type: string
  • fn: (e: L.LeafletEvent) => void
  • context?: any optional

Returns

FeatureGroup

public on(eventMap: any, context?: any): FeatureGroup

Parameters

  • eventMap: any
  • context?: any optional

Returns

FeatureGroup

public onAdd(map: Map)

Should contain code that creates DOM elements for the overlay, adds them to map panes where they should belong and puts listeners on relevant map events. Called on map.addLayer(layer).

Parameters

public onRemove(map: Map)

Should contain all clean up code that removes the overlay's elements from the DOM and removes listeners previously added in onAdd. Called on map.removeLayer(layer).

Parameters

public once(type: string, fn: (e: L.LeafletEvent) => void, context?: any): FeatureGroup

Parameters

  • type: string
  • fn: (e: L.LeafletEvent) => void
  • context?: any optional

Returns

FeatureGroup

public removeEventListener(type: string, fn?: (e: L.LeafletEvent) => void, context?: any): FeatureGroup

Parameters

  • type: string
  • fn?: (e: L.LeafletEvent) => void optional
  • context?: any optional

Returns

FeatureGroup

public removeEventListener(eventMap?: any, context?: any): FeatureGroup

Parameters

  • eventMap?: any optional
  • context?: any optional

Returns

FeatureGroup

public removeLayer(layer: T in L.LayerGroup<T extends ILayer>): LayerGroup

Removes a given layer from the group.

Parameters

  • layer: T in L.LayerGroup<T extends ILayer>

Returns

LayerGroup

public removeLayer(id: string): LayerGroup

Removes a given layer of the given id from the group.

Parameters

  • id: string

Returns

LayerGroup

public removeLayer(layer: T in L.LayerGroup<T extends ILayer>): LayerGroup

Removes a given layer from the group.

Parameters

  • layer: T in L.LayerGroup<T extends ILayer>

Returns

LayerGroup

public removeLayer(id: string): LayerGroup

Removes a given layer of the given id from the group.

Parameters

  • id: string

Returns

LayerGroup

public resetStyle(layer: Path): GeoJSON

Resets the the given vector layer's style to the original GeoJSON style, useful for resetting style after hover events.

Parameters

Returns

GeoJSON

public setStyle(style: (featureData: any) => any): GeoJSON

Changes styles of GeoJSON vector layers with the given style function.

Parameters

  • style: (featureData: any) => any

Returns

GeoJSON

public toGeoJSON(): any

Returns a GeoJSON representation of the layer group (GeoJSON FeatureCollection).

Returns

any

public toGeoJSON(): any

Returns a GeoJSON representation of the layer group (GeoJSON FeatureCollection).

Returns

any