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

amap-toolkit

v0.0.7-beta13

Published

高德地图图形绘制工具扩展,支持多边形测距、多边形编辑器测距、矩形编辑器等

Readme

高德未支持工具封装

安装

npm install amap-toolkit

使用

import AMapToolkit from "amap-toolkit";

const mapIns = new AMap.Map("container");

const polygonRangingIns = new AMapToolkit.PolygonRanging(mapIns);

// 或者直接使用部分功能
import { PolygonRanging } from "amap-toolkit";

const mapIns = new AMap.Map("container");

const polygonRangingIns = new PolygonRanging(mapIns);

polygonRangingIns.open(); // .start() 也可以

本地运行

git clone https://github.com/MeetTheBest/amap-toolkit.git

cd amap-toolkit

npm install

npm run dev

# node 版本需要大于 v16.19.1
# 已安装 nvm 情况下,根目录下执行 nvm use 切换 node 版本

通用 API

| 参数 | 说明 | 类型 | | --------- | ------------ | ---------------------- | | start | 启用相应能力 | instance.start(arg?) | | stop | 停止相应能力 | instance.stop() | | destroy | 销毁相应能力 | instance.destroy() |

多边形类工具

多边形测距 PolygonRanging

示例

import { PolygonRanging } from "amap-toolkit";

const mapIns = new AMap.Map("container");

const polygonRangingIns = new PolygonRanging(mapIns);

const polygon = new AMap.Polygon({});

// 开启测距
polygonRangingIns.start(polygon);

// 适当时机销毁测距(如组件的 destroy 生命周期)
polygonRangingIns.destroy();

多边形测距

多边形绘制时测距 PolygonRangingInDrawing

示例

import { PolygonRangingInDrawing } from "amap-toolkit";

const mapIns = new AMap.Map("container");

const polygonRangingIns = new PolygonRangingInDrawing(mapIns);

const mouseTool = new AMap.MouseTool({});

mouseTool.on("draw", () => {
    // 绘制完成后,需要停止
    polygonRangingIns.stop();
});

// 开始绘制多边形
mouseTool.polygon();

// 开启测距
polygonRangingIns.start();

// 适当时机销毁测距(如组件的 destroy 生命周期)
polygonRangingIns.destroy();

多边形绘制时测距

多边形编辑器测距 PolygonEditorRanging

示例

import { PolygonEditorRanging } from "amap-toolkit";

const mapIns = new AMap.Map("container");

const polygon = new AMap.Polygon({});

const editor = new AMap.PolygonEditor(mapIns, polygon);

const polygonEditorRangingIns = new PolygonEditorRanging(mapIns);

// 开启测距
polygonEditorRangingIns.start(editor);

// 适当时机停止测距
polygonEditorRangingIns.stop();

// 适当时机销毁测距(如组件的 destroy 生命周期)
polygonEditorRangingIns.destroy();

多边形编辑器测距

PolygonEditorEvent 多边形编辑器操作点事件

为什么要做这个?因为高德的 PolygonEditoradjust 事件,只支持在操作点位结束后响应,并且响应的内容是当前编辑的多边形。

示例

import { PolygonEditorEvent } from "amap-toolkit";

const mapIns = new AMap.Map("container");

const polygon = new AMap.Polygon({});

const editor = new AMap.PolygonEditor(mapIns, polygon);
editor.open();

const polygonEditorEventIns = new PolygonEditorEvent(editor);

polygonEditorEventIns.on("mousedown", (target) => {
    console.log("当前鼠标按下点位", target);
});

polygonEditorEventIns.on("mousemove", (target) => {
    console.log("当前移动点位", target);
});

polygonEditorEventIns.on("mouseup", (target) => {
    console.log("当前鼠标松开点位", target);
});

// 适当时机销毁测距(如组件的 destroy 生命周期)
polygonEditorEventIns.clearAll();

多边形编辑器事件

API

| 参数 | 说明 | 类型 | | -------- | -------------------------------------------- | --------------------------------------------------------------------------------------------------- | | on | 监听指定事件 | on(eventName: mousedown \| mousemove \| mouseup, callback: (target: AMap.CircleMarker) => void) | | off | 移除指定事件 | off(eventName: mousedown \| mousemove \| mouseup, callback: (target: AMap.CircleMarker) => void) | | once | 监听指定事件行为,触发一次后自动移除 | once(eventName: mousedown \| mousemove \| mouseup, callback: (target: AMap.CircleMarker) => void) | | clearAll | 移除指定事件监听,eventName 不传则移除全部 | clearAll(eventName?: mousedown \| mousemove \| mouseup) |

类矩形

为什么要做这个?因为高德的 Rectangle 是通过2点(西南点和东北点)创建矩形,所以无法创建出非水平方向的矩形,且不支持旋转功能;

示例

import { LikeRectangle } from "amap-toolkit";

const mapIns = new AMap.Map("container");

const likeRectangleOptions = {
    map: mapIns,
    center: [116.400274, 39.905812] as [number, number],
    width: 200,
    height: 50,
    draggable: true,
    cursor: "pointer",
    fillOpacity: 0.3,
    strokeOpacity: 0.8,
    rotatable: true,
    bubble: true, // 事件穿透
};

// 使用 ts 时,地图会校验没有 LikeRectangle 类型
polygon = new LikeRectangle(likeRectangleOptions)! as unknown as AMap.Polygon;

mapIns.add([polygon]);

类矩形

API

| 参数 | 说明 | 类型 | | ------ | -------------------------------- | ---------------------------------- | | path | 矩形的 4 个点经纬度 | [LngLat, LngLat, LngLat, LngLat] | | center | 中心点(宽+高+中心点创建必传) | LngLat | | width | 宽度(使用中心点创建必传) | number | | height | 高度(使用中心点创建必传) | number |

类矩形编辑

示例

import { LikeRectangle, LikeRectangleEditor } from "amap-toolkit";

const mapIns = new AMap.Map("container");

const likeRectangleOptions = {
    map: mapIns,
    center: [116.400274, 39.905812] as [number, number],
    width: 200,
    height: 50,
    draggable: true,
    cursor: "pointer",
    fillOpacity: 0.3,
    strokeOpacity: 0.8,
    rotatable: true,
    bubble: true, // 事件穿透
};

// 使用 ts 时,地图会校验没有 LikeRectangle 类型
polygon = new LikeRectangle(likeRectangleOptions)! as unknown as AMap.Polygon;

mapIns.add([polygon]);

likeRectangleEditorIns = new LikeRectangleEditor(
    mapIns!,
    likeRectangleIns as LikeRectangle,
    options, // options 配置如下
);
likeRectangleEditorIns.open();

类矩形

options API

| 参数 | 说明 | 类型 | | -------- | --------------------------- | ------------------------------------ | | onChange | 编辑器变化事件 | (type: string, data: any) => void; | | isMobile | 是否为移动端(默认false) | boolean |