I would like to show my .kml file in my leaflet map.~

There is a plugin: https://github.com/windycom/leaflet-kml whixh unfortunately doesn't work. It show only a blank map in the coordinates provided. This issue has been risen here: https://github.com/windycom/leaflet-kml/issues/3 where the basic explanation refers to the:

.then( res => response.text() )


const track = new L.KML(kml)

provided in the example:


I have already uploaded my L.KML.js file alongside with the code, which now looks like this:

 // Load kml file
            .then(res => response.text())
            .then(kmltext => {
                // Create new kml overlay
                const parser = new DOMParser();
                const kml = parser.parseFromString(kmltext, 'text/xml');
                const track = new L.KML(kmltext, 'text/xml');

                // Adjust map to show the kml
                const bounds = track.getBounds();

But the blank map comes again. I believe, that the change is minor, although I don't know certainly where. Is anyone able to clarify?

  • Have you tried it with a very simple KML file that you're 100% sure the map can display correctly? If you try that and it doesn't work, then the issue is probably in your leaflet code (and hopefully someone else can help you with that). If that test does work, then you might have a KML file that's too big or complex, or has other issues which prevent it being displayed. If that's the case, please share the KML (or a representative sample) so that we can help debug the KML. – Christiaan Adams Aug 15 at 9:35
  • One thing, that come to mind - the KML can be too heavy I believe. – Mariusz Krukar Aug 19 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.