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

cesium-3d-tools

v1.1.0

Published

Cesium 三维地图工具包,包含标尺工具、坐标转换、工作面裁剪工具(ClipTool)、月进尺绘制等功能

Downloads

899

Readme

cesium-3d-tools

Cesium 三维地图工具包,包含标尺工具、坐标转换等功能,支持 CGCS2000 坐标系转换和标尺绘制。

安装

npm install cesium-3d-tools
# 或
yarn add cesium-3d-tools

依赖说明

必需依赖

  1. proj4 - 坐标转换库(会自动安装)

  2. Cesium - 三维地图库(需要你自己提供)

    方式一:通过 CDN 引入(推荐)

    <link href="https://cesium.com/downloads/cesiumjs/releases/1.95/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
    <script src="https://cesium.com/downloads/cesiumjs/releases/1.95/Build/Cesium/Cesium.js"></script>

    方式二:通过 npm 安装

    npm install cesium

使用方法

方式1:CDN 引入 Cesium(最简单)

<!-- index.html -->
<link href="https://cesium.com/downloads/cesiumjs/releases/1.95/Build/Cesium/Widgets/widgets.css" rel="stylesheet">
<script src="https://cesium.com/downloads/cesiumjs/releases/1.95/Build/Cesium/Cesium.js"></script>
// main.js
import RulerTool from 'cesium-3d-tools'

// window.Cesium 已经存在(CDN 引入的)
const viewer = new Cesium.Viewer('cesiumContainer')

// 创建标尺工具(不传 Cesium,自动从 window.Cesium 获取)
const rulerTool = new RulerTool(viewer)

// 使用标尺工具
const lineData = {
  id: 'line-001',
  polylineName: '测试标尺',
  platform3dPolylineCoordinatesList: [
    { coordinateName: 'start', coordinateX: 36420298, coordinateY: 4354401, coordinateZ: 878 },
    { coordinateName: 'end', coordinateX: 36419038, coordinateY: 4355592, coordinateZ: 885 }
  ]
}

rulerTool.calculateRulerCoordinates(lineData)

方式2:npm 安装 Cesium

npm install cesium cesium-ruler-tool
// main.js
import * as Cesium from 'cesium'
import RulerTool from 'cesium-3d-tools'

const viewer = new Cesium.Viewer('cesiumContainer')

// 创建标尺工具(传入 Cesium 对象)
const rulerTool = new RulerTool(viewer, Cesium)

// 使用标尺工具
rulerTool.calculateRulerCoordinates(lineData)

API 文档

RulerTool

构造函数

new RulerTool(viewer, Cesium)
  • viewer (必需): Cesium.Viewer 实例
  • Cesium (可选): Cesium 对象,如果不传则自动从 window.Cesium 获取

方法

calculateRulerCoordinates(line)

计算标尺坐标点(每隔1米)并自动绘制标尺。

参数:

  • line (Object): polyline 对象
    • id (String): 标尺ID
    • polylineName (String): 标尺名称
    • platform3dPolylineCoordinatesList (Array): 坐标点数组
      • coordinateName (String): 'start' | 'end' | 其他(中间点)
      • coordinateX (Number): X 坐标
      • coordinateY (Number): Y 坐标
      • coordinateZ (Number): Z 坐标(高度)
    • objectCode (String, 可选): 对象编码
    • layerCode (String, 可选): 图层编码

示例:

const lineData = {
  id: 'line-001',
  polylineName: '测试标尺',
  platform3dPolylineCoordinatesList: [
    { coordinateName: 'start', coordinateX: 36420298, coordinateY: 4354401, coordinateZ: 878 },
    { coordinateName: 'end', coordinateX: 36419038, coordinateY: 4355592, coordinateZ: 885 }
  ]
}

rulerTool.calculateRulerCoordinates(lineData)
addReadyRuler(name, scale, heading, width, leftOrRight, data, layerCode)

添加标尺到地图。

参数:

  • name (String): 标尺名称
  • scale (Number): 刻度间隔(米),默认50米
  • heading (Number): 朝向(弧度)
  • width (Number): 刻度宽度,默认10米
  • leftOrRight (String | null): 左右方向,'right' 或 null
  • data (Array): 坐标点数组 [{index, longitude, latitude, height}, ...]
  • layerCode (String | null): 图层编码(可选)

Bj54TransferRuler

坐标转换工具类。

方法

conversionMethod(longitude, latitude, sourceEPSG, targetEPSG)

坐标转换方法。

参数:

  • longitude (Number): 经度/X坐标
  • latitude (Number): 纬度/Y坐标
  • sourceEPSG (Number): 源坐标系 EPSG 代码(如 4524)
  • targetEPSG (Number): 目标坐标系 EPSG 代码(如 4326)

返回:

  • Array: [x, y] 转换后的坐标

示例:

import { Bj54TransferRuler } from 'cesium-3d-tools'

const transfer = new Bj54TransferRuler()
// CGCS2000 (4524) 转 WGS84 (4326)
const result = transfer.conversionMethod(36420298, 4354401, 4524, 4326)
console.log(result) // [经度, 纬度]

支持的坐标系

  • EPSG:4524: CGCS2000坐标系(108度中央经线,x_0=36500000)
  • EPSG:4326: WGS84经纬度

注意事项

  1. Cesium 必须在使用前加载完成
  2. 如果通过 CDN 引入 Cesium,确保 window.Cesium 存在
  3. 如果通过 npm 安装 Cesium,需要将 Cesium 对象传入构造函数

License

MIT