• Stars
    star
    137
  • Rank 266,121 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple loading control for Leaflet

Leaflet.loading

Leaflet.loading is a simple loading control for Leaflet. An unobtrusive loading indicator is added below the zoom control if one exists. The indicator is visible when tiles are loading or when other data is loading, as indicated by firing custom events on a map. The indicator can be an image, or a spin.js spinner (image-less).

Usage

Leaflet.loading is only tested on Leaflet version 0.6 or greater. It will almost certainly not work with older versions of Leaflet. Of course we intend to support Leaflet 1.0, and we have tested against the latest release (beta 2). Please create an issue if you find that any part of this project is not compatible with Leaflet 1.0.

Include Control.Loading.js and Control.Loading.css, then create a map with loadingControl: true in its options.

By default, Leaflet.loading includes a base64-encoded animagted loading image in Control.Loading.css. You can customize this by changing background-image for the selector .leaflet-control-loading. The simplest case would be adding a 16 x 16 loading gif in .leaflet-control-loading.

You can also set spinjs: true in the options, and load spin.js to use that instead of an image. A spin.js options object can be passed as the spin key when initializing the control.

Whichever method you use, make sure you only use one.

Once the above is complete you will have a loading indicator that only appears when tiles are loading.

If you want to show the loading indicator while other AJAX requests or something else is occurring, fire the dataloading event on your map when you begin loading and dataload when you are finished loading. Please note that there is an issue with the way this control tracks these events and that this will be re-worked in a future version.

Options

  • position: (string) Where you want the control to show up on the map (standard Leaflet control option). Optional, defaults to topleft

  • separate: (boolean) Whether the control should be separate from the zoom control or not, defaults to false.

  • zoomControl: (L.Control.Zoom) The zoom control that the control should be added to. This is only necessary when adding a loading control to a zoom control that you added manually and do not want a separate loading control.

  • delayIndicator: (float) The number of milliseconds to wait before showing the loading indicator. Defaults to null (no delay).

  • spinjs: (boolean) Enable the use of spin.js. Optional, defaults to false

  • spin: (object) A spin.js options object. Optional, defaults to

    {
        lines: 7,
        length: 3,
        width: 3,
        radius: 5,
        rotate: 13,
        top: "83%"
    }
    

Usage with react-leaflet

  1. npm install leaflet-loading.
  2. Add import "leaflet-loading"; to the file containing MapContainer.
  3. Add @import "~leaflet-loading/src/Control.Loading.css" to index.scss.
  4. Add loadingControl={true} to <MapContainer> props.

If you're using TypeScript you will get an error:

Property 'loadingControl' does not exist on type 'IntrinsicAttributes & MapContainerProps'.  TS2322

Until react-leaflet#847 is fixed you can work around with @ts-ignore, eg:

<MapContainer
  // @ts-ignore
  loadingControl={true}
>

Demos

See Leaflet.loading in action (zoom or pan to make tiles load):

License

Leaflet.loading is free software, and may be redistributed under the MIT License.

More Repositories

1

Leaflet.snogylop

A Leaflet plugin that inverts polygons
JavaScript
61
star
2

projestions

projection suggestions
JavaScript
16
star
3

596acres

596 Acres, a public vacant lot viewer for New York City
Python
14
star
4

cartodb-export

Export and backup visualizations from CartoDB
JavaScript
9
star
5

v2v

Vacant to Vibrant, a vacant lot viewer for Philadelphia
Python
8
star
6

cartocss2json

A node module for converting CartoCSS to JSON
JavaScript
7
star
7

Leaflet.handlebars

Leaflet with Handlebars-templated popups
JavaScript
5
star
8

Farming-Concrete

Apps and configuration for Farming Concrete
Python
5
star
9

cartocss2leaflet

Convert CartoCSS styles to Leaflet styles
JavaScript
4
star
10

leaflet-geojson-gridlayer

Vector GeoJSON tiles for Leaflet 1.0
JavaScript
3
star
11

qgis-projestions

QGIS plugin for projestions
JavaScript
3
star
12

pygeoexif

Simply get latitude and longitude from an image's EXIF data
Python
3
star
13

geojson-examples

GeoJSON examples
3
star
14

history-of-collecting-map

JavaScript
3
star
15

django-inplace

A set of helpers for writing place-based applications with GeoDjango.
Python
2
star
16

django-phillydata

A set of Django apps for loading and storing data provided by or related to the city of Philadelphia.
Python
2
star
17

hep-emp

JavaScript
1
star
18

django-cartodb-sync

A Django app that helps keep CartoDB tables synchronized with Django models
Python
1
star
19

cartodbjs-hoverintent

Hover intent for CartoDB.js
JavaScript
1
star
20

tablespoon-desktop

A desktop client for tablespoon
JavaScript
1
star
21

picnic

HTML
1
star
22

jekyll-map

An example of a map that uses Jekyll for feature content
CSS
1
star
23

carto-opendata

HTML
1
star
24

maps-20170208

Slides for a mapping workshop
HTML
1
star
25

cas_food

JavaScript
1
star
26

tablespoon-load

Convert various filetypes to JSON for tablespoon
JavaScript
1
star
27

Leaflet.jsonstyles

Advanced Leaflet GeoJSON styling with JSON objects
JavaScript
1
star
28

feincms-pagepermissions

A simple FeinCMS extension that adds permission-checking to a model
Python
1
star
29

visaweek

HTML
1
star
30

uc_buyingclub

A Drupal module for use with Ubercart for running a food buying club, currently being used at Greene Hill Food Co-op in Brooklyn.
PHP
1
star
31

qgis-style

Slides on styling vector data with QGIS
HTML
1
star