@camptocamp/inkmap

中文文档
2.0.0发布于 2025/09/10SEE LICENSE IN LICENSE.txtES Module近 30 天下载 2712

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

原始使用文档
文档目录9 节
  1. Introduction
  2. Usage
  3. Basic
  4. Advanced
  5. Enabling the service worker
  6. API
  7. Architecture
  8. Contributing
  9. License
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

版本与发布记录

@camptocamp/inkmap 共发布 11 个版本,首次发布于 2021/02/18;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.0latest2025/09/101.2 年前
1.4.02023/09/123 年前
1.3.02022/09/034 年前
1.2.02021/11/304 年前
1.1.12021/03/255 年前
1.1.02021/03/145 年前

关于 @camptocamp/inkmap 的常见问题

@camptocamp/inkmap 是什么?

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

如何安装 @camptocamp/inkmap?

在项目目录运行 npm install @camptocamp/inkmap,或使用 pnpm add / yarn add / bun add。

@camptocamp/inkmap 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/camptocamp__inkmap 是否存在。

@camptocamp/inkmap 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@camptocamp/inkmap 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@camptocamp/inkmap 可以商用吗?

@camptocamp/inkmap 使用 SEE LICENSE IN LICENSE.txt 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@camptocamp/inkmap 的下载量有多少?

根据 npm 官方下载统计,@camptocamp/inkmap 在 2026/10/09 – 2026/11/07 这 30 天内被下载 2,712 次,日均约 90 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@camptocamp/inkmap 还在维护吗?

最新版本 2.0.0 发布于 2025/09/10(1.2 年前);至今共发布 11 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/02/18。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。