Leaflet.FileLayer icon indicating copy to clipboard operation
Leaflet.FileLayer copied to clipboard

Declaring the local file

Open tardigrde opened this issue 7 years ago • 1 comments

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?

tardigrde avatar Jan 10 '18 20:01 tardigrde

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);
}

leplatrem avatar Jan 11 '18 15:01 leplatrem