UNPKG

@allmaps/render

Version:

Render functions for WebGL and image buffers

90 lines (89 loc) 2.3 kB
import { mergePartialOptions } from "@allmaps/stdlib"; import { tileKey, fetchableTileKey } from "../shared/tiles.js"; class FetchableTile { mapId; tile; tileUrl; tileKey; fetchableTileKey; options; /** * Creates an instance of FetchableTile. * * @constructor * @param tile - the tile * @param mapId - Map ID * @param tileUrl - Tile URL * @param imageRequest - Image Request * @param options - FetchableTileOptions */ constructor(tile, mapId, tileUrl, options) { this.tile = tile; this.mapId = mapId; this.tileUrl = tileUrl; this.options = options; this.tileKey = tileKey(tile); this.fetchableTileKey = fetchableTileKey(this); } /** * Creates an instance of FetchableTile from a WarpedMap. * * @constructor * @param tile - the tile * @param warpedMap - A WarpedMap with fetched image */ static fromWarpedMap(tile, warpedMap, options) { const tileImageRequest = warpedMap.image.getTileImageRequest( tile.tileZoomLevel, tile.column, tile.row ); return new FetchableTile( tile, warpedMap.mapId, warpedMap.image.getImageUrl(tileImageRequest), mergePartialOptions(options, { imageRequest: tileImageRequest }) ); } /** * Creates an instance of FetchableTile from a sprite. * * @constructor * @param sprite - Sprite * @param imageSize - imageSize * @param warpedMap - A WarpedMap with fetched image */ static fromSprite(sprite, imageSize, warpedMap, options) { const width = warpedMap.tileSize[0]; const height = warpedMap.tileSize[1]; const tile = { column: 0, row: 0, tileZoomLevel: { scaleFactor: sprite.scaleFactor, width, height, originalWidth: width * sprite.scaleFactor, originalHeight: height * sprite.scaleFactor, columns: 1, rows: 1 }, imageSize }; const tileImageRequest = warpedMap.image.getTileImageRequest( tile.tileZoomLevel, tile.column, tile.row ); return new FetchableTile( tile, warpedMap.mapId, sprite.imageId, mergePartialOptions(options, { imageRequest: tileImageRequest }) ); } } export { FetchableTile }; //# sourceMappingURL=FetchableTile.js.map