UNPKG

3d-tiles-renderer

Version:

https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification

73 lines (49 loc) 1.42 kB
import { ProjectionScheme } from '../utils/ProjectionScheme.js'; import { TiledImageSource } from './TiledImageSource.js'; export class XYZImageSource extends TiledImageSource { constructor( options = {} ) { const { levels = 20, tileDimension = 256, projection = 'EPSG:3857', url = null, ...rest } = options; super( rest ); this.tileDimension = tileDimension; this.levels = levels; this.projection = projection; this.url = url; } getUrl( x, y, level ) { return this.url .replace( /{\s*z\s*}/gi, level ) .replace( /{\s*x\s*}/gi, x ) .replace( /{\s*(y|reverseY|-\s*y)\s*}/gi, y ); } init() { // transform the url const { tiling, tileDimension, levels, url, projection } = this; tiling.flipY = ! /{\s*reverseY|-\s*y\s*}/g.test( url ); tiling.setProjection( new ProjectionScheme( projection ) ); tiling.setContentBounds( ...tiling.projection.getBounds() ); if ( Array.isArray( levels ) ) { levels.forEach( ( info, level ) => { if ( info !== null ) { tiling.setLevel( level, { tilePixelWidth: tileDimension, tilePixelHeight: tileDimension, ...info } ); } } ); } else { tiling.generateLevels( levels, tiling.projection.tileCountX, tiling.projection.tileCountY, { tilePixelWidth: tileDimension, tilePixelHeight: tileDimension, } ); } this.url = url; return Promise.resolve(); } }