makinacorpus / Leaflet.FileLayer

Loads files locally (GeoJSON, KML, GPX) as layers using HTML5 File API
http://makinacorpus.github.io/Leaflet.FileLayer/
MIT License
271 stars 91 forks source link

Declaring the local file #55

Open tardigrde opened 6 years ago

tardigrde commented 6 years ago

Where do I declare which file to load as a layer? So I don't see a part of code in the usage where I can declare that I want to display this and this .geojson as a map layer.. Can somebody help?

leplatrem commented 6 years ago

This plugin is not meant to load one your files to everyone visiting your map. Instead it allows users to browse their local files and load them on their map.

To load one of your files to the map, you don't need this plugin. Something like that (totally untested) would be enough:

fetch('yourgeojson.json')
  .then(resp => resp.json())
  .then(data => {
    L.geoJSON(data).addTo(map);
  })

or with modern JavaScript:

async function loadGeoJSON(map) {
  const resp = await fetch('yourgeojson.json');
  const data = await resp.json()
  L.geoJSON(data).addTo(map);
}