Skip to content

GeoJSON

Represents a GeoJSON object or an array of GeoJSON objects. Allows you to parse GeoJSON data and display it on the map. Extends FeatureGroup.

Usage example

js
new GeoJSON(data, {
style: function (feature) {
return {color: feature.properties.color};
}
}).bindPopup(function (layer) {
return layer.feature.properties.description;
}).addTo(map);

Methods

MethodReturnsDescription
geometryToLayer(featureData: Object, options?: GeoJSON options)LayerCreates a Layer from a given GeoJSON feature. Can use a custom
coordsToLatLng(coords: Array)LatLngCreates a LatLng object from an array of 2 numbers (longitude, latitude)
coordsToLatLngs(coords: Array, levelsDeep?: Number, coordsToLatLng?: Function)ArrayCreates a multidimensional array of LatLngs from a GeoJSON coordinates array.
`latLngToCoords(latlng: LatLng, precision?: Numberfalse)`Array
`latLngsToCoords(latlngs: Array, levelsDeep?: Number, close?: Boolean, precision?: Numberfalse)`Array
getFeature(layer: Layer, newGeometry: Object)ObjectReturns GeoJSON geometries/features of layer with new GeoJSON geometry.
asFeature(geojson: Object)ObjectNormalize GeoJSON geometries/features into GeoJSON features.