Atlaslog
Atlaslog / Leaflet / API reference / GeoJSON
Leaflet · API reference

GeoJSON

Quick answer

L.geoJSON turns GeoJSON feature collections into Leaflet layers, inheriting every FeatureGroup capability plus pointToLayer, style, filter and onEachFeature hooks. It is the standard way to load vector data and to export it back with toGeoJSON at a chosen precision. Each generated child layer is reachable through eachLayer and getLayers.

Last verified 2026-11-03 · Leaflet 1.9.4 · Cite this page
L.geoJSON( geojson? , options? ) → GeoJSON
Key points
Example
var layer = L.geoJSON(data, {
  pointToLayer: function (feature, latlng) {
    return L.circleMarker(latlng, { radius: 6, fillOpacity: 0.9 });
  },
  style: function (feature) {
    return { color: '#1f5fd0', weight: 2, fillOpacity: 0.2 };
  },
  onEachFeature: function (feature, lyr) {
    lyr.bindPopup(feature.properties.name);
  }
}).addTo(map);

layer.addData({
  type: 'Feature',
  properties: { name: '新增点' },
  geometry: { type: 'Point', coordinates: [116.41, 39.91] }
});
layer.eachLayer(function (lyr) {
  lyr.on('click', function () {
    layer.eachLayer(function (other) { layer.resetStyle(other); });
    lyr.setStyle({ color: '#c2410c', weight: 3 });
  });
});
Notes
Runnable examplesChinese originalAll API references
English edition written for Atlaslog. Code is taken from the original Chinese page and runs unchanged.
Cite this page

Atlaslog (2026). GeoJSON. https://www.jingweizhi.com/en/leaflet/api/geojson.html (accessed 2026-11-03).