@geoblocks/ol-maplibre-layer

中文文档
2.0.0发布于 2026/09/24BSD-3-ClauseTypeScriptES Module零依赖近 30 天下载 2.8万

Geoblocks to render a MapLibre GL JS map as an OpenLayers layer.

原始使用文档
文档目录6 节
  1. Installation
  2. Code example
  3. Online doc and demos
  4. Troubleshooting
  5. Local development
  6. Publish a new version to npm

MapLibre OpenLayers layer

Render a MapLibre GL JS map as an OpenLayers layer.

Installation

npm i @geoblocks/ol-maplibre-layer

OpenLayers and MapLibre GL JS are peer dependencies, so you need to install them too.

npm i ol maplibre-gl

Code example

import {MapLibreLayer} from '@geoblocks/ol-maplibre-layer';

const layer = new MapLibreLayer({
  opacity: 0.7,
  mapLibreOptions: {
    style: 'https://www.example.com/path/to/style.json',
  },
});

// ...
map.addLayer(layer);

All the properties passed to the construction (except mapLibreOptions) are used to create the OpenLayers layer. mapLibreOptions is used to create the MapLibre map.

The MapLibreLayer exposes the underlying MapLibre map as public property, so you can use it to interact with the map.

layer.maplibreMap.setStyle('https://www.example.com/path/to/other/style.json');

Online doc and demos

Troubleshooting

With MapLibre-GL v6, you have to set the worker manually, read the MapLibre v6 installation.

Local development

For local development we use a few demos.

npm install
npm run start
open http://localhost:1234

Publish a new version to npm

The source is transpiled to standard ES modules and published on npm.

# update CHANGES.md
npm version patch
npm publish
git push --tags origin master
npm run gh-pages

版本与发布记录

@geoblocks/ol-maplibre-layer 共发布 16 个版本,首次发布于 2021/09/01;过去 12 个月发布了 1 个版本。

版本发布日期距今
2.0.0latest2026/09/241 个月前
1.0.32025/01/131.8 年前
1.0.22024/11/252 年前
1.0.12024/08/152 年前
1.0.02024/05/232 年前
0.1.32024/02/022 年前

关于 @geoblocks/ol-maplibre-layer 的常见问题

@geoblocks/ol-maplibre-layer 是什么?

Geoblocks to render a MapLibre GL JS map as an OpenLayers layer.

如何安装 @geoblocks/ol-maplibre-layer?

在项目目录运行 npm install @geoblocks/ol-maplibre-layer,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:ol(^6 || ^7 || ^8 || ^9 || ^10)、maplibre-gl(>=5.11.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@geoblocks/ol-maplibre-layer 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@geoblocks/ol-maplibre-layer 支持 ESM 还是 CommonJS?

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

@geoblocks/ol-maplibre-layer 可以商用吗?

@geoblocks/ol-maplibre-layer 使用 BSD-3-Clause 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。另外不得用原作者名义为衍生产品背书。以上为概括,不构成法律意见,请以许可原文为准。

@geoblocks/ol-maplibre-layer 的下载量有多少?

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

@geoblocks/ol-maplibre-layer 还在维护吗?

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