arcgis-widgets-ui
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseArcGIS Widgets & UI
ArcGIS Widgets 与 UI开发
Use this skill when building user interfaces with widgets, Map Components, and Calcite.
Best Practice: Prefer Map Components (web components like,arcgis-legend) over Core API widgets when possible. Esri is transitioning to web components, and some widgets are already deprecated. See Esri's component transition plan.arcgis-search
当你使用Widgets、Map Components和Calcite构建用户界面时,可以使用本技能。
最佳实践: 尽可能优先使用Map Components(如、arcgis-legend等Web组件),而非Core API组件。Esri正逐步过渡到Web组件,部分旧组件已被弃用。查看Esri组件过渡计划。arcgis-search
Map Components Approach
Map Components 实现方式
Available Map Components
可用的Map Components
| Component | Purpose |
|---|---|
| 2D map container |
| 3D scene container |
| Zoom in/out buttons |
| Orientation indicator |
| Return to initial extent |
| Find user location |
| Track user location |
| Pan/rotate mode (3D) |
| Toggle fullscreen |
| Display map scale |
| Layer symbology legend |
| Layer visibility control |
| Switch basemaps |
| Toggle two basemaps |
| Location search |
| Feature popups |
| Feature editing |
| Draw geometries |
| Tabular data view |
| Temporal navigation |
| Display time zone |
| Collapsible container |
| Map printing |
| Navigate to bookmarks |
| Turn-by-turn routing |
| Compare layers |
| Coordinate formats |
| 3D lighting control |
| 3D weather effects |
| 2D distance measurement |
| 2D area measurement |
| 3D line measurement |
| 3D area measurement |
| Utility network tracing |
| Utility associations |
Note: Not all widgets have component equivalents yet. FeatureForm, Histogram, and some specialized widgets only have Core API versions.
| 组件 | 用途 |
|---|---|
| 2D地图容器 |
| 3D场景容器 |
| 缩放按钮 |
| 方向指示器 |
| 返回初始视野范围 |
| 定位用户位置 |
| 追踪用户位置 |
| 平移/旋转模式(3D) |
| 切换全屏模式 |
| 显示地图比例尺 |
| 图层符号图例 |
| 图层可见性控制 |
| 切换底图 |
| 切换两种底图 |
| 位置搜索 |
| 要素弹窗 |
| 要素编辑 |
| 绘制几何图形 |
| 表格数据视图 |
| 时间轴导航 |
| 显示时区 |
| 可折叠容器 |
| 地图打印 |
| 导航至书签位置 |
| 逐向导航 |
| 对比图层 |
| 坐标格式转换 |
| 3D光照控制 |
| 3D天气效果 |
| 2D距离测量 |
| 2D面积测量 |
| 3D直线测量 |
| 3D面积测量 |
| 公用设施网络追踪 |
| 公用设施关联管理 |
注意: 并非所有组件都有对应的Map Components版本。FeatureForm、Histogram及部分专用组件仅支持Core API版本。
Slot-Based Positioning
基于插槽的定位
html
<arcgis-map basemap="streets-vector">
<!-- Position widgets using slots -->
<arcgis-zoom slot="top-left"></arcgis-zoom>
<arcgis-home slot="top-left"></arcgis-home>
<arcgis-compass slot="top-left"></arcgis-compass>
<arcgis-search slot="top-right"></arcgis-search>
<arcgis-layer-list slot="top-right"></arcgis-layer-list>
<arcgis-legend slot="bottom-left"></arcgis-legend>
<arcgis-scale-bar slot="bottom-right"></arcgis-scale-bar>
<!-- Popup must use popup slot -->
<arcgis-popup slot="popup"></arcgis-popup>
</arcgis-map>Available slots: , , , , ,
top-lefttop-rightbottom-leftbottom-rightpopupmanualhtml
<arcgis-map basemap="streets-vector">
<!-- 使用插槽定位组件 -->
<arcgis-zoom slot="top-left"></arcgis-zoom>
<arcgis-home slot="top-left"></arcgis-home>
<arcgis-compass slot="top-left"></arcgis-compass>
<arcgis-search slot="top-right"></arcgis-search>
<arcgis-layer-list slot="top-right"></arcgis-layer-list>
<arcgis-legend slot="bottom-left"></arcgis-legend>
<arcgis-scale-bar slot="bottom-right"></arcgis-scale-bar>
<!-- Popup必须使用popup插槽 -->
<arcgis-popup slot="popup"></arcgis-popup>
</arcgis-map>可用插槽:、、、、、
top-lefttop-rightbottom-leftbottom-rightpopupmanualExpand Component
展开组件(Expand Component)
Wrap widgets in for collapsible behavior:
arcgis-expandhtml
<arcgis-map basemap="streets-vector">
<arcgis-expand slot="top-right" expand-tooltip="Show Legend" mode="floating">
<arcgis-legend></arcgis-legend>
</arcgis-expand>
<arcgis-expand slot="top-left" expanded>
<arcgis-layer-list></arcgis-layer-list>
</arcgis-expand>
</arcgis-map>将组件包裹在中实现折叠功能:
arcgis-expandhtml
<arcgis-map basemap="streets-vector">
<arcgis-expand slot="top-right" expand-tooltip="显示图例" mode="floating">
<arcgis-legend></arcgis-legend>
</arcgis-expand>
<arcgis-expand slot="top-left" expanded>
<arcgis-layer-list></arcgis-layer-list>
</arcgis-expand>
</arcgis-map>Reference Element (External Components)
引用元素(外部组件)
Place components outside the map and reference them:
html
<calcite-shell>
<calcite-shell-panel slot="panel-start">
<arcgis-legend reference-element="arcgis-map"></arcgis-legend>
</calcite-shell-panel>
<arcgis-map id="arcgis-map" basemap="topo-vector">
<arcgis-zoom slot="top-left"></arcgis-zoom>
</arcgis-map>
</calcite-shell>将组件放置在地图外部并引用:
html
<calcite-shell>
<calcite-shell-panel slot="panel-start">
<arcgis-legend reference-element="arcgis-map"></arcgis-legend>
</calcite-shell-panel>
<arcgis-map id="arcgis-map" basemap="topo-vector">
<arcgis-zoom slot="top-left"></arcgis-zoom>
</arcgis-map>
</calcite-shell>Core Widget Approach
核心组件实现方式
Adding Widgets to View
向视图中添加组件
javascript
import Legend from "@arcgis/core/widgets/Legend.js";
import LayerList from "@arcgis/core/widgets/LayerList.js";
import Search from "@arcgis/core/widgets/Search.js";
// Create widget
const legend = new Legend({ view: view });
// Add to view UI
view.ui.add(legend, "bottom-left");
// Add multiple widgets
view.ui.add([
{ component: legend, position: "bottom-left" },
{ component: search, position: "top-right" }
]);
// Add to specific index (order in position)
view.ui.add(legend, { position: "bottom-left", index: 0 });
// Remove widget
view.ui.remove(legend);javascript
import Legend from "@arcgis/core/widgets/Legend.js";
import LayerList from "@arcgis/core/widgets/LayerList.js";
import Search from "@arcgis/core/widgets/Search.js";
// 创建组件
const legend = new Legend({ view: view });
// 添加到视图UI
view.ui.add(legend, "bottom-left");
// 添加多个组件
view.ui.add([
{ component: legend, position: "bottom-left" },
{ component: search, position: "top-right" }
]);
// 添加到指定位置的索引(控制显示顺序)
view.ui.add(legend, { position: "bottom-left", index: 0 });
// 移除组件
view.ui.remove(legend);Widget in Custom Container
在自定义容器中使用组件
html
<div id="legendDiv"></div>
<script type="module">
import Legend from "@arcgis/core/widgets/Legend.js";
const legend = new Legend({
view: view,
container: "legendDiv" // Or document.getElementById("legendDiv")
});
</script>html
<div id="legendDiv"></div>
<script type="module">
import Legend from "@arcgis/core/widgets/Legend.js";
const legend = new Legend({
view: view,
container: "legendDiv" // 或 document.getElementById("legendDiv")
});
</script>Common Widgets
常用组件
Legend
图例(Legend)
html
<!-- Map Component -->
<arcgis-legend slot="bottom-left"></arcgis-legend>javascript
// Core API
import Legend from "@arcgis/core/widgets/Legend.js";
const legend = new Legend({
view: view,
layerInfos: [{
layer: featureLayer,
title: "Custom Title"
}]
});
view.ui.add(legend, "bottom-left");html
<!-- Map Components方式 -->
<arcgis-legend slot="bottom-left"></arcgis-legend>javascript
// Core API方式
import Legend from "@arcgis/core/widgets/Legend.js";
const legend = new Legend({
view: view,
layerInfos: [{
layer: featureLayer,
title: "自定义标题"
}]
});
view.ui.add(legend, "bottom-left");LayerList
图层列表(LayerList)
html
<!-- Map Component -->
<arcgis-layer-list slot="top-right"></arcgis-layer-list>javascript
// Core API with actions
import LayerList from "@arcgis/core/widgets/LayerList.js";
const layerList = new LayerList({
view: view,
listItemCreatedFunction: (event) => {
const item = event.item;
item.actionsSections = [[{
title: "Zoom to layer",
icon: "zoom-to-object",
id: "zoom-to"
}]];
}
});
layerList.on("trigger-action", (event) => {
if (event.action.id === "zoom-to") {
view.goTo(event.item.layer.fullExtent);
}
});
view.ui.add(layerList, "top-right");html
<!-- Map Components方式 -->
<arcgis-layer-list slot="top-right"></arcgis-layer-list>javascript
// 带操作的Core API方式
import LayerList from "@arcgis/core/widgets/LayerList.js";
const layerList = new LayerList({
view: view,
listItemCreatedFunction: (event) => {
const item = event.item;
item.actionsSections = [[{
title: "缩放至图层",
icon: "zoom-to-object",
id: "zoom-to"
}]];
}
});
layerList.on("trigger-action", (event) => {
if (event.action.id === "zoom-to") {
view.goTo(event.item.layer.fullExtent);
}
});
view.ui.add(layerList, "top-right");BasemapGallery
底图库(BasemapGallery)
html
<!-- Map Component -->
<arcgis-basemap-gallery slot="top-right"></arcgis-basemap-gallery>javascript
// Core API
import BasemapGallery from "@arcgis/core/widgets/BasemapGallery.js";
const basemapGallery = new BasemapGallery({
view: view
});
view.ui.add(basemapGallery, "top-right");html
<!-- Map Components方式 -->
<arcgis-basemap-gallery slot="top-right"></arcgis-basemap-gallery>javascript
// Core API方式
import BasemapGallery from "@arcgis/core/widgets/BasemapGallery.js";
const basemapGallery = new BasemapGallery({
view: view
});
view.ui.add(basemapGallery, "top-right");Search
搜索(Search)
html
<!-- Map Component -->
<arcgis-search slot="top-right"></arcgis-search>javascript
// Core API with custom sources
import Search from "@arcgis/core/widgets/Search.js";
const search = new Search({
view: view,
sources: [{
layer: featureLayer,
searchFields: ["name", "address"],
displayField: "name",
exactMatch: false,
outFields: ["*"],
name: "My Layer",
placeholder: "Search features"
}]
});
view.ui.add(search, "top-right");
// Events
search.on("select-result", (event) => {
console.log("Selected:", event.result);
});html
<!-- Map Components方式 -->
<arcgis-search slot="top-right"></arcgis-search>javascript
// 带自定义数据源的Core API方式
import Search from "@arcgis/core/widgets/Search.js";
const search = new Search({
view: view,
sources: [{
layer: featureLayer,
searchFields: ["name", "address"],
displayField: "name",
exactMatch: false,
outFields: ["*"],
name: "我的图层",
placeholder: "搜索要素"
}]
});
view.ui.add(search, "top-right");
// 事件监听
search.on("select-result", (event) => {
console.log("已选择:", event.result);
});FeatureTable
要素表格(FeatureTable)
html
<!-- Map Component -->
<arcgis-feature-table reference-element="arcgis-map"></arcgis-feature-table>javascript
// Core API
import FeatureTable from "@arcgis/core/widgets/FeatureTable.js";
const featureTable = new FeatureTable({
view: view,
layer: featureLayer,
container: "tableDiv",
visibleElements: {
header: true,
columnMenus: true,
selectionColumn: true
},
fieldConfigs: [
{ name: "name", label: "Name" },
{ name: "population", label: "Population" }
]
});
// Selection events
featureTable.on("selection-change", (event) => {
console.log("Selected rows:", event.added);
});html
<!-- Map Components方式 -->
<arcgis-feature-table reference-element="arcgis-map"></arcgis-feature-table>javascript
// Core API方式
import FeatureTable from "@arcgis/core/widgets/FeatureTable.js";
const featureTable = new FeatureTable({
view: view,
layer: featureLayer,
container: "tableDiv",
visibleElements: {
header: true,
columnMenus: true,
selectionColumn: true
},
fieldConfigs: [
{ name: "name", label: "名称" },
{ name: "population", label: "人口" }
]
});
// 选择事件监听
featureTable.on("selection-change", (event) => {
console.log("已选择行:", event.added);
});TimeSlider
时间滑块(TimeSlider)
html
<!-- Map Component -->
<arcgis-time-slider
slot="bottom-right"
layout="auto"
mode="time-window"
time-visible
loop>
</arcgis-time-slider>
<script type="module">
const timeSlider = document.querySelector("arcgis-time-slider");
await layer.load();
timeSlider.fullTimeExtent = layer.timeInfo.fullTimeExtent;
timeSlider.stops = {
interval: layer.timeInfo.interval
};
</script>javascript
// Core API
import TimeSlider from "@arcgis/core/widgets/TimeSlider.js";
const timeSlider = new TimeSlider({
view: view,
mode: "time-window", // instant, time-window, cumulative-from-start, cumulative-from-end
fullTimeExtent: layer.timeInfo.fullTimeExtent,
stops: {
interval: {
value: 1,
unit: "hours"
}
},
playRate: 1000, // ms between stops
loop: true
});
view.ui.add(timeSlider, "bottom-right");
// Events
timeSlider.watch("timeExtent", (timeExtent) => {
console.log("Time changed:", timeExtent.start, timeExtent.end);
});html
<!-- Map Components方式 -->
<arcgis-time-slider
slot="bottom-right"
layout="auto"
mode="time-window"
time-visible
loop>
</arcgis-time-slider>
<script type="module">
const timeSlider = document.querySelector("arcgis-time-slider");
await layer.load();
timeSlider.fullTimeExtent = layer.timeInfo.fullTimeExtent;
timeSlider.stops = {
interval: layer.timeInfo.interval
};
</script>javascript
// Core API方式
import TimeSlider from "@arcgis/core/widgets/TimeSlider.js";
const timeSlider = new TimeSlider({
view: view,
mode: "time-window", // 可选值:instant、time-window、cumulative-from-start、cumulative-from-end
fullTimeExtent: layer.timeInfo.fullTimeExtent,
stops: {
interval: {
value: 1,
unit: "hours"
}
},
playRate: 1000, // 每次切换的间隔毫秒数
loop: true
});
view.ui.add(timeSlider, "bottom-right");
// 事件监听
timeSlider.watch("timeExtent", (timeExtent) => {
console.log("时间范围已更改:", timeExtent.start, timeExtent.end);
});打印(Print)
html
<!-- Map Component -->
<arcgis-print slot="top-right"></arcgis-print>javascript
// Core API
import Print from "@arcgis/core/widgets/Print.js";
const print = new Print({
view: view,
printServiceUrl: "https://utility.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task"
});
view.ui.add(print, "top-right");html
<!-- Map Components方式 -->
<arcgis-print slot="top-right"></arcgis-print>javascript
// Core API方式
import Print from "@arcgis/core/widgets/Print.js";
const print = new Print({
view: view,
printServiceUrl: "https://utility.arcgisonline.com/arcgis/rest/services/Utilities/PrintingTools/GPServer/Export%20Web%20Map%20Task"
});
view.ui.add(print, "top-right");Calcite Design System Integration
Calcite设计系统集成
Basic Layout with Calcite
基于Calcite的基础布局
html
<!DOCTYPE html>
<html>
<head>
<script type="module" src="https://js.arcgis.com/calcite-components/3.3.3/calcite.esm.js"></script>
<script src="https://js.arcgis.com/4.34/"></script>
<script type="module" src="https://js.arcgis.com/4.34/map-components/"></script>
<style>
html, body { height: 100%; margin: 0; }
</style>
</head>
<body class="calcite-mode-light">
<calcite-shell>
<!-- Header -->
<calcite-navigation slot="header">
<calcite-navigation-logo slot="logo" heading="My Map App"></calcite-navigation-logo>
</calcite-navigation>
<!-- Side Panel -->
<calcite-shell-panel slot="panel-start">
<calcite-panel heading="Layers">
<arcgis-layer-list reference-element="map"></arcgis-layer-list>
</calcite-panel>
</calcite-shell-panel>
<!-- Map -->
<arcgis-map id="map" basemap="streets-vector">
<arcgis-zoom slot="top-left"></arcgis-zoom>
</arcgis-map>
<!-- End Panel -->
<calcite-shell-panel slot="panel-end">
<calcite-panel heading="Legend">
<arcgis-legend reference-element="map"></arcgis-legend>
</calcite-panel>
</calcite-shell-panel>
</calcite-shell>
</body>
</html>html
<!DOCTYPE html>
<html>
<head>
<script type="module" src="https://js.arcgis.com/calcite-components/3.3.3/calcite.esm.js"></script>
<script src="https://js.arcgis.com/4.34/"></script>
<script type="module" src="https://js.arcgis.com/4.34/map-components/"></script>
<style>
html, body { height: 100%; margin: 0; }
</style>
</head>
<body class="calcite-mode-light">
<calcite-shell>
<!-- 头部导航 -->
<calcite-navigation slot="header">
<calcite-navigation-logo slot="logo" heading="我的地图应用"></calcite-navigation-logo>
</calcite-navigation>
<!-- 侧边面板 -->
<calcite-shell-panel slot="panel-start">
<calcite-panel heading="图层">
<arcgis-layer-list reference-element="map"></arcgis-layer-list>
</calcite-panel>
</calcite-shell-panel>
<!-- 地图 -->
<arcgis-map id="map" basemap="streets-vector">
<arcgis-zoom slot="top-left"></arcgis-zoom>
</arcgis-map>
<!-- 右侧面板 -->
<calcite-shell-panel slot="panel-end">
<calcite-panel heading="图例">
<arcgis-legend reference-element="map"></arcgis-legend>
</calcite-panel>
</calcite-shell-panel>
</calcite-shell>
</body>
</html>Calcite Action Bar
Calcite操作栏
html
<calcite-shell>
<calcite-shell-panel slot="panel-start">
<calcite-action-bar slot="action-bar">
<calcite-action icon="layers" text="Layers" data-panel="layers"></calcite-action>
<calcite-action icon="legend" text="Legend" data-panel="legend"></calcite-action>
<calcite-action icon="bookmark" text="Bookmarks" data-panel="bookmarks"></calcite-action>
</calcite-action-bar>
<calcite-panel id="layers" heading="Layers">
<arcgis-layer-list reference-element="map"></arcgis-layer-list>
</calcite-panel>
<calcite-panel id="legend" heading="Legend" hidden>
<arcgis-legend reference-element="map"></arcgis-legend>
</calcite-panel>
</calcite-shell-panel>
<arcgis-map id="map" basemap="topo-vector"></arcgis-map>
</calcite-shell>
<script>
// Toggle panels on action click
document.querySelectorAll("calcite-action").forEach(action => {
action.addEventListener("click", () => {
const panelId = action.dataset.panel;
document.querySelectorAll("calcite-panel").forEach(panel => {
panel.hidden = panel.id !== panelId;
});
});
});
</script>html
<calcite-shell>
<calcite-shell-panel slot="panel-start">
<calcite-action-bar slot="action-bar">
<calcite-action icon="layers" text="图层" data-panel="layers"></calcite-action>
<calcite-action icon="legend" text="图例" data-panel="legend"></calcite-action>
<calcite-action icon="bookmark" text="书签" data-panel="bookmarks"></calcite-action>
</calcite-action-bar>
<calcite-panel id="layers" heading="图层">
<arcgis-layer-list reference-element="map"></arcgis-layer-list>
</calcite-panel>
<calcite-panel id="legend" heading="图例" hidden>
<arcgis-legend reference-element="map"></arcgis-legend>
</calcite-panel>
</calcite-shell-panel>
<arcgis-map id="map" basemap="topo-vector"></arcgis-map>
</calcite-shell>
<script>
// 点击操作按钮切换面板显示
document.querySelectorAll("calcite-action").forEach(action => {
action.addEventListener("click", () => {
const panelId = action.dataset.panel;
document.querySelectorAll("calcite-panel").forEach(panel => {
panel.hidden = panel.id !== panelId;
});
});
});
</script>Common Calcite Components
常用Calcite组件
| Component | Purpose |
|---|---|
| App layout container |
| Side panels |
| Content panel |
| Header/footer |
| Icon button bar |
| Icon button |
| Standard button |
| Text input |
| List container |
| List item |
| Card container |
| Modal dialog |
| Alert message |
| Loading indicator |
| 组件 | 用途 |
|---|---|
| 应用布局容器 |
| 侧边面板 |
| 内容面板 |
| 头部/底部导航 |
| 图标按钮栏 |
| 图标按钮 |
| 标准按钮 |
| 文本输入框 |
| 列表容器 |
| 列表项 |
| 卡片容器 |
| 模态对话框 |
| 提示消息框 |
| 加载指示器 |
Theming
主题设置
html
<!-- Light mode -->
<body class="calcite-mode-light">
<!-- Dark mode -->
<body class="calcite-mode-dark">
<!-- Custom theme colors -->
<style>
:root {
--calcite-color-brand: #007ac2;
--calcite-color-brand-hover: #005a8e;
--calcite-color-text-1: #323232;
}
</style>html
<!-- 浅色模式 -->
<body class="calcite-mode-light">
<!-- 深色模式 -->
<body class="calcite-mode-dark">
<!-- 自定义主题颜色 -->
<style>
:root {
--calcite-color-brand: #007ac2;
--calcite-color-brand-hover: #005a8e;
--calcite-color-text-1: #323232;
}
</style>Custom Widget Placement
自定义组件定位
Manual Positioning
手动定位
javascript
// Add widget at specific position
view.ui.add(widget, {
position: "manual",
index: 0
});
// Position with CSS
document.getElementById("myWidget").style.cssText = `
position: absolute;
top: 10px;
left: 50%;
transform: translateX(-50%);
`;javascript
// 在指定位置添加组件
view.ui.add(widget, {
position: "manual",
index: 0
});
// 使用CSS定位
document.getElementById("myWidget").style.cssText = `
position: absolute;
top: 10px;
left: 50%;
transform: translateX(-50%);
`;DOM Container
DOM容器定位
html
<div id="mapDiv" style="position: relative;">
<div id="customWidget" style="position: absolute; top: 10px; right: 10px; z-index: 1;">
<!-- Custom content -->
</div>
</div>html
<div id="mapDiv" style="position: relative;">
<div id="customWidget" style="position: absolute; top: 10px; right: 10px; z-index: 1;">
<!-- 自定义内容 -->
</div>
</div>Widget Events
组件事件
javascript
// Search select
search.on("select-result", (event) => {
console.log(event.result);
});
// LayerList trigger action
layerList.on("trigger-action", (event) => {
console.log(event.action, event.item);
});
// TimeSlider time change
timeSlider.watch("timeExtent", (value) => {
console.log(value.start, value.end);
});
// FeatureTable selection
featureTable.on("selection-change", (event) => {
console.log(event.added, event.removed);
});javascript
// 搜索结果选择事件
search.on("select-result", (event) => {
console.log(event.result);
});
// 图层列表操作触发事件
layerList.on("trigger-action", (event) => {
console.log(event.action, event.item);
});
// 时间滑块时间范围变更事件
timeSlider.watch("timeExtent", (value) => {
console.log(value.start, value.end);
});
// 要素表格选择变更事件
featureTable.on("selection-change", (event) => {
console.log(event.added, event.removed);
});TypeScript Usage
TypeScript使用
Widget configurations use autocasting with properties. For TypeScript safety, use :
typeas consttypescript
// Use 'as const' for widget configurations
const layerList = new LayerList({
view: view,
listItemCreatedFunction: (event) => {
const item = event.item;
item.actionsSections = [[{
title: "Zoom to layer",
icon: "zoom-to-object",
id: "zoom-to"
}]];
}
});
// For layer configurations in widgets
const featureTable = new FeatureTable({
view: view,
layer: featureLayer,
fieldConfigs: [
{ name: "name", label: "Name" },
{ name: "population", label: "Population" }
]
});Tip: See arcgis-core-maps skill for detailed guidance on autocasting vs explicit classes.
组件配置通过属性实现自动类型转换。为保证TypeScript类型安全,使用:
typeas consttypescript
// 对组件配置使用'as const'
const layerList = new LayerList({
view: view,
listItemCreatedFunction: (event) => {
const item = event.item;
item.actionsSections = [[{
title: "Zoom to layer",
icon: "zoom-to-object",
id: "zoom-to"
}]];
}
});
// 组件中的图层配置
const featureTable = new FeatureTable({
view: view,
layer: featureLayer,
fieldConfigs: [
{ name: "name", label: "Name" },
{ name: "population", label: "Population" }
]
});提示: 有关自动类型转换与显式类的详细说明,请查看arcgis-core-maps技能。
Common Pitfalls
常见误区
-
Missing reference-element: When placing components outside the map, useattribute
reference-element -
Slot names are specific: Use exact slot names (, not
top-left)topleft -
Calcite CSS not loading: Ensure Calcite script is loaded before using Calcite components
-
Widget container conflicts: Don't add the same widget to both a container and view.ui
-
Dark/light mode mismatch: Addor
calcite-mode-lightclass to bodycalcite-mode-dark
-
缺少reference-element:当组件放置在地图外部时,必须使用属性
reference-element -
插槽名称错误:使用准确的插槽名称(如,而非
top-left)topleft -
Calcite CSS未加载:确保在使用Calcite组件前加载Calcite脚本
-
组件容器冲突:不要将同一个组件同时添加到容器和view.ui中
-
深色/浅色模式不匹配:为body添加或
calcite-mode-light类calcite-mode-dark