Leaflet-omnivore load multiple KMLs & center

by George   Last Updated January 14, 2018 01:22 AM

I'm new with leaflet-omnivore and looking for the optimal way to load a number of KMLs (each of them containing a polygon) and center the map in their "bounds"

I have tried adding the loaded polygons to a feature group and then try to get the bounds of that in order to center the map. The polygons are showing on the map successfully but the map does not zoom/center

    var polygonGroup = new L.FeatureGroup();            

    // Load kml and add to feature group
    $.each(kmls, function (i, kmlUrl) {
        var polygonLayer = omnivore.kml(kmlUrl);
        polygonGroup.addLayer(polygonLayer);
    });

    // Add group to map
    map.addLayer(polygonGroup);

    // Attempt to center map
    map.fitBounds(polygonGroup.getBounds());`


Related Questions



Need to highlight required area using leaflet

Updated February 18, 2016 08:09 AM


Is it possible to use Leaflet.draw on a map in R?

Updated February 29, 2016 05:09 AM

How to export to all points within Leaflet polygon?

Updated April 22, 2015 03:09 AM