UNPKG

leaflet

Version:

JavaScript library for mobile-friendly interactive maps

153 lines (152 loc) • 6.91 kB
import { GridLayer } from './GridLayer.js'; import { Point } from '../../geometry/Point.js'; import type { Coords, Defaults, DoneCallback, TileEvent, TileLayerDefaults, TileLayerEventMap, TileLayerOptions } from '../../types.js'; /** @import {Coords, Defaults, DoneCallback, GridLayerOptions, TileEvent, TileLayerDefaults, TileLayerEventMap, * TileLayerOptions} from '../../types.js' */ /** @satisfies {Defaults<GridLayerOptions>} */ declare const defaultOptions: { /** The minimum zoom level down to which this layer will be displayed (inclusive). */ minZoom: number; /** The maximum zoom level up to which this layer will be displayed (inclusive). */ maxZoom: number; /** * Subdomains of the tile service. Can be passed in the form of one string * (where each letter is a subdomain name) or an array of strings. * @type {string | string[]} */ subdomains: string | string[]; /** URL to the tile image to show in place of the tile that failed to load. */ errorTileUrl: string; /** The zoom number used in tile URLs will be offset with this value. */ zoomOffset: number; /** * If `true`, inverses Y axis numbering for tiles (turn this on for * [TMS](https://en.wikipedia.org/wiki/Tile_Map_Service) services). */ tms: boolean; /** If set to true, the zoom number used in tile URLs will be reversed (`maxZoom - zoom` instead of `zoom`) */ zoomReverse: boolean; /** * If `true` and user is on a retina display, it will request four tiles of half the specified * size and a bigger zoom level in place of one to utilize the high resolution. */ detectRetina: boolean; /** * Whether the crossOrigin attribute will be added to the tiles. If a String is provided, * all tiles will have their crossOrigin attribute set to the String provided. This is needed * if you want to access tile pixel data. Refer to [CORS * Settings](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_settings_attributes) for valid String values. * @type {boolean | string} */ crossOrigin: boolean | string; /** * Sets the tiles' `referrerPolicy` attribute set to the String provided. See * [`HTMLImageElement.referrerPolicy`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/referrerPolicy) * for possible values. * * Tile providers might require you to use a specific referrer policy (e.g. to verify API tokens or * prevent abuse). Specifically, if you are using tiles from `tile.openstreetmap.org` or `tile.osm.org`, * you [should not change this value](https://operations.osmfoundation.org/policies/tiles/). * @type {ReferrerPolicy | false} */ referrerPolicy: ReferrerPolicy | false; }; export type TileLayerDefaultsValues = typeof defaultOptions; export type TileLayerEvents = { /** * Fired when a tile was loading but is now not wanted. */ tileabort: TileEvent; }; /** * @typedef {Object} TileLayerEvents * @property {TileEvent} tileabort Fired when a tile was loading but is now not wanted. */ /** * Used to load and display tile layers on the map. Note that most tile servers * require attribution, which you can set under `Layer`. Extends `GridLayer`. * @example * ```js * new TileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png?{foo}', {foo: 'bar', attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'}).addTo(map); * ``` * @example <caption>URL template</caption> * A string of the following form: * * ``` * 'https://{s}.somedomain.com/blabla/{z}/{x}/{y}{r}.png' * ``` * * `{s}` means one of the available subdomains (used sequentially to help with browser parallel requests per domain limitation; subdomain values are specified in options; `a`, `b` or `c` by default, can be omitted), `{z}` — zoom level, `{x}` and `{y}` — tile coordinates. `{r}` can be used to add "&commat;2x" to the URL to load retina tiles. * * You can use custom keys in the template, which will be [evaluated](#util-template) from TileLayer options, like this: * * ``` * new TileLayer('https://{s}.somedomain.com/{foo}/{z}/{x}/{y}.png', {foo: 'bar'}); * ``` * @template {TileLayerOptions} [O=TileLayerOptions] * @template {TileLayerEventMap} [E=TileLayerEventMap] * @extends {GridLayer<O & TileLayerDefaults, E>} */ export declare class TileLayer<O extends TileLayerOptions = TileLayerOptions, E extends TileLayerEventMap = TileLayerEventMap> extends GridLayer<O & TileLayerDefaults, E> { _url: string; static initHooks: boolean; /** @type {Defaults<TileLayerOptions>} */ static defaultOptions: Defaults<TileLayerOptions>; /** * Instantiates a tile layer object given a `URL template` and optionally an options object. * @category URL template * @param {string} url * @param {NoInfer<Partial<O>>} [options] */ constructor(url: string, options?: NoInfer<Partial<O>>); /** * Updates the layer's URL template and redraws it (unless `noRedraw` is set to `true`). If the URL * does not change, the layer will not be redrawn unless the noRedraw parameter is set to false. * @param {string} url * @param {boolean} [noRedraw] */ setUrl(url: string, noRedraw?: boolean): this; /** * Called only internally, overrides GridLayer's [`createTile()`](#gridlayer-createtile) * to return an `<img>` HTML element with the appropriate image URL given `coords`. * The `done` callback is called when the tile has been loaded. * @param {Coords} coords * @param {DoneCallback} done * @returns {HTMLElement} */ createTile(coords: Coords, done: DoneCallback): HTMLElement; /** * Called only internally, returns the URL for a tile given its coordinates. Classes extending * `TileLayer` can override this function to provide custom tile URL naming schemes. * @category Extension methods * @param {Coords} coords * @uninheritable */ getTileUrl(coords: Coords): string; /** * @param {DoneCallback} done * @param {HTMLImageElement} tile */ _tileOnLoad(done: DoneCallback, tile: HTMLImageElement): void; /** * @param {DoneCallback} done * @param {HTMLImageElement} tile * @param {Event} e */ _tileOnError(done: DoneCallback, tile: HTMLImageElement, e: Event): void; _getZoomForUrl(): number; /** @param {Point} tilePoint */ _getSubdomain(tilePoint: Point): string; _abortLoading(): void; /** @param {string} key */ _removeTile(key: string): void; /** * @param {Coords} coords * @param {unknown} [err] * @param {HTMLElement} [tile] */ _tileReady(coords: Coords, err?: unknown, tile?: HTMLElement): void; /** @param {number} zoom */ _clampZoom(zoom: number): number; } export {};