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.AutoLayers

v0.2.0

Published

A dynamic leaflet layers control that pulls from multiple mapservers and manages basemaps and overlays plus their order.

Downloads

5

Readme

Leaflet.AutoLayers

A dynamic leaflet layers control that pulls from multiple mapservers and manages basemaps and overlays plus their order.

Getting Started

See this demo page for a full example or this barebones demonstration of the simpliest way to configure the plugin.

New! WMS support! Huzzah! Splits the WMS layers up for you so that you can turn them off/on and declare basemaps, automatically pulls layers. See this demo for an example.

Configuration Breakdown

The configuration is an object that is passed in as the first signature on the method call (L.control.autolayers()). The second is the standard Layers options object which is optional.

List of possible configuration keys:

  • overlays: OPTIONAL - standard built control layers object as built statically here
  • baseLayers: OPTIONAL - standard built control layers object as built statically here
  • selectedBasemap: RECOMMENDED - determines which baselayer gets selected first by layer 'name'
  • selectedOverlays: OPTIONAL - determines which overlays are auto-selected on load
  • mapServers: OPTIONAL - but this is kind of the whole point of this plugin
    • url: REQUIRED - the base url of the service (e.g. http://services.arcgisonline.com/arcgis/rest/services)
    • baseLayers: RECOMMENDED - tells the control what layers to place in base maps, else all from this server go into overlays
    • dictionary: REQUIRED - where the published service list dictionary is (e.g. http://services.arcgisonline.com/arcgis/rest/services?f=pjson)
    • tileUrl: REQUIRED - (EXCEPT WMS) - the part that comes after the layer name in the tileserver with xyz coords placeholders (e.g. /MapServer/tile/{z}/{y}/{x} or /{z}/{x}/{y}.png)
    • name: REQUIRED - the name of the server, or however you want to identify the source
    • type: REQUIRED - current options: esri or nrltileserver
    • whitelist: OPTIONAL - ONLY display these layers, matches against both baselayers and overlays. Do not use with blacklist.
    • blacklist: OPTIONAL - DO NOT display these layers, matches against both baselayers and overlays. Do not use with whitelist.

Prerequisities

  1. A recent browser (IE 10 or later, Firefox, Safari, Chrome etc)
  2. Leaflet mapping library

That's it! It has its own built in ajax and comes bundled with x2js, you can drop both of these for your own with some slight modifications.

Installing

  1. Clone
  2. Include leaflet-autolayers.js and the accompanying css/images in your project where appropriate
  3. Create your configuration and place L.control.autolayers(config).addTo(map) where you have your map implemented
  4. And that's it!

Sample Configuration that pulls from the public ArcGIS and Navy Research Labs tileservers:

 var config = {
        overlays: overlays, //custom overlays group that are static
        baseLayers: baseLayers, //custom baselayers group that are static
        selectedBasemap: 'Streets', //selected basemap when it loads
        selectedOverlays: ["ASTER Digital Elevation Model 30M", "ASTER Digital Elevation Model Color 30M", "Cities"], //which overlays should be on by default
        mapServers: [{
            "url": "http://services.arcgisonline.com/arcgis/rest/services",
            "dictionary": "http://services.arcgisonline.com/arcgis/rest/services?f=pjson",
            "tileUrl": "/MapServer/tile/{z}/{y}/{x}",
            "name": "ArcGIS Online",
            "type": "esri",
            "baseLayers": ["ESRI_Imagery_World_2D", "ESRI_StreetMap_World_2D", "NGS_Topo_US_2D"],
            "whitelist": ["ESRI_Imagery_World_2D", "ESRI_StreetMap_World_2D", "NGS_Topo_US_2D"]
        }, {
            "url": "http://geoint.nrlssc.navy.mil/nrltileserver",
            "dictionary": "http://geoint.nrlssc.navy.mil/nrltileserver/wms?REQUEST=GetCapabilities&VERSION=1.1.1&SERVICE=WMS",
            "tileUrl": "/{z}/{x}/{y}.png",
            "name": "Navy NRL",
            "type": "nrltileserver",
            "baseLayers": ["bluemarble", "Landsat7", "DTED0_GRID_COLOR1", "ETOPO1_COLOR1", "NAIP", "DRG_AUTO"],
            "blacklist": ["BlackMarble"]
        }]
    };

Deployment

Make sure all your layers you include are of the same projection. Currently map projection redrawing based on baselayer is not implemented, so if you don't have matching layer projections, things will not line up properly.

Contributing

Contributions, especially for other map servers or enhancements welcome.

Versioning

For now it's going to remain in beta until the Leaflet 1.0.0 release. After that time a standard version 1.x will begin.

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments