-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the unit tests back and server cli for screenshots.
- Loading branch information
1 parent
157f9e4
commit abe178e
Showing
10 changed files
with
1,409 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { createServer } from '@basemaps/server'; | ||
import { Const, Env, LogConfig } from '@basemaps/shared'; | ||
import { | ||
CommandLineAction, | ||
CommandLineFlagParameter, | ||
CommandLineIntegerParameter, | ||
CommandLineStringParameter, | ||
} from '@rushstack/ts-command-line'; | ||
|
||
const DefaultPort = 5000; | ||
|
||
export class CommandServe extends CommandLineAction { | ||
config: CommandLineStringParameter; | ||
assets: CommandLineStringParameter; | ||
port: CommandLineIntegerParameter; | ||
noConfig: CommandLineFlagParameter; | ||
|
||
public constructor() { | ||
super({ | ||
actionName: 'serve', | ||
summary: 'Cli tool to create sprite sheet', | ||
documentation: 'Create a sprite sheet from a folder of sprites', | ||
}); | ||
} | ||
|
||
protected onDefineParameters(): void { | ||
this.config = this.defineStringParameter({ | ||
argumentName: 'CONFIG', | ||
parameterLongName: '--config', | ||
description: 'Configuration source to use', | ||
}); | ||
this.assets = this.defineStringParameter({ | ||
argumentName: 'ASSETS', | ||
parameterLongName: '--assets', | ||
description: 'Where the assets (sprites, fonts) are located', | ||
}); | ||
this.port = this.defineIntegerParameter({ | ||
argumentName: 'PORT', | ||
parameterLongName: '--port', | ||
description: 'port to use', | ||
defaultValue: DefaultPort, | ||
}); | ||
} | ||
|
||
protected async onExecute(): Promise<void> { | ||
const logger = LogConfig.get(); | ||
|
||
const config = this.config.value ?? 'dynamodb://' + Const.TileMetadata.TableName; | ||
const port = this.port.value; | ||
const assets = this.assets.value; | ||
|
||
// Force a default url base so WMTS requests know their relative url | ||
const ServerUrl = Env.get(Env.PublicUrlBase) ?? `http://localhost:${port}`; | ||
process.env[Env.PublicUrlBase] = ServerUrl; | ||
|
||
const server = await createServer({ config, assets }, logger); | ||
await server.listen({ port: port ?? DefaultPort, host: '0.0.0.0' }); | ||
logger.info({ url: ServerUrl }, 'ServerStarted'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { Bounds, Epsg, EpsgCode, GoogleTms } from '@basemaps/geo'; | ||
import { LogConfig } from '@basemaps/shared'; | ||
import { fsa } from '@chunkd/fs'; | ||
import { CogTiff } from '@cogeotiff/core'; | ||
|
||
import o from 'ospec'; | ||
import { CogBuilder, guessProjection } from '../builder.js'; | ||
|
||
o.spec('Builder', () => { | ||
o('should guess WKT', () => { | ||
o( | ||
guessProjection( | ||
'PCS Name = NZGD_2000_New_Zealand_Transverse_Mercator|GCS Name = GCS_NZGD_2000|Ellipsoid = GRS_1980|Primem = Greenwich||', | ||
), | ||
).equals(Epsg.Nztm2000); | ||
|
||
o( | ||
guessProjection('NZGD2000_New_Zealand_Transverse_Mercator_2000|GCS Name = GCS_NZGD_2000|Primem = Greenwich||'), | ||
).equals(Epsg.Nztm2000); | ||
}); | ||
|
||
o('should not guess unknown wkt', () => { | ||
o(guessProjection('')).equals(null); | ||
o(guessProjection('NZTM')).equals(null); | ||
o(guessProjection('NZGD2000')).equals(null); | ||
}); | ||
|
||
o.spec('tiff', () => { | ||
const googleBuilder = new CogBuilder(GoogleTms, 1, LogConfig.get()); | ||
const origInit = CogTiff.prototype.init; | ||
const origGetImage = CogTiff.prototype.getImage; | ||
|
||
o.after(() => { | ||
CogTiff.prototype.init = origInit; | ||
CogTiff.prototype.getImage = origGetImage; | ||
}); | ||
|
||
o('bounds', async () => { | ||
const localTiff = fsa.source('/local/file.tiff')!; | ||
const s3Tiff = fsa.source('s3://bucket/file.tiff')!; | ||
|
||
const imageLocal = { | ||
resolution: [0.1], | ||
value: (): any => [1], | ||
valueGeo: (): any => EpsgCode.Nztm2000, | ||
bbox: Bounds.fromJson({ | ||
x: 1492000, | ||
y: 6198000, | ||
width: 24000, | ||
height: 36000, | ||
}).toBbox(), | ||
}; | ||
|
||
const imageS3 = { | ||
resolution: [0.1], | ||
value: (): any => [1], | ||
valueGeo: (): any => EpsgCode.Nztm2000, | ||
bbox: Bounds.fromJson({ | ||
x: 1492000 + 24000, | ||
y: 6198000, | ||
width: 24000, | ||
height: 36000, | ||
}).toBbox(), | ||
}; | ||
|
||
CogTiff.prototype.init = o.spy() as any; | ||
CogTiff.prototype.getImage = function (): any { | ||
return this.source === localTiff ? imageLocal : imageS3; | ||
}; | ||
|
||
const ans = await googleBuilder.bounds([localTiff, s3Tiff]); | ||
|
||
o(ans).deepEquals({ | ||
projection: 2193, | ||
nodata: 1, | ||
bands: 1, | ||
bounds: [ | ||
{ | ||
x: 1492000, | ||
y: 6198000, | ||
width: 24000, | ||
height: 36000, | ||
name: '/local/file.tiff', | ||
}, | ||
{ | ||
x: 1516000, | ||
y: 6198000, | ||
width: 24000, | ||
height: 36000, | ||
name: 's3://bucket/file.tiff', | ||
}, | ||
], | ||
pixelScale: 0.1, | ||
resZoom: 21, | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.