3个版本 (1个稳定版)
1.0.0 | 2024年8月7日 |
---|---|
0.2.0 | 2024年7月29日 |
0.1.0 | 2024年5月29日 |
#626 in 编码
每月253次下载
120KB
2.5K SLoC
s2-pmtiles
关于
A Modified TypeScript implementation of the PMTiles library. It is backwards compatible but offers support for the S2 Projection.
阅读规范
目前此规范支持在浏览器内解压缩元数据和目录,但将来将被移除。
安装
#bun
bun add s2-pmtiles
# pnpm
pnpm add s2-pmtiles
# yarn
yarn add s2-pmtiles
# npm
npm install s2-pmtiles
# cargo
cargo install s2-pmtiles
示例用法
import { PMTilesReader, PMTilesWriter } from 's2-pmtiles'
// The File Reader you can run on bun/node/deno
const testFixture1 = new PMTilesReader(`test/fixtures/test_fixture_1.pmtiles`);
// get an WM tile
let x = 0;
let y = 0;
let z = 0;
let face = 0;
testFixture1.getTile(x, y, z); // undefied | Uint8Array
// get an S2 tile
testFixture1.getTileS2(face, x, y, z); // undefined | Uint8Array
// The File Writer you can run on bun/node/deno
const testFixture2 = new PMTilesWriter(`tmpFile.pmtiles`);
// write a tile
testFixture2.writeTileXYZ(x, y, z, Uint8Array.from([]));
// write an S2 tile
testFixture2.writeTileS2(face, x, y, z, Uint8Array.from([]));
// when you finish you commit to build the metadata
testFixture2.commit();
// The File Reader you can run in the browser
import { S2PMTilesReader } from 's2-pmtiles/browser';
// you want to add a true after the path for generic PMTiles, as it ensures 206 byte requests.
const browserFixture = new S2PMTilesReader(`https://www.example.com/test.pmtiles`, true);
// get an WM tile
browserFixture.getTile(x, y, z); // undefied | Uint8Array
// get an S2 tile
browserFixture.getTileS2(face, x, y, z); // undefined | Uint8Array
浏览器支持
一些tsconfigs可能需要一些额外的帮助才能看到 s2-pmtiles/browser
包。
要修复此问题,请使用以下命令更新您的tsconfig.json
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"s2-pmtiles/browser": ["./node_modules/s2-pmtiles/dist/browser.d.ts"]
}
}
}
开发
需求
您需要 tarpaulin
工具来生成覆盖率报告。使用以下命令安装它
cargo install cargo-tarpaulin
bacon coverage
工具用于生成覆盖率报告。要使用 pycobertura 包生成更漂亮的覆盖率报告,请使用以下命令安装它
pip install pycobertura
运行测试
要运行测试,请使用以下命令
# TYPESCRIPT
## basic test
bun run test
## live testing
bun run test:dev
# RUST
## basic test
cargo test
# live testing
bacon test
生成覆盖率报告
要生成覆盖率报告,请使用以下命令
cargo tarpaulin
# bacon
bacon coverage # or type `l` inside the tool
依赖关系
~1.1–2.2MB
~48K SLoC