Skip to content

digidem/mapeo-map-server

Repository files navigation

Mapeo Map Server

Build Status

An in-progress offline map style and tile server for Mapeo.

npm install @mapeo/map-server

⚠️ This is alpha software. No guarantees can be made about the stability of the API at the moment, so proceed with caution. 😄

Features

  • Manages tiles and tilesets (TileJSON)

  • Manages Mapbox map styles

  • Supports importing MBTile files as tilesets

    • Supports getting import progress
  • Provides info related to downloads and storage

Usage

The default export is a function for creating a map server instance. Basic usage is as follows:

// If you're using TypeScript, you may want to use one of the following import syntaxes to get type definitions:
// - `require('@mapeo/map-server').default`
// - `import createMapServer from '@mapeo/map-server'
const createMapServer = require('@mapeo/map-server')

// Create the server instance
const mapServer = createMapServer({ storagePath: './map-server-example.db' })

// Run the server!
await mapServer.listen(3000)

createServer(opts): MapServer

Creates the map server instance

  • opts (required): Options object to customize the map server instance. Options include:
    • storagePath: string (required): Path to use for persistent map server storage. Happens to be a SQLite database under the hood, but consumers should treat this as an opaque path managed exclusively by the map server.

API Documentation

API documentation is available in API.md.

Technical Details

  • Fastify for creating the server.
  • SQLite as the underlying persistence layer.
  • Prisma as a build tool for updating the schema, creating migration scripts, and generating schema assets.
    • Schema diagram can be found here.
    • Due to the distributed and local-first nature of Mapeo, migrations are performed at runtime by the server on initialization. See the migrations implementation for more details. It roughly follows the logic that Prisma uses for build-time migrations.

Developing

Some notes before working on this locally:

  • If you make any changes to the schema via schema.prisma, run the following commands afterwards:
    • npm run prisma:migrate-dev -- --name MIGRATION_NAME_HERE - creates a new migration in the prisma/migrations/ directory, which is used by tests and the server if running locally

License

MIT