GithubHelp home page GithubHelp logo

emergenzehack / offline-leaflet-map Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mwater/offline-leaflet-map

0.0 4.0 0.0 616 KB

Offline maps in Leaflet using IndexedDb to store tiles

CSS 6.29% JavaScript 69.14% CoffeeScript 24.56%

offline-leaflet-map's Introduction

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.

offline-leaflet-map's People

Contributors

mbriau avatar grassick avatar

Watchers

Andrea Borruso avatar James Cloos avatar Stefano avatar Iltempe avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.