Get bounds of featureGroup with multiple features

by Dixos   Last Updated April 25, 2018 16:22 PM

I tried looking into a solution for this myself, or an alternative way to load my layers, but I'm simply unable to.

Right now I load a geoJSON file through L.GeoJSON.AJAX(), then add the features (polylines and markers) that I need to a L.featureGroup(), but I'm having issues using the featureGroup.getBounds() function when doing this.

How can I get the bounds of all the features added to a featureGroup like this?

Edit: Added code. Completely slipped my mind when asking the question to include this.

function addMapData(id, map) {
  var newIcon = L.icon({
    iconUrl: './img/icons/ring.png',
    iconSize: [84, 80],
    iconAnchor: [5, 70],
    popupAnchor: [10, 10],

  var mapData = L.featureGroup();

  new L.GeoJSON.AJAX('./data/fjelltrimmen/fjelltrimmen.vefsn.geojson', {
    local: true,
    style: {
      weight: 5,
      color: '#c0392b',
    onEachFeature: function(feature, layer) {
      if ( === id) {
        // Polyline

        // Map marker
          feature.geometry.coordinates[feature.geometry.coordinates.length - 1][1],
          feature.geometry.coordinates[feature.geometry.coordinates.length - 1][0],
        ], { icon: newIcon }).addTo(mapData);


Related Questions

Looking for world maritime boundaries in Geojson

Updated January 08, 2018 16:22 PM

European postal code shapes provider

Updated February 26, 2017 17:22 PM