An open API service indexing awesome lists of open source software.

https://github.com/windycom/leaflet-kml

🌎Leaflet KML layer plugin
https://github.com/windycom/leaflet-kml

Last synced: 11 months ago
JSON representation

🌎Leaflet KML layer plugin

Awesome Lists containing this project

README

          

# Leaflet KML layer plugin

![Example](assets/screenshot.jpg)

Demo: https://www.windy.com/uploader

This plugin was extracted from Pavel Shramov's Leaflet Plugins [repository](https://github.com/shramov/leaflet-plugins) in order to maintain this code more frequently and separate KML layer from other plugins.

So far we have fixed few issues.

Probably will work on Leaflet 1+, tested on Leaflet 1.4.

## How to use

```html









// Make basemap
const map = new L.Map('map', { center: new L.LatLng(58.4, 43.0), zoom: 11 });
const osm = new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png');

map.addLayer(osm);

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

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

```

## Licence

MIT