Loads OGC GeoPackage vector data tables into OpenLayers Vector Sources
npm install ol-load-geopackage
A JavaScript module to load OGC GeoPackage vector data tables into OpenLayers Vector Sources, transforming the data (if necessary) to match the specified display projection. This was primarily designed to directly load data exported by the QGIS Package Layers Processing Toolbox operation. As such, it will also (if it exists) load the associated "layer_styles" table of SLD XML styling data exported by QGIS in the same GeoPackage. It is implemented as an NPM module and is a lightweight wrapper around the sql.js SQLite JavaScript library.
The current version was tested with OpenLayers 10.7, but should work with OpenLayers 6+.
Each example (in the GitHub repository) is presented as HTML/JavaScript source code and as directly viewable web pages (built using both Vite and the Webpack module bundler).
- Basic Example: web page: Vite, Webpack (sources: Vite HTML, Webpack HTML,
JavaScript (common))
- Loads vector tables and associated QGIS "layer_styles" SLD XML strings from an OGC GeoPackage and render all tables as layers on an OpenLayers map. Displays details of package contents.
- Proj4 Example: web page: Vite, Webpack (sources: Vite HTML, Webpack HTML,
JavaScript (common))
- Used in conjunction with Proj4js module to enable additional projections to those built in to OpenLayers. These other projections can be for the input source data and/or the output display projection. Also demonstrates loading required sql.js WebAssembly binary (WASM) from an external Content Delivery Network (CDN) site.
Note: identical JavaScript code is used in the Webpack/Vite versions, with the HTML code only being very subtly different.
You can try the examples with your own GeoPackage data files (without having to install Node.js or WebPack) by cloning the GitHub repository then editing the "gpkgFile" definition in the HTML files. In order to ensure all the files are able to load you will have to host them with a (simple) local HTTP server, for example by running in the examples/dist or examples-vite/dist folder...
``bash`
python -m http.server (Windows)
python3 -m http.server (macOS/Linux)
...which will allow you to view them in a browser at http://localhost:8000/. Note however that if your source data uses projections (SRS) other than the few built in to OpenLayers, then you would need to modify the .js source files (as in the Proj4 example) to add more SRS and rebuild the .js bundles.
Use Node.js to install the NPM package: ol-load-geopackage
`bash`
npm install --save ol-load-geopackage
After running npm install, the sql.js WebAssembly file (sql-wasm.wasm) will need to be copied from folder _node_modules/sql.js/dist/_ to a folder where the web page can load it from (unless you plan to load it from a CDN).
This package must be imported as a module - it is not designed to be loaded directly with a \