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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ngx.leaflet.offline

v1.1.2

Published

A Leaflet library that downloads map tiles and uses them offline.

Readme

ngx.leaflet.offline License: GPLv2 npm version

A Leaflet library that downloads map tiles and uses them offline. Check out the demo at https://betoxl.github.io/ngx.leaflet.offline/index.html .

Example: https://github.com/BETOXL/offlinemap-angular-example

@types https://www.npmjs.com/package/@types/ngx.leaflet.offline

Inspiration

This library was heavily inspired and based on the leaflet.offline library by Allart Kooiman. I decided to create a new one because the ideas I had were diverging too much from what leaflet.offline proposes to do.

The biggest change I made was removing the dependency on localForage and introducing a new parameter that makes you able to give your own implementantion of a database layer to save, retrieve and delete the map tiles however you like as long as it implements the same interface (more on that below).

Dependencies

Install

If you use npm, you can install ngx.leaflet.offline by running: npm install ngx.leaflet.offline

If you don't use a package manager, simply download a file from the dist/ folder and include it in your application.

Guide

Database Layer

When creating both the OfflineControl and the OfflineLayer, you need to pass an object that will act as the database layer when saving, retrieving and deleting map tiles. The object must implement the following interface.

| Method | Parameters | Returns | | ----------- | --------------- | --------------------------------------------------------------------------------------------- | | 'getItem' | key: String | Promise. The result of the promise must be a Blob, File or MediaStream representing the image | | 'saveTiles' | tileUrls: Array | Promise. The result is ignored | | 'clear' | None | Promise. The result is ignored |

Layer API

When creating the OfflineLayer, you need to pass the URL from where the map tiles will be retrieved, the database layer object and the options parameter. There are no special options for the OfflineLayer, they are the same as the TileLayer options from Leaflet.

Control API

When creating the OfflineControl, you need to pass the OfflineLayer, the database layer object and the options parameter. The options parameter is defined as follows:

| Option | Type | Default | Description | | ------------------------ | -------- | -------------- | ---------------------------------------------------------------------------------- | | 'position' | String | 'topleft' | Control options | | 'saveButtonHtml' | String | 'S' | The HTML that will be displayed as the save button | | 'saveButtonTitle' | String | 'Save tiles' | The title that will be used for the save button | | 'removeButtonHtml' | String | 'R' | The HTML that will be displayed as the remove button | | 'removeButtonTitle' | String | 'Remove tiles' | The title that will be used for the remove button | | 'minZoom' | Number | 0 | The save operation won't start when trying to save map tiles below this zoom level | | 'maxZoom' | Number | 19 | The save operation will not save map tiles beyond this zoom level | | 'confirmSavingCallback' | Function | null | A function to be executed before the save operation starts | | 'confirmRemovalCallback' | Function | null | A function to be executed before the remove operation starts |

The callbacks should implement the following interface.

| Method | Parameters | Returns | | ------------------------- | ------------------------------------------------- | ---------------------------------------------------------------------------- | | 'confirmSavingCallback' | nTilesToSave: Number, continueSaveTiles: Function | Whatever. Remember to call continueSaveTiles to resume the operation | | 'confirmRemovalCallback' | continueRemoveTiles: Function | Whatever. Remember to call continueRemoveTiles to resume the operation |

Events

Events fired by the OfflineControl on the OfflineLayer. Assume that tilesDb is the database layer object.

| Event | Data | Description | | ------------------------------ | ---------------------- | ------------------------------------------------------------------------------- | | 'offline:below-min-zoom-error' | undefined | Fired when trying to save below minimum zoom level | | 'offline:save-start' | {nTilesToSave: Number} | Fired when the save operation starts but before calling tilesDb.saveTiles | | 'offline:save-end' | undefined | Fired when the promise from tilesDb.saveTiles finishes successfully | | 'offline:save-error' | {error: Error} | Fired when the promise from tilesDb.saveTiles finishes with an error | | 'offline:remove-start' | undefined | Fired when the remove operation starts but before calling tilesDb.clear | | 'offline:remove-end' | undefined | Fired when the promise from tilesDb.clear finishes successfully | | 'offline:remove-error' | {error: Error} | Fired when the promise from tilesDb.clear finishes with an error |

Example

Creating the database layer object.

var tilesDb = {
    getItem: function (key) {
        // return Promise that has the image Blob/File/Stream.
    },

    saveTiles: function (tileUrls) {
        // return Promise.
    },

    clear: function () {
        // return Promise.
    }
};

Creating the OfflineLayer.

var map = L.map('map-id');
var offlineLayer = L.tileLayer.offline('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', tilesDb, {
    attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
    subdomains: 'abc',
    minZoom: 13,
    maxZoom: 19,
    crossOrigin: true
});

Creating the OfflineControl.

var offlineControl = L.control.offline(offlineLayer, tilesDb, {
    saveButtonHtml: '<i class="fa fa-download" aria-hidden="true"></i>',
    removeButtonHtml: '<i class="fa fa-trash" aria-hidden="true"></i>',
    confirmSavingCallback: function (nTilesToSave, continueSaveTiles) {
        if (window.confirm('Save ' + nTilesToSave + '?')) {
            continueSaveTiles();
        }
    },
    confirmRemovalCallback: function (continueRemoveTiles) {
        if (window.confirm('Remove all the tiles?')) {
            continueRemoveTiles();
        }
    },
    minZoom: 13,
    maxZoom: 19
});

Adding both of them to the map.

offlineLayer.addTo(map);
offlineControl.addTo(map);

For a more complete example, check the demo code inside the gh-pages branch.