export module Layer { export interface OlWMTSLayerOptions { layerName: string; url: string; hdpi?: boolean; attribution?: string; } export const defaultResolutions: number[] = [8960, 4480, 2240, 1120, 560, 280, 140, 70, 28, 14, 7, 2.8, 1.4, 0.7, 0.28, 0.14, 0.07]; /** * @param openlayers - e.g. window.ol * @param sourceOptions */ export function olTileLayer(openlayers: any, sourceOptions: OlWMTSLayerOptions) { return new openlayers.layer.Tile({ source: olTileWMTSSource(openlayers, sourceOptions) }) } /** * @param openlayers - e.g. window.ol * @param options */ export function olTileWMTSSource(openlayers: any, options: OlWMTSLayerOptions) { let projExtent = [274000, 3087000, 3327000, 7173000]; let tileGrid = new openlayers.tilegrid.WMTS({ origin: openlayers.extent.getTopLeft(projExtent), extent: projExtent, resolutions: defaultResolutions, matrixIds: ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"] }); let matrixSet = options.hdpi ? "NZTM2000HDPI" : "NZTM2000"; return new openlayers.source.WMTS({ tileGrid: tileGrid, projection: "EPSG:2193", url: options.url, format: 'jpeng', layer: options.layerName + (options.hdpi ? '-HDPI' : ''), style: 'default', tilePixelRatio: options.hdpi ? 2 : 1, matrixSet, // requestEncoding: "REST", attributions: options.attribution ? [ new openlayers.Attribution({ html: options.attribution }) ] : [], }); } }