@geoql/ maplibre-gl-starfield (英语)
三.js 星地天盒自定义层 MapLibre GL 联合来文 地球预测.
将可选的等角星系/密道全景纹理与可配置的亮度相接,再用添加剂混合成上千个个点星. 适合需要类似空间背景的地球投影图——地震可视化,卫星跟踪仪,飞行路径等等.
安装
# 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
使用量
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);
});
选项
interface MaplibreStarfieldLayerOptions {
id?: string;
starCount?: number;
starSize?: number;
starColor?: number;
galaxyTextureUrl?: string;
galaxyBrightness?: number;
}
| 选项 | 类型 | 默认 | 说明 |
|---|---|---|---|
id | string | 'starfield' | 独特的层 ID |
starCount | number | 4000 | 单个点星数 |
starSize | number | 2.0 | 恒星基点大小(随机±60%) |
starColor | number | 0xffffff | 点星的正弦颜色 |
galaxyTextureUrl | string | undefined | URL 到正方形全景图像 。 如果省去,则只让点星渲染出. |
galaxyBrightness | number | 0.35 | 银河纹理的亮度乘以 (0-1) |
银河纹理
这个图书馆的确是 没有 捆绑一个银河系图像。 您需要通过 galaxyTextureUrl。 。 。 .
一个伟大的自由选择是 ESO/S. Brunier 银河全景 (单位:千美元)来源),根据 CC BY 4.0 (英语)。为了在质量和文件大小方面保持良好的平衡,下载并调整大小为~4096x2048:
# 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
归属:ESO/S.布鲁尼尔 - CC BY 4.0 (英语)
如何运作
该图层执行 MapLibre 的 CustomLayerInterface 并和 MapLibre 共享 WebGL 上下文 :
- 银河系 -一个三.js
SphereGeometry与BackSide渲染, 以全景图像纹理 。 通过顶点遮蔽术在接近无限深度的地方被渲染出. - 点星 (单位:千美元)
Points以天然发光的添加剂混合制成. - 相机同步 ——投影矩阵从MapLibre的模型-视图-投影矩阵中分解出,并脱去翻译,因此无论缩放/平放,天盒都保持无限.
出口
// 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';
所需资源
- MapLibre GL 联合来文
- 三.js 0.135.0 (韩语)
- 节点.js 24.0.0
捐款
pnpm install
pnpm run build
pnpm run lint
pnpm run typecheck
演示会住在这里 example/ 并运行在云浮工人在
马图利布尔-gl-starfield.geoql.in。使用节点 26
或后会.
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)
更多来自作者
- 映射- gl- snow — WebGPU 雪粒层
- 映射- gl- 风 ——风粒子动画层
- 映射- gl- 比较 ——刷卡式地图对比控制
- 映射- gl- 检查 检查矢量瓦片特征及其属性
- v 地图 用于 MapLibre GL 的 50+ Vue 3 组件
- 映射图 复制到应用程序中的 shadcn- vue 映射组件
见每个项目 vinayakkulkarni.dev/项目 财务报告和审定财务报表 地理单位。 。 。 .