Giter Club home page Giter Club logo

leaflet.offline's Introduction

leaflet.offline

Just a modern and slim library to store image and vector tiles offline. Easy to use in your existing projects. Take a look in the example folder and see how it works, or head to http://allartk.github.io/leaflet.offline/!

Dependencies

Install

Manual or Clone

Just use one of github's download methods (look under the releasestab ) and add dist/leaflet.offline.min.js in a script tag to your page (after leaflet and localforage)

With npm

The package and it's dependencies can also be downloaded into your existing project with npm:

npm install leaflet.offline

I encourage you to a bundler like browserify to bundle all files (localforage, this script and any other you use) into one. Require the offline script like this:

require('leaflet.offline');

Leaflet is expected to be global var L

Run example

For running the example, you'll need to clone the project and have gulp globally installed. Then, from the project root run and visit http://localhost:8080/:

npm install
gulp example

Api

L.control.savetiles

Show control buttons to saves tiles.

L.control.savetiles options

First arg of constructor is layer object to save, second is object of all optional options:

  • zoomlevels: array of integers, default current zoomlevel
  • position: position of the control default 'topleft'
  • saveText: html to show on save button
  • rmText: html to show on remove button
  • maxZoom: maximum zoom level that will be reached when saving tiles with saveWhatYouSee. Default value: 19 (ignored if saveWhatYouSee is false)
  • saveWhatYouSee: saves the tiles that you see on screen plus deeper zoom levels (ignores zoomLevels array if true). This feature won't work when trying to save with zoom below level 5
  • confirm: a function with args layer and a callback function that should be called when user confirms download
  • confirmRemoval: a function with args layer and a callback function that should be called when user confirms removal of tiles

L.control.savetiles methods

  • setlayer: change the layer to save tiles from

L.tileLayer.offline

Extends and has the same options as L.TileLayer. It uses offline tiles when available and falls back to online if not. If configured to use subdomains, the key used to store has the first defined subdomain. The tileserver should server the tiles with a Access-Control-Allow-Origin header.

L.control.savetiles Events

The following events are fired by the control on the layer while saving tiles:

  • savestart, start downloading tiles
  • loadtileend, a tile is downloaded (eg show progress bar)
  • savetileend, one tile is saved (eg show progress bar)
  • loadend, all tiles are downloaded
  • tilesremoved, all tiles are removed
  • saveend
  • storagesize files saved in total for all layers

Each event object has the following properties:

  • storagesize int
  • lengthToBeSaved int
  • lengthSaved int
  • lengthLoaded int
  • _tilesforSave array of objects

L.VectorGrid.Protobuf.Offline

Work in progress

Update from older release

Release 0.1 will use Leaflet 1.0.x, the argument for the confirm option changed in this release.

Release pre 0.1 use leaflet 0.7 (and other extra dependencies, see readme)

Example

The layer:

var baseLayer =  L.tileLayer.offline('http://tiles.example.nl/tiles/tiles.py/mq_proxy/{z}/{x}/{y}.jpg',
      {
          attribution:
                  'Tiles Courtesy of <a href="http://www.mapquest.com/">MapQuest</a> &mdash; ' +
                  'Map data {attribution.OpenStreetMap}',
          subdomains: '1234',
          minZoom: 13
      }
).addTo(map);

The control:

L.control.savetiles(baseLayer,{
  'zoomlevels':[13,16] //optional zoomlevels to save tiles for, default current zoomlevel
    }
).addTo(map);

Develop

Use gulp tasks. Also make sure you use eslint in your editor.

leaflet.offline's People

Contributors

allartk avatar robertomlsoares avatar

Watchers

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