arcgis-js-component

Development aid for ArcGIS Maps SDK for JavaScript 5.0 web components, intended for creating or migrating to component-based arcgis-scene, arcgis-map, arcgis-sketch and other custom elements. Common trigger phrases include: "component", "arcgis-scene", "arcgis-sketch", "arcgis-map", "map-components", "web component", "custom element", "migrate to component", "5.0 component", "Sketch widget deprecated", "replace widget with component", "declarative map". Use the ArcGIS JS SDK 5.0 CDN unless otherwise specified.

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "arcgis-js-component" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-682420bd5388c625cb3b7365aa37d222b93e99baf6545932abc0d0afc6d99de4. Verify the upstream source and version against https://skillhub.cn/skills/user_d03b9e2c/arcgis-js-component before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

skillhub.cn

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Development aid for ArcGIS Maps SDK for JavaScript 5.0 web components, intended for creating or migrating to component-based arcgis-scene, arcgis-map, arcgis-sketch and other custom elements. Common trigger phrases include: "component", "arcgis-scene", "arcgis-sketch", "arcgis-map", "map-components", "web component", "custom element", "migrate to component", "5.0 component", "Sketch widget deprecated", "replace widget with component", "declarative map". Use the ArcGIS JS SDK 5.0 CDN unless otherwise specified.

0 Downloads

Introduction source: third_party · user_d03b9e2c · 1.0.3 Reference

SkillPi interpretation

Tasks
Translation pending; see source documentation.
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: arcgis-js-component
description: >
  ArcGIS Maps SDK for JavaScript 5.0 Components (Web Components) 开发辅助。
  This skill should be used when the user wants to create or migrate to the component-based
  approach using arcgis-scene, arcgis-map, arcgis-sketch, and other custom elements.
  Triggers: "component", "arcgis-scene", "arcgis-sketch", "arcgis-map", "map-components",
  "web component", "custom element", "migrate to component", "5.0 component",
  "Sketch widget deprecated", "replace widget with component", "declarative map".
  Unless otherwise specified, use ArcGIS JS SDK 5.0 CDN.

ArcGIS JS Components 开发技能

概述

ArcGIS Maps SDK for JavaScript 从 5.0 版本开始大力推进组件化(Web Components), 将原来的命令式 API(new SceneView(), new Sketch() 等)迁移到声明式的自定义元素 (<arcgis-scene>, <arcgis-sketch> 等)。此技能提供组件化开发的完整指南。

触发条件

使用本技能当用户请求涉及:

  • 创建使用 arcgis-scene / arcgis-map 组件的应用
  • 使用 arcgis-sketch 替代已弃用的 Sketch widget
  • 使用 map-components 下的组件替换之前的 widget 组件
  • 将现有命令式代码迁移到组件化方式
  • 在 5.0 CDN 下进行组件开发
  • 组件间通信、属性设置、事件监听等问题

核心原则

  1. 使用 5.0 CDN — https://js.arcgis.com/5.0/,4.x 本地 CDN 不支持组件自定义元素
  2. 声明式视图 — <arcgis-scene camera-position="..."> 替代 new SceneView({...})
  3. referenceElement 优先 — 组件间通过 referenceElement 关联,而非直接传递 view 对象
  4. 时序关键 — 组件属性设置和就绪等待有严格顺序要求
  5. 坐标系一致 — GraphicsLayer 的 spatialReference 须与 arcgis-scene camera 坐标系一致

项目结构模板

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
    <title>Title</title>

    <link rel="stylesheet" href="https://js.arcgis.com/5.0/esri/themes/light/main.css"/>

    <style>
        html, body { padding: 0; margin: 0; height: 100%; width: 100%; }
        arcgis-scene { height: 100%; width: 100%; }
    </style>
</head>
<body>

<arcgis-scene id="viewDiv"
    camera-position="121.0076, 23.3814, 9000"
    camera-tilt="35"
    camera-heading="0">
    <arcgis-sketch id="sketchEl" slot="top-right"></arcgis-sketch>
</arcgis-scene>

<!-- 5.0 运行时:注册所有自定义元素 -->
<script type="module" src="https://js.arcgis.com/5.0/"></script>

<script type="module">
    // ─── 加载 ArcGIS JS API 模块 ───
    const [
        Map, SpatialReference,
        ElevationLayer, GraphicsLayer
    ] = await $arcgis.import([
        "@arcgis/core/Map.js",
        "@arcgis/core/geometry/SpatialReference.js",
        "@arcgis/core/layers/ElevationLayer.js",
        "@arcgis/core/layers/GraphicsLayer.js",
    ]);

    // ─── 天地图底图 ───
    const getTianditu = await $arcgis.import(
        "https://openlayers.vip/examples/resources/tianditu_layers_local_es6.js"
    );
    const tiandituLayers = getTianditu.default({ type: "img_w" }); // img_w=影像, vec_w=矢量, cva_w=注记

    // ─── 创建 Map(含高程地形)───
    const map = new Map({
        basemap: { baseLayers: [tiandituLayers.base, tiandituLayers.anno] },
        ground: {
            layers: [
                new ElevationLayer({
                    url: 'https://www.geosceneonline.cn/image/rest/services/OpenData/ChinaTerrain3D/ImageServer'
                })
            ]
        }
    });

    // ─── arcgis-scene 组件获取 view ───
    const viewElement = document.querySelector("arcgis-scene");
    const view = viewElement.view;
    view.map = map;

    // ─── arcgis-sketch 配置(所有属性必须在 viewOnReady 前设置)───
    const sketchEl = document.getElementById("sketchEl");
    const sketchLayer = new GraphicsLayer({
        elevationInfo: { mode: "on-the-ground" },
        spatialReference: SpatialReference.WGS84
    });
    map.add(sketchLayer);

    sketchEl.referenceElement = "viewDiv";
    sketchEl.defaultGraphicsLayerDisabled = true;
    sketchEl.creationMode = "single";
    sketchEl.layer = sketchLayer;

    await viewElement.viewOnReady();
    // view.map 赋值会重置相机,显式定位
    view.goTo({
        position: { x: 121.0076, y: 23.3814, z: 9000, spatialReference: SpatialReference.WGS84 },
        heading: 0,
        tilt: 35
    });

    await sketchEl.componentOnReady();
    console.log("组件初始化完成");
</script>
</body>
</html>

底图初始化

天地图底图

通过 tianditu_layers_local_eqQOW30ICo3.js 加载天地图瓦片服务:

const getTianditu = await $arcgis.import(
    "https://openlayers.vip/examples/resources/tianditu_layers_local_es6.js"
);
const layers = getTianditu.default({ type: "img_w" });

type 参数选项:

值 类型 说明
"img_w" 影像底图 卫星影像(推荐 3D 场景使用)
"vec_w" 矢量底图 矢量地图
"cva_w" 注记图层 中文注记叠加

返回对象包含 .base(底图图层)和 .anno(注记图层),组合传入 basemap.baseLayers。

3D 高程地形

SceneView 3D 场景需要地面高程数据:

ground: {
    layers: [
        new ElevationLayer({
            url: 'https://www.geosceneonline.cn/image/rest/services/OpenData/ChinaTerrain3D/ImageServer'
        })
    ]
}

核心组件速查

arcgis-scene / arcgis-map

<arcgis-scene id="viewDiv" camera-position="lon, lat, alt" camera-tilt="45" camera-heading="0">
  • viewElement.view 获取 view 对象
  • viewElement.viewOnReady() 等待就绪
  • 支持子组件通过 slot 属性自动定位

arcgis-sketch(替代已弃用 Sketch widget)

详细文档见 references/arcgis-sketch.md。

关键要点:

  • defaultGraphicsLayerDisabled = true 必须设置
  • event.detail 即 CreateEvent,detail.state / detail.toolEventInfo 与旧版兼容
  • 3D SceneView 下 GraphicsLayer 需 elevationInfo: { mode: "on-the-ground" }

其他常用组件

组件 用途
<arcgis-zoom> 缩放控件
<arcgis-compass> 指南针
<arcgis-home> 回到初始视角
<arcgis-search> 搜索控件
<arcgis-layer-list> 图层列表
<arcgis-legend> 图例
<arcgis-basemap-toggle> 底图切换
<arcgis-expand> 可展开面板容器

初始化时序规则

详细说明见 references/timing.md。

核心规则:

设置组件属性 → viewOnReady() → view.goTo() 定位 → componentOnReady()

必须记住:所有 arcgis-sketch 的属性(layer, referenceElement, defaultGraphicsLayerDisabled, creationMode)必须在 viewElement.viewOnReady() 之前设置。

严格按照官方示例和API,严禁使用不存在的类和工具。

常见错误与解决

错误 原因 解决
Cannot set properties of undefined (setting 'map') 4.x CDN 不支持自定义元素 改用 5.0 CDN
Failed to create layerview for layer 'Sketch Layer' 组件自建图层坐标系冲突 defaultGraphicsLayerDisabled=true + 自建 GraphicsLayer
arcgis-sketch 事件不触发 componentOnReady 在 viewOnReady 前 调整等待顺序
交叉多边形检测不生效 event.detail.state / toolEventInfo 未使用 参考 references/arcgis-sketch.md
相机不定位到目标 view.map=map 重置相机 viewOnReady 后调用 view.goTo()

官方资源

Current listing version

1.0.3

Verify the source revision ↗

Safety and assessment details

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value88/100

Highlights

  • 提供 ArcGIS JS SDK 5.0 组件化迁移的完整解决方案
  • 覆盖从命令式 API 到声明式组件的实际开发痛点
  • 包含天地图底图、3D 高程地形等本土化实用配置
Trigger Precision92/100

Highlights

  • 触发词精准覆盖组件化开发核心场景(arcgis-scene, arcgis-sketch, migrate to component 等)
  • 边界清晰,有效区分传统 widget 开发模式
Structure and Standards75/100

Areas to improve

  • 文档结构优化 Reported severity: Minor

    文档内容完整但篇幅较长(约600行),建议拆分或增加目录导航;缺少显式的 When to Use 使用场景说明章节

    Recommendation: 可考虑将详细 API 说明移至独立参考文件;在主文档开头增加 When to Use 段落明确适用场景

Highlights

  • 提供完整的项目结构模板和端到端 HTML 示例
  • frontmatter 元数据完整规范
Execution Reliability85/100

Highlights

  • 工具来源明确(5.0 CDN、天地图脚本、高程服务 URL 均有效)
  • 覆盖主要异常场景并提供解决方案(坐标系冲突、初始化时序、CDN 版本问题)
  • 参数使用符合官方 API 规范
Evidence Verifiability (mean of the first four)85/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

These common operations were not identified in the main document. This does not mean no permissions or risks exist.

Domains or addresses referenced in the document

These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.

  • developers.arcgis.com
  • js.arcgis.com
  • openlayers.vip
  • www.geosceneonline.cn

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.