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 🙏

© 2025 – Pkg Stats / Ryan Hefner

ecef

v2.0.0

Published

High-performance ECEF Coordinate Conversion Library (Based on Simplified Spherical Model)

Downloads

37

Readme

ecef

高性能 ECEF 坐标转换库(基于简化球模型)

支持 JWH(经纬度高程)与 XYZ(ECEF)坐标双向转换,提供单个坐标转换和批量 Float64Array 转换接口。

特性

  • 支持多种模块格式:ESM、CJS 和 IIFE。
  • 提供单个坐标和批量数据的高效转换。
  • 内置单位法向量计算、距离计算等辅助功能。
  • 严格的输入校验,确保数据有效性。

安装

使用 npm 或 yarn

npm install ecef

或者

yarn add ecef

直接引入 UMD 构建文件

你可以通过 <script> 标签直接在浏览器中使用本库,全局变量名为 ecef

<script src="https://unpkg.com/ecef/dist/ecef.iife.js"></script>
<script>
  const jwh = { longitude: 120, latitude: 30, height: 0 };
  const xyz = ecef.fromDegree(jwh);
  console.log(xyz);
</script>

使用方法

ESM 和 CJS

引入模块

// ESM
import { fromDegree, toDegree, distance } from 'ecef';

// CJS
const { fromDegree, toDegree, distance } = require('ecef');

示例代码

将大地坐标(JWH)转换为 ECEF 坐标(XYZ):

const jwh = { longitude: 120, latitude: 30, height: 0 };
const xyz = fromDegree(jwh);
console.log(xyz); // { x, y, z }

将 ECEF 坐标(XYZ)转换为大地坐标(JWH):

const xyz = { x: 1000000, y: 2000000, z: 3000000 };
const jwh = toDegree(xyz);
console.log(jwh); // { longitude, latitude, height }

计算两个 ECEF 坐标之间的直线距离:

const pointA = { x: 1000000, y: 2000000, z: 3000000 };
const pointB = { x: 1500000, y: 2500000, z: 3500000 };
const dist = distance(pointA, pointB);
console.log(dist); // 距离(米)

IIFE(浏览器环境)

在浏览器环境中,可以通过全局变量 ecef 使用所有导出的方法:

<script src="https://unpkg.com/ecef/dist/ecef.iife.js"></script>
<script>
  const jwh = { longitude: 120, latitude: 30, height: 0 };
  const xyz = ecef.fromDegree(jwh);
  console.log(xyz);

  const jwhBack = ecef.toDegree(xyz);
  console.log(jwhBack);

  const pointA = { x: 1000000, y: 2000000, z: 3000000 };
  const pointB = { x: 1500000, y: 2500000, z: 3500000 };
  const dist = ecef.distance(pointA, pointB);
  console.log(dist);
</script>

API 文档

核心转换函数

  • fromDegree(jwh: JWH, radius?: number): XYZ
    将大地坐标(JWH)转换为 ECEF 坐标(XYZ)。
    参数:

    • jwh: 大地坐标对象 { longitude, latitude, height }
    • radius: 球体半径,默认为 SphereRadius.WGS84_SEMIMAJOR
  • toDegree(xyz: XYZ, radius?: number): JWH
    将 ECEF 坐标(XYZ)转换为大地坐标(JWH)。
    参数:

    • xyz: ECEF 坐标对象 { x, y, z }
    • radius: 球体半径,默认为 SphereRadius.WGS84_SEMIMAJOR

批量处理函数

  • fromDegrees(jwhArray: Float64Array, radius?: number): Float64Array
    批量将大地坐标数组转换为 ECEF 坐标数组。
    输入格式:[longitude0, latitude0, height0, ...]
    输出格式:[x0, y0, z0, ...]

  • toDegrees(xyzArray: Float64Array, radius?: number): Float64Array
    批量将 ECEF 坐标数组转换为大地坐标数组。
    输入格式:[x0, y0, z0, ...]
    输出格式:[longitude0, latitude0, height0, ...]

辅助计算函数

  • distance(a: XYZ, b: XYZ): number
    计算两个 ECEF 坐标之间的直线距离。

  • center(points: XYZ[]): XYZ
    计算多个 ECEF 坐标的中心点。

  • distanceArray(a: Float64Array, b: Float64Array): number
    计算两个 Float64Array 存储的 ECEF 坐标之间的距离。

类型检查工具

  • isJWH(value: unknown): boolean
    检查是否为有效的大地坐标对象。

  • isXYZ(value: unknown): boolean
    检查是否为有效的 ECEF 坐标对象。

许可证

MIT