@geoql/maplibre-gl-starfield

中文文档
0.1.4发布于 2026/10/29MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 2477

A MapLibre GL JS custom layer for rendering a Three.js starfield skybox with galaxy panorama

原始使用文档
文档目录10 节
  1. Installation
  2. Usage
  3. Options
  4. Galaxy Texture
  5. How It Works
  6. Exports
  7. Requirements
  8. Contributing
  9. More from the author
  10. License

@geoql/maplibre-gl-starfield

Three.js starfield skybox custom layer for MapLibre GL JS globe projections.

npm version JSR npm bundle size License: MIT

oxlint tsdown typescript

Live demo · npm · JSR

Renders an optional equirectangular galaxy/milky-way panorama texture with configurable brightness, plus thousands of individual point stars with additive blending. Perfect for globe-projection maps that need a space-like background — earthquake visualizations, satellite trackers, flight paths, and more.

Installation

# npm
npm install @geoql/maplibre-gl-starfield maplibre-gl three

# pnpm
pnpm add @geoql/maplibre-gl-starfield maplibre-gl three

# yarn
yarn add @geoql/maplibre-gl-starfield maplibre-gl three

# JSR
pnpm dlx jsr add @geoql/maplibre-gl-starfield

Usage

import * as maplibregl from 'maplibre-gl';
import { MaplibreStarfieldLayer } from '@geoql/maplibre-gl-starfield';
import 'maplibre-gl/dist/maplibre-gl.css';

const map = new maplibregl.Map({
  container: 'map',
  style: {
    version: 8,
    projection: { type: 'globe' },
    sources: {
      satellite: {
        type: 'raster',
        tiles: [
          'https://tiles.maps.eox.at/wmts/1.0.0/s2cloudless-2020_3857/default/g/{z}/{y}/{x}.jpg',
        ],
        tileSize: 256,
        attribution: '© EOX IT Services GmbH - S2 Cloudless',
      },
    },
    layers: [{ id: 'satellite', type: 'raster', source: 'satellite' }],
  },
  center: [0, 20],
  zoom: 1.5,
});

map.on('load', () => {
  const starfield = new MaplibreStarfieldLayer({
    galaxyTextureUrl: '/milkyway.jpg', // your panorama image
    galaxyBrightness: 0.35,
    starCount: 4000,
    starSize: 2.0,
  });

  // Add below all other layers so stars render behind the globe
  map.addLayer(starfield, map.getStyle().layers[0]?.id);
});

Options

interface MaplibreStarfieldLayerOptions {
  id?: string;
  starCount?: number;
  starSize?: number;
  starColor?: number;
  galaxyTextureUrl?: string;
  galaxyBrightness?: number;
}
OptionTypeDefaultDescription
idstring'starfield'Unique layer ID
starCountnumber4000Number of individual point stars
starSizenumber2.0Base point size for stars (randomized ±60%)
starColornumber0xffffffHex color for point stars
galaxyTextureUrlstringundefinedURL to an equirectangular panorama image. If omitted, only point stars render.
galaxyBrightnessnumber0.35Brightness multiplier for the galaxy texture (0–1)

Galaxy Texture

This library does not bundle a galaxy image. You need to provide your own equirectangular panorama via galaxyTextureUrl.

A great free option is the ESO/S. Brunier Milky Way panorama (source), licensed under CC BY 4.0. Download and resize to ~4096×2048 for a good balance of quality and file size:

# Download the 6000×3000 original (8 MB)
curl -o milkyway_full.jpg "https://cdn.eso.org/images/large/eso0932a.jpg"

# Resize to 4096×2048 (~3 MB)
sips --resampleWidth 4096 milkyway_full.jpg --out public/milkyway.jpg

Attribution: ESO/S. Brunier — CC BY 4.0

How It Works

The layer implements MapLibre's CustomLayerInterface and shares the WebGL context with MapLibre:

  1. Galaxy sphere — A Three.js SphereGeometry with BackSide rendering, textured with the panorama image. Rendered at near-infinite depth via a vertex shader trick.
  2. Point stars — Thousands of Points with per-vertex random size and opacity, rendered with additive blending for a natural glow.
  3. Camera sync — The projection matrix is decomposed from MapLibre's model-view-projection matrix, with translation stripped so the skybox stays at infinity regardless of zoom/pan.

Exports

// Main class
export { MaplibreStarfieldLayer } from '@geoql/maplibre-gl-starfield';

// Default export (same class)
export { default } from '@geoql/maplibre-gl-starfield';

// Types
export type { MaplibreStarfieldLayerOptions } from '@geoql/maplibre-gl-starfield';

Requirements

  • MapLibre GL JS >= 3.0.0
  • Three.js >= 0.135.0
  • Node.js >= 24.0.0

Contributing

  1. Fork and create a feature branch from main
  2. Make changes following conventional commits
  3. Ensure commits are signed (why?)
  4. Submit a PR
pnpm install
pnpm run build
pnpm run lint
pnpm run typecheck

The demo lives in example/ and runs on a Cloudflare Worker at maplibre-gl-starfield.geoql.in. Use Node 26 or later.

pnpm run dev:demo     # local dev server
pnpm run build:demo   # build the library, then the demo
pnpm run deploy:demo  # build and deploy the Worker (needs wrangler login)

More from the author

See every project at vinayakkulkarni.dev/projects and geoql.in.

License

MIT

版本与发布记录

@geoql/maplibre-gl-starfield 共发布 7 个版本,首次发布于 2026/02/08;过去 12 个月发布了 7 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.4latest2026/10/2917 天前
0.1.32026/10/2819 天前
0.1.22026/08/153 个月前
0.1.12026/02/248 个月前
0.1.02026/02/208 个月前
0.0.22026/02/089 个月前

关于 @geoql/maplibre-gl-starfield 的常见问题

@geoql/maplibre-gl-starfield 是什么?

A MapLibre GL JS custom layer for rendering a Three.js starfield skybox with galaxy panorama

如何安装 @geoql/maplibre-gl-starfield?

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

@geoql/maplibre-gl-starfield 支持 TypeScript 吗?

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

@geoql/maplibre-gl-starfield 支持 ESM 还是 CommonJS?

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

@geoql/maplibre-gl-starfield 需要什么版本的 Node.js?

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

@geoql/maplibre-gl-starfield 可以商用吗?

@geoql/maplibre-gl-starfield 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@geoql/maplibre-gl-starfield 的下载量有多少?

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

@geoql/maplibre-gl-starfield 还在维护吗?

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