npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

leaflet.tilelayer.fallback

v1.0.4

Published

Replaces missing Tiles (404 error) by scaled lower zoom Tiles

Downloads

2,528

Readme

Leaflet.TileLayer.Fallback

Plugin for Leaflet. Replaces missing Tiles (404 error) by scaled lower zoom Tiles.

Leaflet is the leading open-source JavaScript library for mobile-friendly interactive maps.

GitHub releases npm

Size: 2 kB minified, < 1 kB gzipped.

Requirements

Demo

TileLayer.Fallback demonstration page

Usage instructions

Quick Guide

HTML:

<!-- add TileLayer.Fallback script after Leaflet -->
<script src="leaflet.tilelayer.fallback.js"></script>

JavaScript:

var myTileLayer = L.tileLayer.fallback(url, options);

Now missing tiles will be automatically replaced by scaled up tiles from lower zoom levels.

Installing the plugin

Local copy

  1. Download the "leaflet.tilelayer.fallback.js" file from the v1.0.4 release.
  2. Place the file alongside your page.
  3. Add the script tag (see Quick Guide > HTML) to your page after Leaflet script.

CDN

You can alternatively use the free unpkg CDN service, but keep in mind that it "is a free, best-effort service and cannot provide any uptime or support guarantees".

<!-- After Leaflet script -->
<script src="https://unpkg.com/[email protected]/dist/leaflet.tilelayer.fallback.js"></script>

Creation

Simply use the L.tileLayer.fallback factory instead of your regular L.tileLayer:

var myTileLayer = L.tileLayer.fallback(url, options);

myTileLayer.addTo(map);

API Reference

Creation

| Factory | Description | | :------ | :---------- | | L.tileLayer.fallback( <String> urlTemplate, <TileLayer options> options? ) | Instantiates a tile layer object given a URL template and optionally an options object. When tile images return a 404 error, they are replaced by a scaled up tile from lower zoom. |

Options

| Option | Type | Default | Description | | :----- | :--- | :------ | :---------- | | minNativeZoom | Number | 0 | Minimum zoom number the tiles source has available. If tiles are missing down to that zoom level (included), they will be replaced by the standard Error Tile (specified by errorTileUrl). For zoom lower than minNativeZoom, standard Tile Layer behaviour applies, i.e. tiles are loaded from minNativeZoom and scaled down. |

All other TileLayer options are applicable.

Events

| Event | Data | Description | | :---- | :--- | :---------- | | tilefallback | TileFallbackEvent | Fired when a tile is being replaced by a scaled up tile of lower zoom. |

All other TileLayer events are applicable.

TileFallbackEvent

| Property | Type | Description | | :------- | :--- | :---------- | | tile | HTMLElement | The tile element (image). | | url | String | The original source URL of the tile (before any fallback is applied). | | urlMissing | String | The missing source URL of the tile (possibly after a few fallback attempts). | | urlFallback | String | The fallback source URL of the tile (which may turn out to be also missing). |

Methods

All regular TileLayer methods are applicable.

Limitations

TileLayer.Fallback plugin tries to replace each missing tile by its immediate lower zoom equivalent, and if that one is also missing, it goes to lower zoom again; and so on until a tile image is returned by the server, or it reaches minNativeZoom.

That means it has to wait for the server to return a 404 error before attempting to replace the tile by a lower zoom equivalent. If several zoom levels are missing, it has to wait as many times as the number of missing zooms. Therefore, the more missing zoom levels, the more time it takes to replace a tile.

License

license

Leaflet.TileLayer.Fallback is distributed under the Apache 2.0 License.