Skip to content

George-Madeley/leaflet-vector-offline

Repository files navigation

Leaflet Vector Offline

Vector tile rendering for Leaflet with support for offline use.

npm

About

Based on propmaps-leaflet and leaflet.offline, this packge gives the ability to render vector tiles on a Leaflet.js map from online and offline sources.

Features

  • Render vector tile maps with Leaflet integration.
  • Supports reading Z/X/Y tile URLs or PMTiles format.
  • Ability to download all tiles within view port at selected zoom levels and store them in the cache.
  • Ability to choose to use on online, cache, or both tile sources.

Dependencies

How to use

To install Leaflet Vector Offline with npm, use the following command:

npm install leaflet-vector-offline

or with yarn:

yarn add leaflet-vector-offline

To use Leaflet Vector Offline, use the following code:

const map: Map = L.map("map");
const url: string = "https://<YourUrlGoesHere>/{z}/{x}/{y}.mvt";
const attribution: string: "";
const vectorLayer: VectorOfflineLayer = vectorOfflineLayer(url, {
  attribution,
  subdomains: "abc",
  minZoom: minZoom,
  maxZoom: maxZoom,
  theme: "light",
});
vectorLayer.addTo(map);

See