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.
L.geoJson(data, {
style: function (feature) {
return {color: feature.properties.color};
},
onEachFeature: function (feature, layer) {
layer.bindPopup(feature.properties.description);
}
}).addTo(map);
Each feature layer created by it gets a feature
property that links to the GeoJSON feature data the layer was created from (so that you can access its properties later).
Creation
Factory |
Description |
L.geoJson(
<Object> geojson?,
<GeoJSON options> options? )
|
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. |
Options
Option |
Description |
pointToLayer(
<GeoJSON> featureData,
<LatLng> latlng )
|
Function that will be used for creating layers for GeoJSON points (if not specified, simple markers will be created). |
style(
<GeoJSON> featureData )
|
Function that will be used to get style options for vector layers created for GeoJSON features. |
onEachFeature(
<GeoJSON> featureData,
<ILayer> layer )
|
Function that will be called on each created feature layer. Useful for attaching events and popups to features. |
filter(
<GeoJSON> featureData,
<ILayer> layer )
|
Function that will be used to decide whether to show a feature or not. |
coordsToLatLng(
<Array> coords )
|
Function that will be used for converting GeoJSON coordinates to LatLng points (if not specified, coords will be assumed to be WGS84 — standard [longitude, latitude] values in degrees). |
Additionally accepts all Path options for polylines and polygons.
Methods
Method |
Returns |
Description |
addData(
<GeoJSON> data )
|
this |
Adds a GeoJSON object to the layer. |
setStyle(
<Function> style )
|
this |
Changes styles of GeoJSON vector layers with the given style function. |
resetStyle(
<Path> layer )
|
this |
Resets the given vector layer's style to the original GeoJSON style, useful for resetting style after hover events. |
Static methods
Method |
Returns |
Description |
geometryToLayer(
<GeoJSON> featureData,
<Function> pointToLayer? )
|
ILayer |
Creates a layer from a given GeoJSON feature. |
coordsToLatLng(
<Array> coords,
<Boolean> reverse? )
|
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). |
coordsToLatLngs(
<Array> coords,
<Number> levelsDeep?,
<Boolean> reverse? )
|
Array |
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). |