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

@maptec/maptec-spatial

v0.2.0

Published

Maptec geometry library for spatial relationships

Readme

@maptec/maptec-spatial

Maptec 几何空间关系库。用于判断点、线、面之间的空间关系,多数方法返回 boolean

本库负责计算;地图展示与高亮请使用 @maptec/maptec-js

安装

npm install @maptec/maptec-spatial

或:

pnpm add @maptec/maptec-spatial

在项目中使用(推荐:打包工具)

import {GeoUtils} from '@maptec/maptec-spatial';

const point = {type: 'Point', coordinates: [103.86, 1.32]};
const polygon = {
  type: 'Polygon',
  coordinates: [[
    [103.84, 1.30],
    [103.88, 1.30],
    [103.88, 1.34],
    [103.84, 1.34],
    [103.84, 1.30],
  ]],
};

const isInPolygon = GeoUtils.pointInPolygon(point, polygon);
console.log(isInPolygon);

const route = {
  type: 'LineString',
  coordinates: [[103.82, 1.31], [103.90, 1.33]],
};
const doesRouteEnterZone = GeoUtils.intersects(route, polygon);
console.log(doesRouteEnterZone);

也可直接传入 Maptec 覆盖物(需实现 toGeoJSON())或 Marker:

const isIntersecting = GeoUtils.intersects(polygonOverlayA, polygonOverlayB);
console.log(isIntersecting);

const isMarkerInFence = GeoUtils.pointInPolygon(marker, fencePolygonOverlay);
console.log(isMarkerInFence);

通过 CDN 引入(UMD,全局变量 MaptecSpatial

unpkg

<!doctype html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Maptec Spatial CDN Demo</title>
  </head>
  <body>
    <script src="https://unpkg.com/@maptec/maptec-spatial/dist/MaptecSpatial.js"></script>
    <script>
      const point = {type: 'Point', coordinates: [103.86, 1.32]};
      const polygon = {
        type: 'Polygon',
        coordinates: [[
          [103.84, 1.30],
          [103.88, 1.30],
          [103.88, 1.34],
          [103.84, 1.34],
          [103.84, 1.30],
        ]],
      };

      const isInPolygon = MaptecSpatial.GeoUtils.pointInPolygon(point, polygon);
      console.log(isInPolygon);
    </script>
  </body>
</html>

jsDelivr

<script src="https://cdn.jsdelivr.net/npm/@maptec/maptec-spatial/dist/MaptecSpatial.js"></script>
<script>
  const isInPolygon = MaptecSpatial.GeoUtils.pointInPolygon(point, polygon);
  console.log(isInPolygon);
</script>

常用地址:

| 用途 | unpkg | jsDelivr | |---|---|---| | UMD 主包 | https://unpkg.com/@maptec/maptec-spatial/dist/MaptecSpatial.js | https://cdn.jsdelivr.net/npm/@maptec/maptec-spatial/dist/MaptecSpatial.js | | ESM | https://unpkg.com/@maptec/maptec-spatial/dist/MaptecSpatial.esm.js | https://cdn.jsdelivr.net/npm/@maptec/maptec-spatial/dist/MaptecSpatial.esm.js |

锁定版本示例(推荐生产环境):

<script src="https://cdn.jsdelivr.net/npm/@maptec/[email protected]/dist/MaptecSpatial.js"></script>

常用方法

| 方法 | 含义 | |---|---| | intersects / disjoint | 相交 / 相离 | | touches / crosses / overlaps | 接触 / 穿越 / 重叠 | | contains / within | 严格包含 / 严格位于内部(不含边界) | | covers / coveredBy | 覆盖(含边界) | | equals | 拓扑相等 | | pointInPolygon / pointOnLine | 点在面 / 点在线 | | filterByRelation | 一对多筛选 | | findRelatedByRelation | 多源各自关联目标集合 |

按几何组合查阅

| 组合 | 推荐方法 | |---|---| | 点 × 面 | pointInPolygon / covers(含边界);严格内部用 within / contains | | 点 × 线 | pointOnLine(可带米级容差) | | 线 × 面 | intersects / within / crosses | | 线 × 线 | intersects / crosses / touches | | 面 × 面 | intersects / overlaps / contains |

常见问题

  • 浏览器里怎么拿到对象?:CDN / UMD 会暴露全局 MaptecSpatial;打包工具使用 import {GeoUtils} from '@maptec/maptec-spatial'
  • 和 Maptec 地图库什么关系?:本库只做几何关系计算,不负责渲染;展示与高亮请配合 @maptec/maptec-js

License

BSD-3-Clause,详见 LICENSE

开发

npm install
npm test
npm run build

产物:

  • dist/MaptecSpatial.js — 浏览器 UMD(全局 MaptecSpatial
  • dist/MaptecSpatial.esm.js — ESM
  • dist/MaptecSpatial.cjs — CommonJS
  • dist/types/ — 类型声明

示例:

npm run demo:prepare

然后用 Live Server 打开(本仓库端口 5504):

  • demo/SpatialRelationsBasic.html — 按「点×面 / 点×线 / 线×面 / 线×线 / 面×面」分类演示
  • demo/SpatialRelationsBatch.html — 点×面批量筛选

Maptec 资源会同步到 demo/lib/

API 文档

npm run docs          # 生成到 docs/api/
npm run docs:serve    # 生成并在 http://localhost:8000 打开