AGENT SKILL

amap-jsapi-skill

高德地图 JSAPI v2.0 (WebGL) 开发技能。涵盖地图生命周期管理、强制安全配置、3D 视图控制、覆盖物绘制及 LBS 服务集成。

License 许可
MIT
最近更新
2026-09-30
Stars
★ 3
Forks
0

01 前言 Front Matter

name
amap-jsapi-skill
license
MIT
version
1.1.1
homepage
https://lbs.amap.com
metadata
{ "openclaw": { "requires": { "env": [ "AMAP_JSAPI_KEY", "AMAP_SECURITY_JS_CODE" ] }, "primaryEnv": "AMAP_JSAPI_KEY" } }
description
高德地图 JSAPI v2.0 (WebGL) 开发技能。涵盖地图生命周期管理、强制安全配置、3D 视图控制、覆盖物绘制及 LBS 服务集成。
display_name
Gaode Map JSAPI - 高德官方 JavaScript SDK Skill

02 资源文件 34

03 SKILL.md 正文

高德地图 JSAPI v2.0 开发技能

本指南包含地图初始化、覆盖物、事件、图层等核心模块的 API 说明和代码示例,旨在帮助开发者快速集成高德地图并遵循正确的使用方式。

快速开始

1. 引入加载器

使用 script 标签加载 loader.js:

<script src="https://webapi.amap.com/loader.js"></script>

2. 安全密钥配置 (强制)

重要:自 v2.0 起,必须在加载地图前配置安全密钥,否则无法通过鉴权。详情及后端代理示例请参考 安全策略。

安全提示:安全密钥属于敏感凭据,请通过环境变量 AMAP_SECURITY_JS_CODE 传入,禁止在代码中硬编码。生产环境务必使用 serviceHost 代理方式,避免前端暴露密钥。

// 在调用 AMapLoader.load 前执行
window._AMapSecurityConfig = {
  securityJsCode: process.env.AMAP_SECURITY_JS_CODE, // 通过环境变量安全获取
  // serviceHost: 'https://your-proxy-domain/_AMapService', // 生产环境:建议使用代理转发
};

3. 初始化地图

import AMapLoader from '@amap/amap-jsapi-loader';
AMapLoader.load({
    key: '您的Web端开发者Key', // 必填
    version: '2.0',           // 指定版本
    plugins: ['AMap.Scale', 'AMap.ToolBar'] // 预加载插件
}).then((AMap) => {
    // 可选:设置应用标识,用于 API 调用来源统计
    AMap.getConfig().appname = 'amap-jsapi-skill';

    const map = new AMap.Map('container', {
        viewMode: '3D',       // 开启3D视图
        zoom: 11,             // 初始缩放级别
        center: [116.39, 39.90] // 初始中心点
    });
    map.addControl(new AMap.Scale());
}).catch(e => console.error(e));

场景示例

地图控制

  • 生命周期:references/map-init.md - 掌握 load、Map 实例创建及 destroy 销毁流程。
  • 视图交互:references/view-control.md - 控制 zoom (缩放)、center (平移)、pitch (俯仰)、rotation (旋转)。

覆盖物绘制

  • 点标记:references/marker.md - 使用 Marker (基础)、LabelMarker (海量避让) 标注位置。
  • 矢量图形:references/vector-graphics.md - 绘制 Polyline (轨迹、线)、Polygon (区域、面)、Circle (范围、圆)。
  • 信息展示:references/info-window.md - 通过 InfoWindow 展示详细信息。
  • 右键菜单:references/context-menu.md - 自定义地图或覆盖物的右键交互。

图层管理

  • 基础图层:references/layers.md - 标准、卫星、路网及 3D 楼块图层。
  • 自有数据:references/custom-layers.md - 集成 Canvas、WMS/WMTS, GLCustomLayer 地图上叠加 Canvas、WMS图层、 Threejs图层。

服务与插件

  • LBS 服务:
    • references/geocoder.md - 地理编码/逆地理编码(地址/坐标互转)。
    • references/routing.md - 路径规划(驾车/步行/公交)。
    • references/search.md - POI 搜索与输入提示。
  • 事件系统:references/events.md - 响应点击、拖拽、缩放等交互事件。

最佳实践

  1. 安全第一:生产环境务必使用代理服务器转发 serviceHost,避免 securityJsCode 泄露。
  2. 按需加载:仅在 plugins 中声明需要的插件,减少首屏资源体积。
  3. 资源释放:组件卸载时务必调用 map.destroy(),防止 WebGL 上下文内存泄漏。

API Reference

JSAPI 文档分为以下几个类别:

Foundation Classes

LngLat / Bounds / Pixel / Size

Information Window

InfoWindow

Events

Event

Map

Map / MapsEvent

Official Layers

TileLayer / Traffic / Satellite / RoadNet / Buildings / DistrictLayer / IndoorMap

Standard Layers

WMS / WMTS / MapboxVectorTileLayer

Custom Layers

HeatMap / VectorLayer / LabelsLayer / CustomLayer / Flexible / ImageLayer / CanvasLayer / GLCustomLayer

Markers

Marker / Text / Icon / LabelMarker / ElasticMarker / MarkerCluster / MassMarks / MoveAnimation / AnimationCallback / EasingCallback

Context Menu

ContextMenu

Vector Graphics

Polygon / Polyline / BezierCurve / Circle / CircleMarker / Ellipse / Rectangle / GeoJSON

Overlay Groups

LayerGroup / OverlayGroup

Controls

Control / Scale / ToolBar / ControlBar / MapType / HawkEye

Tools

RangingTool / MouseTool / PolygonEditor / PolylineEditor / CircleEditor / BezierCurveEditor / EllipseEditor / RectangleEditor

Services

WebService / WebServiceCallback

Search

AutoComplete / AutoCompleteSearchCallback / PlaceSearch / searchCallback / CloudDataSearch / CloudDataSearchCallback

Geocoder

Geocoder / GeocoderCallback / ReGeocoderCallback / convertFrom

Routing

Driving / DrivingCallback / DrivingResult / DriveStepBasic / DriveStepDetail / TruckDriving / Walking / WalkingCallback / WalkingResult / Transfer / TransferCallback / TransferResult / Riding / RidingCallback / RidingResult / DragRoute / DragRouteTruck / GraspRoad / GraspRoadCallback

Other Services

DistrictSearch / Weather / WeatherLiveResult / WeatherForecastResult / StationSearch / LineSearch

Geolocation

Geolocation / GeolocationCallBack / GeolocationResult / CitySearch

Common Library

GeometryUtil / DomUtil / Browser / Util

使用 skills 必须遵循的规范

  1. 校验生成代码可用性:生成代码后必须进行自我校验,确保代码语法正确、逻辑完整且可以正常运行,禁止输出未经验证的代码。
  2. 本地文件放置规范:所有生成的项目文件必须放置在 openclaw workspace 目录下的 amap-jsapi/ 文件夹中。文件名统一使用 kebab-case 命名(如 map-init.html、layers-official.html)。
  3. appname 应用标识(推荐):建议在生成地图初始化代码时,在 AMapLoader.load().then() 回调中设置应用标识,用于 API 调用来源统计。规则如下:
    • 设置位置:AMapLoader.load({...}).then((AMap) => { 回调内部,new AMap.Map() 之前
    • 设置方式:AMap.getConfig().appname = 'amap-jsapi-skill';
    • 代码模板:
      AMapLoader.load({
        key: '您的Key',
        version: '2.0',
        plugins: [...]
      }).then((AMap) => {
        // 可选:设置应用标识,用于 API 调用来源统计
        AMap.getConfig().appname = 'amap-jsapi-skill';
      
        const map = new AMap.Map('container', { ... });
      });
      
    • 说明:此设置用于标识 API 调用来源,便于统计分析。开发者可根据需要决定是否保留。

如何使用

  1. 如果有相近的“场景示例”那么去阅读场景示例,再阅读场景示例中的涉及的类的api文档。再结合描述/场景示例/api 去完成任务。
  2. 在最终的完成任务前,检查用的api用法是否符合文档。

04 同仓库更多 Skills

Jinhong270
Jinhong270/AI-Agent

xlsx

Open, create, read, analyze, edit, repair, or validate spreadsheet files (.xlsx, .xlsm, .xltx, .csv, .tsv) with zero format loss, with first-class support for Chinese / CJK content. Use whenever the user asks to create, build, modify, fill, analyze, read, repair, validate, or format any spreadsheet, workbook, report, dashboard, budget, financial model, pivot table, or tabular data file. Handles Chinese text, encodings (UTF-8 / GB18030 / GBK), full-width characters, CJK fonts in rendering, and Chinese number/date conventions (¥, 万/亿, 年/月/日). Covers: creating new workbooks from scratch, reading and analyzing existing files, editing existing workbooks while preserving pivot tables / VBA macros / charts / sparklines / conditional formatting / named ranges, formula recalculation and validation, visual review of results, and applying professional formatting. Triggers on 'spreadsheet', 'Excel', 'workbook', '表格', '工作簿', '.xlsx', '.xlsm', '.csv', 'pivot table', '透视表', 'macro', '宏', 'chart', '图表', 'financial model', '财务模型', 'formula', '公式', or any request to produce tabular data.

★ 3
Jinhong270
Jinhong270/AI-Agent

xlsx-formula-master

你描述需求(人话),它给你 Excel / WPS 公式 + 解释 + 不踩坑的边界条件。 专攻 VLOOKUP / XLOOKUP / INDEX-MATCH / SUMIFS / 数组公式 / 动态数组 / Power Query 等高频但易错场景。 自动适配你的 Excel 版本(2019 / 365 / WPS)——版本不同公式可能不能用。 触发:用户说 "Excel 公式"、"VLOOKUP"、"怎么算"、"WPS 公式"、"求和怎么写"、"匹配数据"、"数据透视"。

★ 3
Jinhong270
Jinhong270/AI-Agent

self-improving-agent

Self-improving agent system that analyzes conversation quality, identifies improvement opportunities, and continuously optimizes response strategies.

★ 3
Jinhong270
Jinhong270/AI-Agent

xiaohongshu-content-tools

小红书运营数据工具|当提到小红书关键词搜索,小红书笔记详情及评论,小红书博主作品时使用,可实现爆款挖掘/竞品分析/KOL筛选/趋势洞察,用数据驱动小红书流量增长,告别盲目创作

★ 3
Jinhong270
Jinhong270/AI-Agent

xfg-ddd-skills

DDD 六边形架构设计与部署技能包。提供 Domain/Case/Infrastructure 层设计模式与代码模板,以及 Docker 环境部署脚本。当用户询问 DDD 架构、设计模式或需要部署项目时调用。

★ 3
Jinhong270
Jinhong270/AI-Agent

wordpress

WordPress.com API integration with managed OAuth. Manage posts, pages, sites, and content. Use this skill when users want to create, read, update, or delete WordPress.com posts, pages, or manage site content. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway). Requires network access and valid Maton API key.

★ 3