Skip to content

Commit

Permalink
Merge pull request #102 from Kanahiro/npm
Browse files Browse the repository at this point in the history
improve library mode interface
  • Loading branch information
Kanahiro authored Aug 17, 2024
2 parents f5bb439 + ab1b5a0 commit a370ddd
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,58 @@ node dist/main.js tile-server -c s3 -s3b chiitiler -s3r ap-northeast-1
}
```

## Library Mode

- chiitiler can be used as a library to render MapLibre Style.
- methods to render MapLibre Style are exposed from `chiitiler` package.

### installation

```sh
npm install chiitiler
```

- chiitiler requires some dependencies in runtime, you can find them in [Dockerfile](./Dockerfile)

### Usage

```typescript
import {
getRenderedBboxBuffer,
getRenderedTileBuffer,
ChiitilerCache
} from 'chiitiler';

const s3Cache = ChiitilerCache.s3Cache({
bucket: 'chiitiler',
region: 'ap-northeast-1',
endpoint: null,
});

const tileBuf = await getRenderedTileBuffer({
stylejson: 'https://example.com/style.json', // or StyleSpecification object
z: 0,
x: 0,
y: 0,
tileSize: 512,
ext: 'webp', // png, webp, jpg
cache: s3Cache,
quality: 80,
margin: 0,
});

const bboxBuf = await getRenderedBboxBuffer({
stylejson: 'file://path/to/style.json', // or StyleSpecification object
bbox: [123.4, 34.5, 124.5, 35.6],
size: 1024,
cache: s3Cache,
ext: 'webp',
quality: 80,
});

// return value is Buffer - binary of each image
```

## development

- run `docker compose up`
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "module",
"name": "chiitiler",
"version": "1.12.4",
"version": "1.12.5",
"description": "Tiny map rendering server for MapLibre Style Spec",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
8 changes: 5 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export { initServer, type InitServerOptions } from './server/index.js';

export * as cache from './cache/index.js';
export {
getRenderedBboxBuffer,
getRenderedTileBuffer,
} from './render/index.js';
export * as ChiitilerCache from './cache/index.js';

0 comments on commit a370ddd

Please sign in to comment.