GithubHelp home page GithubHelp logo

zhangweiabc / leaflet.functionaltilelayer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ismyrnow/leaflet.functionaltilelayer

0.0 0.0 0.0 253 KB

Leaflet tile layer with functionally defined URL and support for promises.

License: MIT License

HTML 56.71% JavaScript 43.29%

leaflet.functionaltilelayer's Introduction

Leaflet.functionaltilelayer

Leaflet tile layer with functionally defined URL and support for promises.

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

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 promise 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).

For an example of using promises, see the [promise example] (http://ismyrnow.github.com/Leaflet.functionaltilelayer/example/promise.html).

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.

leaflet.functionaltilelayer's People

Contributors

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