npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

leaflet-filelayer

v1.2.0

Published

Loads local files (GeoJSON, GPX, KML) into the map using the HTML5 FileReader API

Downloads

1,873

Readme

Leaflet.FileLayer

Loads local files (GeoJSON, JSON, GPX, KML) into the map using the HTML5 FileReader API, without server call !

  • A simple map control
  • The user can browse a file locally
  • It is read locally (FileReader) and converted to GeoJSON
  • And loaded as a layer eventually!

Check out the demo !

For GPX and KML files, it currently depends on Tom MacWright's togeojson.js.

Build Status

Install

In order to use this plugin in your app you can either:

  • install it via your favorite package manager:
    • npm i leaflet-filelayer
    • bower install git://github.com:makinacorpus/Leaflet.FileLayer.git
  • download the repository and import the leaflet.filelayer.js file in your app.

Dependencies and compatibilities

In order to use this plugin, you need to have both leaflet and togeojson installed. If you're using Leaflet < 1, you need to use the version 0.6.0 of this plugin. After that, Leaflet > 1 is required.

Usage

    var map = L.map('map').fitWorld();
    ...
    L.Control.fileLayerLoad({
        // Allows you to use a customized version of L.geoJson.
        // For example if you are using the Proj4Leaflet leaflet plugin,
        // you can pass L.Proj.geoJson and load the files into the
        // L.Proj.GeoJson instead of the L.geoJson.
        layer: L.geoJson,
        // See http://leafletjs.com/reference.html#geojson-options
        layerOptions: {style: {color:'red'}},
        // Add to map after loading (default: true) ?
        addToMap: true,
        // File size limit in kb (default: 1024) ?
        fileSizeLimit: 1024,
        // Restrict accepted file formats (default: .geojson, .json, .kml, and .gpx) ?
        formats: [
            '.geojson',
            '.kml'
        ]
    }).addTo(map);

Events:

  • data:loaded (event)
    var control = L.Control.fileLayerLoad();
    control.loader.on('data:loaded', function (event) {
        // event.layer gives you access to the layers you just uploaded!

        // Add to map layer switcher
        layerswitcher.addOverlay(event.layer, event.filename);
    });
  • data:error (error)
    var control = L.Control.fileLayerLoad();
    control.loader.on('data:error', function (error) {
        // Do something usefull with the error!
        console,error(error);
    });

Changelog

1.2.0

  • Leaflet 1.2.0 compatibility
  • Accept json file as input (thanks kkdd)

1.1.0

  • Leaflet 1.1.0 compatibility (thanks @thorinii)

0.6.0

  • Better plugin packaging and dependencies
  • Adding bower support (thanks @george-silva)
  • Adding support for custom geoJson layers (thanks @MuellerMatthew)
  • Treating json files as geoJson (thanks @Jmuccigr)

0.5.0

  • Load multiple files (thanks @jens-duttke)

0.4.0

  • Support whitelist for file formats (thanks CJ Cenizal)

0.3.0

  • Add data:error event (thanks @joeybaker)
  • Fix multiple uploads (thanks @joeybaker)
  • Add addToMap option (thanks @joeybaker)

(* Did not release version 0.2 to prevent conflicts with Joey's fork. *)

0.1.0

  • Initial working version

Authors

Makina Corpus

Contributions

  • Mathieu Leplatre
  • Joey Baker http://byjoeybaker.com
  • CJ Cenizal
  • Jens-duttke
  • Jmuccigr
  • Matthew Mueller
  • George Silva
  • Simon Bats
  • Opoto
  • Lachlan Phillips
  • kkdd