JavaScript Quickstart
Get started with A5 in JavaScript by installing the package and running a simple example.
Installation
Install the A5 package using npm:
npm install a5-js
Or using yarn:
yarn add a5-js
Code Example: Generate A5 Cells
Here's a complete example that generates A5 cells at a specified resolution and outputs them as GeoJSON:
import { cellToBoundary, bigIntToHex, cellToChildren } from "a5-js";
// Generate all cells at the specified resolution
const resolution = 2;
const cells = [];
const cellIds = cellToChildren(0n, resolution);
// Generate boundary for each cell
for (let cellId of cellIds) {
const cellIdHex = bigIntToHex(cellId);
const boundary = cellToBoundary(cellId);
cells.push({
type: "Feature",
geometry: { type: "Polygon", coordinates: [boundary] },
properties: { cellIdHex }
});
}
// Create GeoJSON FeatureCollection
const geojson = { type: "FeatureCollection", features: cells };
Example Output
The above code will produce a collection of cells that cover the whole world.
Note that the cells all have the same area (approximately) shape - they are just warped by the map projection
A5 Wireframe Example
Cells shown: 240
Hover over cells to see their IDs
CLI Usage
The code above in CLI form is available here.
node index.js 2 a5.geojson
This will generate A5 cells at resolution 2 and save them as GeoJSON in a5.geojson
.
Next Steps
- Learn more about A5 indexing
- Explore cell hierarchy
- Check out more examples