.gpkg file, define tables, and populate them with features and tiles.
Create a new GeoPackage
GeoPackageManager.create() creates the file on disk in Node.js, or creates an in-memory database in the browser.- Node.js
- Browser (in-memory)
The path argument is ignored in browser environments. The library automatically creates the minimum required GeoPackage metadata tables on creation.
Create a feature table
Use
createFeatureTableWithMetadata() to create the user table and all required GeoPackage metadata (geometry columns, contents, SRS) in one call.Insert feature rows
Get a
FeatureDao for your table, create a new row, set the geometry and attribute values, then save it.Create a tile table
Use
createTileTableWithMetadata() to create a tile table along with its tile matrix set and contents entries.After creating the tile table, you also need to define
TileMatrix rows for each zoom level before inserting tiles. These describe how many columns and rows exist at each zoom level.Insert tiles
addTile() is the simplest way to insert a tile — pass the raw image bytes, table name, zoom level, tile row, and tile column.addTile() for each one: