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

offline-leaflet-map

v0.4.0

Published

A Leaflet TileLayer with offline capabilities.

Downloads

21

Readme

offline-leaflet-map

offline-leaflet-map makes it possible to save portions of leaflet maps and consult them offline. It uses either IndexedDB or Web SQL to store the images.

##OfflineLayer The OfflineLayer inherits the leaflet TileLayer. If no dbOption is specified, it will behave like a basic TileLayer.

Initialization:

It is initialized the same way, using url and options but it has extra options:

  • onReady: All db operations are asynch, onReady will be called when the DB is ready and tile images can be retrieved.
  • dbOption: Can choose storage by setting to "WebSQL" or "IndexedDB". "None" or null will not use any DB.
  • onError(optional): Will be called if anything goes wrong with (errorType, errorData), more details in Errors section.
  • storeName(optional): If you ever need to change the default storeName: "OfflineLeafletTileImages".

Methods:

  • saveTiles(zoomLevelLimit, onStarted, onSuccess, onError): saves all the tiles currently present in the screen + all tiles under these (bigger zoom) + all tiles containing the tiles (smaller zoom) The idea is to make it possible to zoom in but also to locate your saved data from a lower zoom level when working offline. zoomLevelLimit will limit the zoom depth.

  • calculateNbTiles(zoomLevelLimit): An important function that will tell you how many tiles would be saved by a call to saveTiles. Make sure to call this function and limit any call to saveTiles() if you want to avoid saving millions of tiles. zoomLevelLimit will limit the zoom depth.

  • isBusy(): It is currently not possible to call saveTiles or clearTiles if OfflineLayer is busy saving tiles.

  • cancel(): This will skip the saving for all the files currently in the queue. You still have to wait for it to be done before calling saveTiles again.

  • clearTiles(): Clear the DB store used for storing images.

Events:

OfflineLayer fires the following events while saving tiles:

  • 'tilecachingstart': fired when just starting to save tiles. Until the 'tilecachingprogressstart' is fired, it is not safe to display information about the progression since it's both saving images and going through the DB looking for already present images.
  • 'tilecachingprogressstart': at this point, the total number of images that still need to be saved is known.
  • 'tilecachingprogress': fired after each image is saved.
  • 'tilecachingprogressdone': fired when all images have been saved and the OfflineLayer is ready to save more.

##Error callback:

When calling the onError callback, the parameters are (errorType, errorData)

new OfflineLayer errors:

  • "COULD_NOT_CREATE_DB": An error has been thrown when creating the DB (calling new IDBStore internally). errorData is the error thrown by the IDBStore.
  • "NO_DB": Calling clearTiles() or saveTiles() will doing nothing but call the error callback if there is no DB. This could happen if these functions are called before the onReady callback or if the DB could not be initialized (previous error).
  • "COULD_NOT_CREATE_DB": Could not create DB.

saveTiles() errors:

  • "SYSTEM_BUSY": System is busy.
  • "SAVING_TILES": An error occurred when calling saveTiles.
  • "DB_GET": An error occurred when calling get on ImageStore. errorData is the DB key of the tile.
  • "GET_STATUS_ERROR": The XMLHttpRequest Get status is not equal to 200. errorData contains the error from XMLHttpRequest and the URL of the image.
  • "NETWORK_ERROR": The XMLHttpRequest used to get an image threw an error. errorData contains the error from XMLHttpRequest and the URL of the image.

clearTiles() errors:

  • "SYSTEM_BUSY": System is busy.
  • "COULD_NOT_CLEAR_DB": Could not clear DB.

##Example

Look at src/demo.coffee for a complete example of how to use OfflineLayer and a basic progression control example.