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-advanced-layer-system

v2.2.10

Published

An advanced layer system and more for Leaflet

Downloads

56

Readme

Advanced Layer System (ALS) for Leaflet

Have you ever needed something more than a simple layer switcher? Probably, custom layer types? Multiple interactive layers? Full-blown projects like in big apps? Just a cool menu? ALS got you covered!

Layer system handles hard stuff like managing layers, hacking Leaflet, struggling with UI and everything else. You're left to focus only on your app's functionality.

Features:

  1. A layer system which allows you to create custom layer types and allows users to add those layers to the map. Users can add, delete, move, hide and tweak layers.
  2. Project management done by serialization. Projects can be exported as GeoJSON files. Yup, like in GIS.
  3. A simple menu which uses single layer type and doesn't feature all the advanced stuff.
  4. A widget library. Moreover, you can add widgets to the map!
  5. Extras: wizards, settings, localization, Electron integration and more!

Sounds cool? See "Getting started" or jump straight to the docs!

Demos

ALS demos - demonstrates all important ALS capabilities and provides the source code for all demos.

SynthFlight - aerial photography planning software which uses ALS. Well, initially, ALS has been developed for SynthFlight :D

Docs

Getting started

Adding a dependency

Run npm i leaflet-advanced-layer-system.

Importing ALS

In your index.html add following stuff to the <head> after Leaflet's scripts and CSS:

<!-- ALS CSS. Must go before scripts. -->
<link rel="stylesheet" href="css/base.css" />

<!-- ALS scripts. Put in exact same order. -->
<script src="node_modules/leaflet-advanced-layer-system/dist/polyfills.js"></script> <!-- Polyfills -->
<script src="node_modules/leaflet-advanced-layer-system/dist/System.js"></script> <!-- ALS entry point. Alternatively, you can import it in your main script -->

Warning: Polyfills should NEVER be transformed by anything! You still can require() them, but it's better to leave them in your HTML and ignore in your build script.

Setting up a project

Add following code to your entry point:

require("leaflet-advanced-layer-system"); // Require this plugin or add it to your .html page via "script" tag as has been shown above
require("./MyLayer.js"); // Require your layer types and other stuff

L.ALS.System.initializeSystem(); // Initialize system. This method MUST be called after all Leaflet and ALS imports.
let map = L.map("map", { // Create a map
    preferCanvas: true, // Use it to improve performance
    keyboard: false // Setting this option to false is a MANDATORY! If you don't do that, you'll encounter problems when using L.ALS.LeafletLayers.WidgetLayer!
});
let layerSystem = new L.ALS.System(map, { /* Options */ }); // Create an instance of this class
let baseLayer = L.tileLayer(/* ... */); // Create some base layers
layerSystem.addBaseLayer(baseLayer, "My Base Layer"); // Add your base layers to the system
layerSystem.addLayerType(L.ALS.MyLayer); // Add your layer types

Then jump to the docs and start coding!

Browser support

ALS supports following browsers:

  • Chrome 8 or later.
  • Firefox 22 or later.
  • Safari 6 or later.
  • Internet Explorer 9 or later.
  • Any other modern desktop or mobile browser.

Known issues with old browsers (~7 years or older) that can't be fixed due to technical reasons:

  • Outdated Chromium-based browsers have a "feature" that prevents FileReader from reading local files. To solve it, you should either:
    • Host your app on a web server.
    • Somehow make your users add --allow-file-access-from-files flag when running browser.
  • Users can't save files, they need to manually copy JSON from the browser to their files.
  • Users can save files, but those files won't have a proper name.
  • IE 9 only: users needs to manually save multiple files when exporting project.
  • IE 9 only: users might be asked to change their settings when they'll try to open a project or import settings. The pop-up window will provide all necessary instructions.
  • Users can't save settings.

You can solve these problems either by removing functionality based on the browser or by providing a backend which will receive the data and send it back to the client, so it will "simulate" a download. ALS provides the callbacks where you can make your requests. See SystemOptions docs for both options.

FAQ

What about learning curve?

Learning curve is a bit steep, but ALS solves much more problems than it adds.

ALS widgets vs modern frameworks with plugins

  1. ALS uses traditional and non-reactive widgets similar to Qt and GTK. Frameworks uses reactive components.
  2. ALS is faster since it uses straightforward DOM manipulation when needed instead of heavy stuff like Virtual DOM. ALS also doesn't need to sync components since it's not reactive.
  3. ALS provides way better browser support than most modern frameworks.
  4. ALS provides a huge set of features that you'll need to implement yourself otherwise.

Can I use my favourite framework instead of built-in widget system?

Technically, yes, but you'll have to pass L.ALS.Widgetable's containers to your framework which is a bit hacky. There will be some more things to do such as serialization.

If you need to just add more widgets, you can do so by extending L.ALS.Widgets.BaseWidget. Otherwise, you're probably better off not using ALS.

What is project file format?

See the docs' home page.

Are any API changes planned?

No, unless they will fix bugs. It also includes some parts returning text instead of locale properties. All such API changes will be documented in release notes.

However, internal (package-scoped and private-scoped) members might be changed in the future, so please, avoid using it. File a bug report or feature request instead.

How can I contribute to the project?

Oh, there's much to add to the project, you can contribute by:

  1. Developing apps using ALS, so they can be added to this ReadMe :D
  2. Coding:
    1. Create more widgets.
    2. Improve browser support.
    3. Provide additional layer types which others can use.
    4. Create examples and tutorials for the docs.
    5. Provide unit tests.
    6. Everything else that comes to your mind.
  3. Localizing ALS.
  4. Improving docs. Note: docs are being generated from the JSDoc comments. Either edit the comments or create an issue and describe what and where needs to be changed.
  5. Reporting bugs.
  6. Requesting features.