Skip to content

Leaflet tile layer with functionally defined URL and support for jQuery deferreds.

License

Notifications You must be signed in to change notification settings

jbumueller/Leaflet.functionaltilelayer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Leaflet.functionaltilelayer

Leaflet tile layer with functionally defined URL and support for jQuery deferreds.

A typical use case is fetching tiles asynchronously, with an ajax request or IndexedDB query.

Does not require jQuery, unless you are using the deferred functionality

Usage

Use it like any other tile layer, but instead of providing a urlTemplate as the first argument, provide a function. The function should return either the tile URL as a string, or a deferred object which resolves to a string.

var funcLayer = new L.TileLayer.Functional(function (view) {
    var url = 'http://otile{3}.mqcdn.com/tiles/1.0.0/map/{0}/{1}/{2}.jpg'
        .replace('{0}', view.zoom)
        .replace('{1}', view.tile.row)
        .replace('{2}', view.tile.column)
        .replace('{3}', view.subdomain);
    
    return url;
});

The function is given a view object with the following properties:

view = {
  bbox,
  width,
  height,
  zoom,
  tile: {
    row,
    column
  },
  subdomain
};

For an example of the code above, see the [basic example] (http://ismyrnow.github.com/Leaflet.functionaltilelayer/example/basic.html).

A more useful example, which demonstrates the deferred functionality, can be seen [here] (http://jsfiddle.net/ismyrnow/LbSpp/).

Thanks

Thanks to @ryanttb and jQuery Geo's service objects, which were the inspiration for this plugin.

License

Leaflet.functionaltilelayer is free software, and may be redistributed under the MIT-LICENSE.

About

Leaflet tile layer with functionally defined URL and support for jQuery deferreds.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published