Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

@camptocamp/inkmap

Package Overview
Dependencies
Maintainers
7
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@camptocamp/inkmap

A library for generating printable, high quality maps in the browser.

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
7
Created
Source
inkmap, a library for generating high resolution maps in the browser
Live demo here!

Introduction

inkmap is based on OpenLayers and will generate maps in PNG format based on a given JSON specification.

inkmap can handle long-running jobs (e.g. A0 format in 300 dpi) and provides an API for following a job progress. It uses a service worker in the background provided the user browser supports OffscreenCanvas, and falls back (almost) seamlessly to the main thread if not.

Please note that the first version of inkmap has been entirely funded and supported by the French Ministry of Ecology as part of their Descartes web mapping toolkit, hosted here: https://adullact.net/projects/descartes/

Usage

Basic

To include the library in your project:

$ npm install --save @camptocamp/inkmap

Then import the different methods from the inkmap package:

import { print, downloadBlob } from '@camptocamp/inkmap';

print({
  layers: [ ... ],
  projection: 'EPSG:4326',
  ...
}).then(downloadBlob);

Advanced

inkmap offers advanced job monitoring through the use of Observables provided by the rxjs library.

Observables are different from Promises in that they can emit multiple values instead of just one, and are a very good fit for progress reporting.

To use an Observable, simply call its subscribe() method with a function as argument. The function will be called anytime a new value is emitted, like so:

import { getJobStatus } from '@camptocamp/inkmap';

...

getJobStatus(jobId).subscribe((jobStatus) => {
  // do something with the status
});

Note that for long-lived Observables (i.e. Observables that never completes) it is important to call unsubscribe() when the emitted values are not needed anymore. Open subscriptions to Observables might create memory leaks.

Enabling the service worker

inkmap can and will use a dedicated service worker for running print jobs if given the chance. This offers the following advantages:

  • Jobs run in a separate thread, meaning the user navigation will not be impacted at all by any CPU-intensive task
  • The service worker isn't tied to a window or tab, so jobs will continue running when the tab is closed (and even when the browser is closed, depending on the platform)
  • Push notifications might be sent to the user when a print job complete (not implemented yet)

To enable this, the inkmap-worker.js file located in the dist folder must be published on the same path as the application using inkmap.

The worker file can be published either using a symbolic link or by actually copying the file, for example in the application build pipeline.

If using Webpack to build the application, a solution is to use the CopyWebpackPlugin:

export default {
  ...
  plugins: [
     new CopyWebpackPlugin([
       {
         from: 'node_modules/@camptocamp/inkmap/dist/inkmap-worker.js',
         to: 'dist'
       },
     ]),
  ],
  ...
}

API

Important note: all API functions are named exports from the inkmap package.

See the API documentation website.

Architecture

Under the hood, inkmap will attempt to install a service worker on the page it is called. The service worker will then be in charge of loading all the map images and data, composing them together and giving them back to the application code.

Contributing

See CONTRIBUTING.

License

CeCILL-C

Keywords

map

FAQs

Package last updated on 10 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts