Giter VIP home page Giter VIP logo

leaflet-tilelayer-mbtiles-ts's Introduction

This is an updated version of the typescript version of Max Battcher here This version adds OS platform detection to make it compatible with iOS and Android, since fetch didn't support File URI Schema see..

Leaflet.TileLayer.MBTiles

A LeafletJS plugin to load tilesets in .mbtiles format.

Exemple

The following demo loads a ~9.6MB .mbtiles file with the "countries" style from the good ol' Tilemill:

Compatibility

LeafletJS 1.0.1 (or newer), sql.js 0.5.0 and a web browser that supports:

Any recent version of Firefox, Chrome or Safari should work without problems. IE10/IE11 should work with a fetch polyfill.

Usage

npm i leaflet leaflet-tilelayer-mbtiles-ts --save

Include Leaflet like:

<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
declare var L: any;

or like :

import * as L from 'leaflet';

or like :

import 'leaflet';
declare var L: any;

Then include Leaflet.TileLayer.MBTiles, like:

import 'leaflet-tilelayer-mbtiles-ts';

Once everything is loaded, you can instantiate L.TileLayer.MBTiles just by providing the URL to a .mbtiles database:

const mb = L.tileLayer.mbTiles('http://server/something/cool-stuff.mbtiles').addTo(map);

Extra metadata handling

Some .mbtiles have metadata rows which is not in the specification .mbtiles format. This plugin will handle the following optional metadata rows, if they exist:

  • minzoom (as the layer's minzoom option).
  • maxzoom (as the layer's maxzoom option).
  • attribution (as the layer's attribution option).

Due to the database being opened asynchronously, and the fact that layer options have to be given when the layer is instantiated, metadata handling does not work very well. Consider handling the metadata manually and setting Leaflet layer options accordingly.

Legalese


"THE BEER-WARE LICENSE": [email protected] wrote this file. As long as you retain this notice you can do whatever you want with this stuff. If we meet some day, and you think this stuff is worth it, you can buy me a beer in return.


leaflet-tilelayer-mbtiles-ts's People

Contributors

0nza1101 avatar dependabot[bot] 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.