npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

map3d-package

v1.0.0

Published

A JavaScript library for encapsulating Cesium 3D map operations

Readme

Map3D - Cesium三维操作封装库

一个用于封装Cesium三维地图操作的JavaScript库,提供了简洁易用的API来操作Cesium三维场景。

功能特性

  • 核心初始化 - 封装Cesium Viewer的初始化和管理
  • 3D Tiles - 支持加载和管理3D Tiles数据
  • GeoJSON - 支持加载和显示GeoJSON数据
  • KML/CZML - 支持KML和CZML格式数据
  • 影像服务 - 封装多种影像数据源(OpenStreetMap、天地图、高德地图等)
  • 地形服务 - 封装多种地形数据源
  • 实体管理 - 便捷的实体创建和管理API

安装

通过 npm 安装(推荐)

npm install map3d-package

从源码安装

git clone <repository-url>
cd map3d-packages
npm install

快速开始

方式一:在浏览器中使用(通过 CDN)

<!DOCTYPE html>
<html>
<head>
  <link href="https://unpkg.com/[email protected]/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
</head>
<body>
  <div id="cesiumContainer"></div>
  
  <script type="importmap">
    {
      "imports": {
        "map3d-package": "https://esm.sh/[email protected]",
        "cesium": "https://esm.sh/[email protected]"
      }
    }
  </script>
  
  <script type="module">
    import { Map3D, EntityManager } from "map3d-package";
    import * as Cesium from "cesium";
    
    const map3d = new Map3D("cesiumContainer", {
      token: "YOUR_CESIUM_ION_TOKEN"
    });
  </script>
</body>
</html>

方式二:在 Node.js 项目中使用

npm install map3d-package cesium
import { Map3D, Tileset, GeoJSONSource, EntityManager } from 'map3d-package';
import * as Cesium from 'cesium';

方式三:从源码引入

import { Map3D, Tileset, GeoJSONSource, EntityManager } from './src/index.js';
import * as Cesium from 'cesium';

2. 初始化地图

const map3d = new Map3D('cesiumContainer', {
    token: 'YOUR_CESIUM_ION_TOKEN', // 可选,Cesium Ion访问令牌
    viewerOptions: {
        terrainProvider: Cesium.createWorldTerrain()
    }
});

3. 加载数据源

// 加载3D Tiles
const tileset = new Tileset('https://your-tileset-url/tileset.json');
tileset.addToScene(map3d.getScene());

// 加载GeoJSON
const geoJSONSource = new GeoJSONSource('https://your-geojson-url.geojson');
await geoJSONSource.init();
map3d.addDataSource(geoJSONSource);

4. 添加实体

const entityManager = new EntityManager(map3d.getViewer());

// 添加点
entityManager.addPoint('point1', 116.3974, 39.9093, 0, {
    pixelSize: 20,
    color: Cesium.Color.RED,
    label: { text: '标记点' }
});

API文档

Map3D (核心类)

构造函数

new Map3D(container, options)

主要方法

  • getViewer() - 获取Cesium Viewer实例
  • getScene() - 获取场景对象
  • getCamera() - 获取相机对象
  • setCameraPosition(longitude, latitude, height, options) - 设置相机位置
  • flyTo(longitude, latitude, height, options) - 飞行到指定位置
  • addDataSource(dataSource) - 添加数据源
  • removeDataSource(dataSource) - 移除数据源
  • clearDataSources() - 清除所有数据源
  • destroy() - 销毁地图实例

Tileset (3D Tiles)

const tileset = new Tileset(url, options);
tileset.addToScene(scene);
await tileset.flyTo(viewer);

GeoJSONSource (GeoJSON数据源)

const geoJSONSource = new GeoJSONSource(data, options);
await geoJSONSource.init();
map3d.addDataSource(geoJSONSource);

EntityManager (实体管理器)

const entityManager = new EntityManager(viewer);

// 添加点
entityManager.addPoint(id, lon, lat, height, options);

// 添加线
entityManager.addPolyline(id, positions, options);

// 添加面
entityManager.addPolygon(id, positions, options);

// 添加3D模型
entityManager.addModel(id, lon, lat, height, modelUrl, options);

ImageryProvider (影像服务)

// OpenStreetMap
const osm = ImageryProvider.createOpenStreetMap();

// 天地图
const tianditu = ImageryProvider.createTianditu('vec', { token: 'YOUR_TOKEN' });

// 高德地图
const gaode = ImageryProvider.createGaode('img');

TerrainProvider (地形服务)

// Cesium World Terrain
const terrain = TerrainProvider.createWorldTerrain();

// 椭球体
const ellipsoid = TerrainProvider.createEllipsoid();

项目结构

Map3D/
├── src/
│   ├── core/
│   │   └── Map3D.js          # 核心地图类
│   ├── datasource/
│   │   ├── Tileset.js        # 3D Tiles封装
│   │   ├── GeoJSONSource.js  # GeoJSON封装
│   │   ├── KMLSource.js      # KML封装
│   │   ├── CZMLSource.js     # CZML封装
│   │   ├── ImageryProvider.js # 影像服务封装
│   │   ├── TerrainProvider.js # 地形服务封装
│   │   └── EntityManager.js   # 实体管理
│   └── index.js              # 主入口文件
├── examples/                 # 使用示例
├── package.json
└── README.md

示例

查看 examples/ 目录下的示例代码。

依赖

  • Cesium ^1.136.0

许可证

ISC

作者

plr