Skip to content

Commit

Permalink
updated for writer and reader to work in the browser as the default; …
Browse files Browse the repository at this point in the history
…added gzip writing; bug fixes
  • Loading branch information
Mr Martian committed Sep 15, 2024
1 parent a83b91d commit b76a353
Show file tree
Hide file tree
Showing 61 changed files with 951 additions and 715 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ benchmarks/data/bing/mvt/*.mvt
tools/fetchBingTiles.ts
tools/fetchOMT.ts
s2-pmtiles-spec/1.0.0/README.bak.md
coverage
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ docs/
benchmarks/
tools/
s2-pmtiles-spec/
coverage
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ cargo install s2-pmtiles
### Example use

```ts
import { PMTilesReader, PMTilesWriter } from 's2-pmtiles'
import { S2PMTilesReader, S2PMTilesWriter, TileType } from 's2-pmtiles'
import { FileReader, FileWriter } from 's2-pmtiles/file';

// The File Reader you can run on bun/node/deno
const testFixture1 = new PMTilesReader(`test/fixtures/test_fixture_1.pmtiles`);
const testFixture1 = new S2PMTilesReader(new FileReader('test/fixtures/test_fixture_1.pmtiles'));
// get an WM tile
let x = 0;
let y = 0;
Expand All @@ -74,18 +75,19 @@ testFixture1.getTile(x, y, z); // undefied | Uint8Array
testFixture1.getTileS2(face, x, y, z); // undefined | Uint8Array

// The File Writer you can run on bun/node/deno
const testFixture2 = new PMTilesWriter(`tmpFile.pmtiles`);
const testFixture2 = new S2PMTilesWriter(new FileWriter('tmpFile.pmtiles'), TileType.Pbf);
// 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';
import { S2PMTilesReader } from 's2-pmtiles';
// 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);
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
Expand All @@ -94,7 +96,7 @@ browserFixture.getTileS2(face, x, y, z); // undefined | Uint8Array

### Browser Support

Some tsconfigs might need some extra help to see the `s2-pmtiles/browser` package.
Some tsconfigs might need some extra help to see the `s2-pmtiles/file` or `s2-pmtiles/mmap` package.

To fix this update your tsconfig.json with the following:

Expand All @@ -103,7 +105,8 @@ To fix this update your tsconfig.json with the following:
"compilerOptions": {
"baseUrl": "./",
"paths": {
"s2-pmtiles/browser": ["./node_modules/s2-pmtiles/dist/browser.d.ts"]
"s2-pmtiles/file": ["./node_modules/s2-pmtiles/dist/file.d.ts"],
"s2-pmtiles/mmap": ["./node_modules/s2-pmtiles/dist/mmap.d.ts"]
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions assets/doc-coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 15 additions & 5 deletions build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,30 @@ try {
format: 'esm',
minify: true,
sourcemap: 'external',
target: 'node',
target: 'browser',
// target: 'esnext', // Adjust target based on your project needs
});
console.info('Node Build completed successfully!', outputNode);
const outputBrowser = await bun.build({
entrypoints: ['src/browser.ts'],
const outputFile = await bun.build({
entrypoints: ['src/file.ts'],
outdir: 'dist',
format: 'esm',
minify: true,
sourcemap: 'external',
target: 'browser',
target: 'node',
// target: 'esnext', // Adjust target based on your project needs
});
console.info('File Build completed successfully!', outputFile);
const outputMMap = await bun.build({
entrypoints: ['src/mmap.ts'],
outdir: 'dist',
format: 'esm',
minify: true,
sourcemap: 'external',
target: 'node',
// target: 'esnext', // Adjust target based on your project needs
});
console.info('Browser Build completed successfully!', outputBrowser);
console.info('File Build completed successfully!', outputMMap);
} catch (error) {
console.error('Build failed:', error);
}
Binary file modified bun.lockb
Binary file not shown.
6 changes: 3 additions & 3 deletions bunfig.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[test]

# preload options
# preload = []
preload = ['./test/polyfill.ts']

# root directory
root = "./test"
Expand All @@ -11,6 +11,6 @@ root = "./test"
coverage = true

# new
# coverageReporter = ["text", "lcov"] # default ["text"]
coverageReporter = ["lcov"] # default ["text"]
coverageReporter = ["text", "lcov"] # default ["text"]
# coverageReporter = ["lcov"] # default ["text"]
coverageDir = "./coverage" # default "coverage"
2 changes: 1 addition & 1 deletion docs/assets/navigation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/assets/search.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b76a353

Please sign in to comment.