@tianditu/web-components 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +97 -0
- package/dist/index.d.mts +313 -0
- package/dist/index.mjs +771 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Demo Macro
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# @tianditu/web-components
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
> 用标准 Web Components 写天地图,任何框架或纯 HTML 均可使用。
|
|
8
|
+
> 基于 Lit 的自定义元素与 Vue 适配层共享同一份 core 定义:attribute 带类型化转换器,事件以 `tdt-` 前缀转发,覆盖物元素嵌套即挂载,容器元素就近收编子级。
|
|
9
|
+
|
|
10
|
+
## 特性
|
|
11
|
+
|
|
12
|
+
- 🖥️ **框架无关** — 标准自定义元素,任何框架或纯 HTML 均可使用
|
|
13
|
+
- 🧩 **基于 Lit** — 响应式 attribute,坐标与集合带类型化转换器
|
|
14
|
+
- 📦 **同源内核** — 与 Vue 适配层共享 @tianditu/core 的挂载/同步/卸载编排
|
|
15
|
+
- 🏷️ **声明式子级** — 覆盖物元素写在 `<tdt-map>` 内部即自动挂载
|
|
16
|
+
|
|
17
|
+
## 安装
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# npm
|
|
21
|
+
$ npm install @tianditu/web-components
|
|
22
|
+
|
|
23
|
+
# yarn
|
|
24
|
+
$ yarn add @tianditu/web-components
|
|
25
|
+
|
|
26
|
+
# pnpm
|
|
27
|
+
$ pnpm add @tianditu/web-components
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## 快速开始
|
|
31
|
+
|
|
32
|
+
```html
|
|
33
|
+
<script type="module">
|
|
34
|
+
import { registerComponents } from "@tianditu/web-components";
|
|
35
|
+
|
|
36
|
+
registerComponents();
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<tdt-map tk="你的浏览器端密钥" center="116.404,39.915" zoom="12" style="width:100vw;height:100vh">
|
|
40
|
+
<tdt-marker lnglat="116.404,39.915">
|
|
41
|
+
<tdt-info-window open>
|
|
42
|
+
<div>天安门</div>
|
|
43
|
+
</tdt-info-window>
|
|
44
|
+
</tdt-marker>
|
|
45
|
+
<tdt-polyline path="116.38,39.9;116.42,39.92" color="#2563eb" weight="4"></tdt-polyline>
|
|
46
|
+
<tdt-control-zoom position="bottomright"></tdt-control-zoom>
|
|
47
|
+
</tdt-map>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## 元素
|
|
51
|
+
|
|
52
|
+
| 元素 | 官方类 | 说明 |
|
|
53
|
+
| ----------------- | -------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
|
|
54
|
+
| `tdt-map` | `T.Map` | `tk`、`center`("lng,lat")、`locate`(定位方式:"geolocation" / "ip" / "auto",`locate` 空值即 auto)、`zoom`;事件以 `tdt-` 前缀派发 |
|
|
55
|
+
| `tdt-info-window` | `T.InfoWindow` | `open`、`lnglat`、`max-width` 等;嵌套在覆盖物内由宿主打开 |
|
|
56
|
+
|
|
57
|
+
### 覆盖物
|
|
58
|
+
|
|
59
|
+
| 元素 | 官方类 | 说明 |
|
|
60
|
+
| ---------------------- | ------------------------- | --------------------------------------------------------------------------- |
|
|
61
|
+
| `tdt-marker` | `T.Marker` | `lnglat`、`icon`(JSON)、`draggable`、`title`、`z-index-offset`、`opacity` |
|
|
62
|
+
| `tdt-polyline` | `T.Polyline` | `path`("lng,lat;…")、`color`、`weight`、`opacity`、`line-style` |
|
|
63
|
+
| `tdt-polygon` | `T.Polygon` | 折线 attribute + `fill-color`、`fill-opacity` |
|
|
64
|
+
| `tdt-rectangle` | `T.Rectangle` | `bounds`("swLng,swLat;neLng,neLat")、线与填充 attribute |
|
|
65
|
+
| `tdt-circle` | `T.Circle` | `center`、`radius`、线与填充 attribute |
|
|
66
|
+
| `tdt-label` | `T.Label` | `text`、`lnglat`、`font-color`、`font-size`、`background-color` |
|
|
67
|
+
| `tdt-cloud-marker` | `T.CloudMarkerCollection` | `lnglats`("lng,lat;…")、`styles`(JSON) |
|
|
68
|
+
| `tdt-marker-clusterer` | `T.MarkerClusterer` | 收编子级标注;`grid-size`、`max-zoom` |
|
|
69
|
+
| `tdt-layer-group` | `T.LayerGroup` | 收编子级覆盖物 |
|
|
70
|
+
|
|
71
|
+
### 控件
|
|
72
|
+
|
|
73
|
+
`tdt-control-zoom`、`tdt-control-scale`、`tdt-control-copyright`、`tdt-control-overview-map`、`tdt-control-map-type` — attribute 随官方控件选项(`position`、`zoom-in-text`、`is-open` 等)。
|
|
74
|
+
|
|
75
|
+
### 图层
|
|
76
|
+
|
|
77
|
+
`tdt-tile-layer`、`tdt-tile-layer-wms`、`tdt-tile-layer-tdt`、`tdt-gridline-layer` — `url`(瓦片图层必填)、`opacity`、`z-index`、`bounds`;事件以 `tdt-` 前缀派发(`tdt-load`、`tdt-tileerror` 等)。
|
|
78
|
+
|
|
79
|
+
### 鼠标工具
|
|
80
|
+
|
|
81
|
+
`tdt-polyline-tool`、`tdt-polygon-tool`、`tdt-circle-tool`、`tdt-rectangle-tool`、`tdt-mark-tool`、`tdt-paint-brush-tool`、`tdt-coordinate-pickup` — 经布尔 `active` attribute 开关(presence 语义:框架绑定走 property,attribute 不存在即关闭)。
|
|
82
|
+
|
|
83
|
+
### 标绘
|
|
84
|
+
|
|
85
|
+
22 个标绘实体(`tdt-arc`、`tdt-bezier-curve2`、`tdt-bezier-curve3`、`tdt-bezier-curve-arrow`、`tdt-bezier-curve-n`、`tdt-cardinal-curve`、`tdt-cardinal-curve-arrow`、`tdt-parallel-search`、`tdt-polyline-arrow`、`tdt-sector-search`、`tdt-close-curve`、`tdt-curve-flag`、`tdt-diagonal-arrow`、`tdt-double-arrow`、`tdt-dove-tail-diagonal-arrow`、`tdt-dove-tail-straight-arrow`、`tdt-gathering-place`、`tdt-rect-flag`、`tdt-round-rect`、`tdt-sector`、`tdt-straight-arrow`、`tdt-triangle-flag`)共用 `path` attribute 与线、填充样式;23 个标绘工具(实体 tag 加 `-tool` 后缀,如 `tdt-arc-tool`、`tdt-hand-drawing-tool`)共用 `active` 开关、`style`(JSON)与 JS-only 的 `layers` property。
|
|
86
|
+
|
|
87
|
+
坐标类 attribute 用 `"lng,lat"` 逗号分隔;坐标集合用 `";"` 分隔;纯数据对象用 JSON。SDK 实例(图层组、地图类型等)为 JS-only property,无对应 attribute。
|
|
88
|
+
|
|
89
|
+
## 相关包
|
|
90
|
+
|
|
91
|
+
- [@tianditu/core](https://www.npmjs.com/package/@tianditu/core) — 框架无关内核(自动安装)
|
|
92
|
+
- [@tianditu/vue](https://www.npmjs.com/package/@tianditu/vue) — Vue 3 组件适配层
|
|
93
|
+
- [@tianditu/services](https://www.npmjs.com/package/@tianditu/services) — 类型化 REST 服务客户端
|
|
94
|
+
|
|
95
|
+
## 许可
|
|
96
|
+
|
|
97
|
+
- [MIT](LICENSE) © [Demo Macro](https://www.demomacro.com/)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { OverlayCollector } from "@tianditu/core";
|
|
2
|
+
import { LitElement, PropertyValues } from "lit";
|
|
3
|
+
//#region src/tdt-map.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* 地图容器。light DOM 渲染(createRenderRoot 返回自身):SDK 直接持有
|
|
6
|
+
* 容器并挂载控件、覆盖物与窗体,shadow 边界会隔离 SDK 的样式与 DOM 操作。
|
|
7
|
+
*
|
|
8
|
+
* 子组件经 closest("tdt-map") 取容器、经 whenReady() 等待 SDK 就绪;
|
|
9
|
+
* 地图事件以 `tdt-<官方事件名>` 的 CustomEvent 转发(detail 为 SDK 原生
|
|
10
|
+
* 事件对象),避免与标准 DOM 事件同名混淆。
|
|
11
|
+
*/
|
|
12
|
+
/** "lng,lat" 字符串 → [lng, lat] 数组;attribute 不传时为 undefined(回退默认中心) */
|
|
13
|
+
declare function lnglatConverter(value: string | null): [number, number] | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* 定位方式:attribute 不存在即关闭;空值(presence 写法 `locate`)或
|
|
16
|
+
* "auto" 为自动模式(浏览器定位 → IP 定位),亦可显式写 "geolocation"/"ip"。
|
|
17
|
+
*/
|
|
18
|
+
type LocateMode = boolean | "geolocation" | "ip" | "auto";
|
|
19
|
+
declare function locateConverter(value: string | null): LocateMode;
|
|
20
|
+
declare class TdtMapElement extends LitElement {
|
|
21
|
+
tk: string;
|
|
22
|
+
center?: [number, number];
|
|
23
|
+
locate: LocateMode;
|
|
24
|
+
zoom: number;
|
|
25
|
+
minZoom?: number;
|
|
26
|
+
maxZoom?: number;
|
|
27
|
+
private session?;
|
|
28
|
+
private ready?;
|
|
29
|
+
private unbindEvents?;
|
|
30
|
+
/** 当前地图实例;SDK 就绪前为 undefined */
|
|
31
|
+
get map(): T.Map | undefined;
|
|
32
|
+
static properties: {
|
|
33
|
+
tk: {
|
|
34
|
+
type: StringConstructor;
|
|
35
|
+
};
|
|
36
|
+
center: {
|
|
37
|
+
converter: typeof lnglatConverter;
|
|
38
|
+
};
|
|
39
|
+
locate: {
|
|
40
|
+
converter: typeof locateConverter;
|
|
41
|
+
};
|
|
42
|
+
zoom: {
|
|
43
|
+
type: NumberConstructor;
|
|
44
|
+
};
|
|
45
|
+
minZoom: {
|
|
46
|
+
type: NumberConstructor;
|
|
47
|
+
};
|
|
48
|
+
maxZoom: {
|
|
49
|
+
type: NumberConstructor;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
createRenderRoot(): HTMLElement;
|
|
53
|
+
/** SDK 与地图实例就绪的 promise;子组件挂载前等待 */
|
|
54
|
+
whenReady(): Promise<T.Map>;
|
|
55
|
+
private init;
|
|
56
|
+
connectedCallback(): void;
|
|
57
|
+
disconnectedCallback(): void;
|
|
58
|
+
updated(changed: PropertyValues): void;
|
|
59
|
+
render(): import("lit").TemplateResult<1>;
|
|
60
|
+
}
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/factory.d.ts
|
|
63
|
+
/** 覆盖物元素类(具名类型:d.ts 不展开工厂内的匿名类实现) */
|
|
64
|
+
interface OverlayElementClass<O> {
|
|
65
|
+
new (): LitElement & {
|
|
66
|
+
/** SDK 实例就绪 promise(容器收编子级、InfoWindow 宿主等待) */
|
|
67
|
+
whenInstance(): Promise<O>;
|
|
68
|
+
/** 当前 SDK 实例;未挂载时 undefined */
|
|
69
|
+
readonly instance: O | undefined;
|
|
70
|
+
/** 收集容器时把实例适配为 OverlayCollector */
|
|
71
|
+
collectorFor(instance: O): OverlayCollector;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** 工具元素类(具名类型) */
|
|
75
|
+
interface ToolElementClass {
|
|
76
|
+
new (): LitElement & {
|
|
77
|
+
/** 受控开关:attribute 存在即开启 */
|
|
78
|
+
active: boolean;
|
|
79
|
+
/** SDK 工具实例就绪 promise */
|
|
80
|
+
whenInstance(): Promise<unknown>;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/** 控件元素类(具名类型) */
|
|
84
|
+
interface ControlElementClass {
|
|
85
|
+
new (): LitElement & {
|
|
86
|
+
/** 当前 SDK 控件实例;未挂载时 undefined */
|
|
87
|
+
readonly instance: T.Control | undefined;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/** 图层元素类(具名类型) */
|
|
91
|
+
interface LayerElementClass {
|
|
92
|
+
new (): LitElement & {
|
|
93
|
+
/** SDK 图层实例就绪 promise */
|
|
94
|
+
whenInstance(): Promise<T.TileLayer>;
|
|
95
|
+
/** 当前 SDK 图层实例;未挂载时 undefined */
|
|
96
|
+
readonly instance: T.TileLayer | undefined;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/overlays.d.ts
|
|
101
|
+
/**
|
|
102
|
+
* 覆盖物元素:定义(props/构造/sync/事件表)见 core defs,元素只承载
|
|
103
|
+
* attribute 声明与生命周期桥接。attribute 命名随官方 Options 字段
|
|
104
|
+
* (kebab-case);坐标 "lng,lat"、集合 "lng,lat;…"、对象 JSON。
|
|
105
|
+
*/
|
|
106
|
+
declare const TdtMarkerElement: OverlayElementClass<T.Marker>;
|
|
107
|
+
declare const TdtPolylineElement: OverlayElementClass<T.Polyline>;
|
|
108
|
+
declare const TdtPolygonElement: OverlayElementClass<T.Polygon>;
|
|
109
|
+
declare const TdtRectangleElement: OverlayElementClass<T.Rectangle>;
|
|
110
|
+
declare const TdtLabelElement: OverlayElementClass<T.Label>;
|
|
111
|
+
declare const TdtCircleElement: OverlayElementClass<T.Circle>;
|
|
112
|
+
declare const TdtCloudMarkerElement: OverlayElementClass<T.CloudMarkerCollection>;
|
|
113
|
+
/** 点聚合容器:子级 tdt-marker 经 DOM 就近收编加入聚合而非直接上屏 */
|
|
114
|
+
declare const TdtMarkerClustererElement: OverlayElementClass<T.MarkerClusterer>;
|
|
115
|
+
/** 图层组容器:子级覆盖物加入容器,容器卸载时随 clearLayers 清空 */
|
|
116
|
+
declare const TdtLayerGroupElement: OverlayElementClass<T.LayerGroup>;
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/controls.d.ts
|
|
119
|
+
/**
|
|
120
|
+
* 控件元素:定义(props/构造)见 core defs,attribute 声明与 addControl/
|
|
121
|
+
* removeControl 生命周期编排已在 factory 的 makeControlElement。
|
|
122
|
+
*/
|
|
123
|
+
declare const TdtControlZoomElement: ControlElementClass;
|
|
124
|
+
declare const TdtControlScaleElement: ControlElementClass;
|
|
125
|
+
declare const TdtControlCopyrightElement: ControlElementClass;
|
|
126
|
+
declare const TdtControlOverviewMapElement: ControlElementClass;
|
|
127
|
+
declare const TdtControlMapTypeElement: ControlElementClass;
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/layers.d.ts
|
|
130
|
+
/**
|
|
131
|
+
* 瓦片图层元素:定义(props/构造/sync/事件表)见 core defs,元素只承载
|
|
132
|
+
* attribute 声明与生命周期桥接。url 为必填 attribute;bounds 用
|
|
133
|
+
* "swLng,swLat;neLng,neLat" 形态;格网图层的样式对象用 JSON。
|
|
134
|
+
*/
|
|
135
|
+
declare const TdtTileLayerElement: LayerElementClass;
|
|
136
|
+
declare const TdtTileLayerWmsElement: LayerElementClass;
|
|
137
|
+
declare const TdtTileLayerTdtElement: LayerElementClass;
|
|
138
|
+
declare const TdtGridlineLayerElement: LayerElementClass;
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/plot-entities.d.ts
|
|
141
|
+
/**
|
|
142
|
+
* 标绘覆盖物元素:定义(props/构造/sync)见 core defs,vue/wc 共享。
|
|
143
|
+
* attribute path 形如 "lng,lat;lng,lat";样式 props 仅构造时生效。
|
|
144
|
+
*/
|
|
145
|
+
declare const TdtArcElement: OverlayElementClass<T.Arc>;
|
|
146
|
+
declare const TdtBezierCurve2Element: OverlayElementClass<T.BezierCurve2>;
|
|
147
|
+
declare const TdtBezierCurve3Element: OverlayElementClass<T.BezierCurve3>;
|
|
148
|
+
declare const TdtBezierCurveArrowElement: OverlayElementClass<T.BezierCurveArrow>;
|
|
149
|
+
declare const TdtBezierCurveNElement: OverlayElementClass<T.BezierCurveN>;
|
|
150
|
+
declare const TdtCardinalCurveElement: OverlayElementClass<T.CardinalCurve>;
|
|
151
|
+
declare const TdtCardinalCurveArrowElement: OverlayElementClass<T.CardinalCurveArrow>;
|
|
152
|
+
declare const TdtParallelSearchElement: OverlayElementClass<T.ParallelSearch>;
|
|
153
|
+
declare const TdtPolylineArrowElement: OverlayElementClass<T.PolylineArrow>;
|
|
154
|
+
declare const TdtSectorSearchElement: OverlayElementClass<T.SectorSearch>;
|
|
155
|
+
declare const TdtCloseCurveElement: OverlayElementClass<T.CloseCurve>;
|
|
156
|
+
declare const TdtCurveFlagElement: OverlayElementClass<T.CurveFlag>;
|
|
157
|
+
declare const TdtDiagonalArrowElement: OverlayElementClass<T.DiagonalArrow>;
|
|
158
|
+
declare const TdtDoubleArrowElement: OverlayElementClass<T.DoubleArrow>;
|
|
159
|
+
declare const TdtDoveTailDiagonalArrowElement: OverlayElementClass<T.DoveTailDiagonalArrow>;
|
|
160
|
+
declare const TdtDoveTailStraightArrowElement: OverlayElementClass<T.DoveTailStraightArrow>;
|
|
161
|
+
declare const TdtGatheringPlaceElement: OverlayElementClass<T.GatheringPlace>;
|
|
162
|
+
declare const TdtRectFlagElement: OverlayElementClass<T.RectFlag>;
|
|
163
|
+
declare const TdtRoundRectElement: OverlayElementClass<T.RoundRect>;
|
|
164
|
+
declare const TdtSectorElement: OverlayElementClass<T.Sector>;
|
|
165
|
+
declare const TdtStraightArrowElement: OverlayElementClass<T.StraightArrow>;
|
|
166
|
+
declare const TdtTriangleFlagElement: OverlayElementClass<T.TriangleFlag>;
|
|
167
|
+
//#endregion
|
|
168
|
+
//#region src/plot-tools.d.ts
|
|
169
|
+
/**
|
|
170
|
+
* 标绘工具元素族:定义见 core defs,vue/wc 共享。active attribute
|
|
171
|
+
* (presence 语义)受控开关,事件以 `tdt-<官方事件名>` 转发(如 tdt-dbclick)。
|
|
172
|
+
*/
|
|
173
|
+
declare const TdtArcToolElement: ToolElementClass;
|
|
174
|
+
declare const TdtBezierCurve2ToolElement: ToolElementClass;
|
|
175
|
+
declare const TdtBezierCurve3ToolElement: ToolElementClass;
|
|
176
|
+
declare const TdtBezierCurveArrowToolElement: ToolElementClass;
|
|
177
|
+
declare const TdtBezierCurveNToolElement: ToolElementClass;
|
|
178
|
+
declare const TdtCardinalCurveArrowToolElement: ToolElementClass;
|
|
179
|
+
declare const TdtCardinalCurveToolElement: ToolElementClass;
|
|
180
|
+
declare const TdtCloseCurveToolElement: ToolElementClass;
|
|
181
|
+
declare const TdtCurveFlagToolElement: ToolElementClass;
|
|
182
|
+
declare const TdtDiagonalArrowToolElement: ToolElementClass;
|
|
183
|
+
declare const TdtDoubleArrowToolElement: ToolElementClass;
|
|
184
|
+
declare const TdtDoveTailDiagonalArrowToolElement: ToolElementClass;
|
|
185
|
+
declare const TdtDoveTailStraightArrowToolElement: ToolElementClass;
|
|
186
|
+
declare const TdtGatheringPlaceToolElement: ToolElementClass;
|
|
187
|
+
declare const TdtHandDrawingToolElement: ToolElementClass;
|
|
188
|
+
declare const TdtParallelSearchToolElement: ToolElementClass;
|
|
189
|
+
declare const TdtPolylineArrowToolElement: ToolElementClass;
|
|
190
|
+
declare const TdtRectFlagToolElement: ToolElementClass;
|
|
191
|
+
declare const TdtRoundRectToolElement: ToolElementClass;
|
|
192
|
+
declare const TdtSectorSearchToolElement: ToolElementClass;
|
|
193
|
+
declare const TdtSectorToolElement: ToolElementClass;
|
|
194
|
+
declare const TdtStraightArrowToolElement: ToolElementClass;
|
|
195
|
+
declare const TdtTriangleFlagToolElement: ToolElementClass;
|
|
196
|
+
//#endregion
|
|
197
|
+
//#region src/info-window.d.ts
|
|
198
|
+
/**
|
|
199
|
+
* 信息窗元素。内容为元素自身的子节点(light DOM),经 MutationObserver
|
|
200
|
+
* 克隆进窗体容器:SDK 在 open 时会搬移内容容器,克隆可保持元素内原始
|
|
201
|
+
* 子节点稳定,且避免 observer 被搬移触发误清窗口(vue 适配层同款方案)。
|
|
202
|
+
* 独立使用时经 lnglat 属性由地图打开;嵌套在覆盖物元素内时由宿主打开。
|
|
203
|
+
* attribute 随官方 InfoWindowOptions 字段(kebab-case)。
|
|
204
|
+
*/
|
|
205
|
+
/** "x,y" 属性 → T.Point */
|
|
206
|
+
declare function pointConverter(value: string | null): T.Point | undefined;
|
|
207
|
+
declare class TdtInfoWindowElement extends LitElement {
|
|
208
|
+
static properties: {
|
|
209
|
+
open: {
|
|
210
|
+
type: BooleanConstructor;
|
|
211
|
+
reflect: boolean;
|
|
212
|
+
};
|
|
213
|
+
lnglat: {
|
|
214
|
+
converter: typeof lnglatConverter;
|
|
215
|
+
};
|
|
216
|
+
minWidth: {
|
|
217
|
+
type: NumberConstructor;
|
|
218
|
+
attribute: string;
|
|
219
|
+
};
|
|
220
|
+
maxWidth: {
|
|
221
|
+
type: NumberConstructor;
|
|
222
|
+
attribute: string;
|
|
223
|
+
};
|
|
224
|
+
maxHeight: {
|
|
225
|
+
type: NumberConstructor;
|
|
226
|
+
attribute: string;
|
|
227
|
+
};
|
|
228
|
+
autoPan: {
|
|
229
|
+
type: BooleanConstructor;
|
|
230
|
+
attribute: string;
|
|
231
|
+
};
|
|
232
|
+
closeButton: {
|
|
233
|
+
type: BooleanConstructor;
|
|
234
|
+
attribute: string;
|
|
235
|
+
};
|
|
236
|
+
offset: {
|
|
237
|
+
converter: typeof pointConverter;
|
|
238
|
+
};
|
|
239
|
+
autoPanPadding: {
|
|
240
|
+
converter: typeof pointConverter;
|
|
241
|
+
attribute: string;
|
|
242
|
+
};
|
|
243
|
+
closeOnClick: {
|
|
244
|
+
type: BooleanConstructor;
|
|
245
|
+
attribute: string;
|
|
246
|
+
};
|
|
247
|
+
};
|
|
248
|
+
open: boolean;
|
|
249
|
+
lnglat?: [number, number];
|
|
250
|
+
minWidth?: number;
|
|
251
|
+
maxWidth?: number;
|
|
252
|
+
maxHeight?: number;
|
|
253
|
+
autoPan?: boolean;
|
|
254
|
+
closeButton?: boolean;
|
|
255
|
+
offset?: T.Point;
|
|
256
|
+
autoPanPadding?: T.Point;
|
|
257
|
+
closeOnClick?: boolean;
|
|
258
|
+
private handle?;
|
|
259
|
+
private observer?;
|
|
260
|
+
private map?;
|
|
261
|
+
/** 就近解析到的覆盖物宿主(如 tdt-marker);无宿主时为 undefined */
|
|
262
|
+
private host?;
|
|
263
|
+
connectedCallback(): void;
|
|
264
|
+
disconnectedCallback(): void;
|
|
265
|
+
/** 把元素子节点克隆进窗体容器 */
|
|
266
|
+
private syncContent;
|
|
267
|
+
private syncOpen;
|
|
268
|
+
protected updated(): void;
|
|
269
|
+
}
|
|
270
|
+
//#endregion
|
|
271
|
+
//#region src/tools.d.ts
|
|
272
|
+
/**
|
|
273
|
+
* 鼠标工具元素:定义见 core defs;active attribute(presence 语义)受控
|
|
274
|
+
* 开关。事件以 `tdt-<官方事件名>` 转发(如 tdt-draw)。
|
|
275
|
+
*/
|
|
276
|
+
declare const TdtPolylineToolElement: ToolElementClass;
|
|
277
|
+
declare const TdtPolygonToolElement: ToolElementClass;
|
|
278
|
+
declare const TdtCircleToolElement: ToolElementClass;
|
|
279
|
+
declare const TdtRectangleToolElement: ToolElementClass;
|
|
280
|
+
declare const TdtMarkToolElement: ToolElementClass;
|
|
281
|
+
declare const TdtPaintBrushToolElement: ToolElementClass;
|
|
282
|
+
/**
|
|
283
|
+
* 坐标拾取元素(官方 CoordinatePickup):非 Mousetool 体系,以
|
|
284
|
+
* addEvent/removeEvent 开关;官方 Options.callback 转写为 tdt-pick 事件
|
|
285
|
+
* (SDK 点击地图即调用 callback,未设置时点击会抛错,故构造必传)。
|
|
286
|
+
*/
|
|
287
|
+
declare class TdtCoordinatePickupElement extends LitElement {
|
|
288
|
+
static properties: {
|
|
289
|
+
active: {
|
|
290
|
+
type: BooleanConstructor;
|
|
291
|
+
reflect: boolean;
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
/** 受控开关:attribute 存在即开启 */
|
|
295
|
+
active: boolean;
|
|
296
|
+
private pickup?;
|
|
297
|
+
private callback;
|
|
298
|
+
connectedCallback(): void;
|
|
299
|
+
updated(changed: PropertyValues): void;
|
|
300
|
+
disconnectedCallback(): void;
|
|
301
|
+
render(): import("lit").TemplateResult<1>;
|
|
302
|
+
}
|
|
303
|
+
//#endregion
|
|
304
|
+
//#region src/index.d.ts
|
|
305
|
+
/** tag → 元素类注册表(registerComponents 与副作用注册共用) */
|
|
306
|
+
declare const ELEMENTS: Array<[string, CustomElementConstructor]>;
|
|
307
|
+
/**
|
|
308
|
+
* 注册全部自定义元素;已注册的 tag 自动跳过(重复 import 安全)。
|
|
309
|
+
* SSR/Node 环境无 customElements,静默跳过(客户端水合后再调用)。
|
|
310
|
+
*/
|
|
311
|
+
declare function registerComponents(): void;
|
|
312
|
+
//#endregion
|
|
313
|
+
export { ELEMENTS, TdtArcElement, TdtArcToolElement, TdtBezierCurve2Element, TdtBezierCurve2ToolElement, TdtBezierCurve3Element, TdtBezierCurve3ToolElement, TdtBezierCurveArrowElement, TdtBezierCurveArrowToolElement, TdtBezierCurveNElement, TdtBezierCurveNToolElement, TdtCardinalCurveArrowElement, TdtCardinalCurveArrowToolElement, TdtCardinalCurveElement, TdtCardinalCurveToolElement, TdtCircleElement, TdtCircleToolElement, TdtCloseCurveElement, TdtCloseCurveToolElement, TdtCloudMarkerElement, TdtControlCopyrightElement, TdtControlMapTypeElement, TdtControlOverviewMapElement, TdtControlScaleElement, TdtControlZoomElement, TdtCoordinatePickupElement, TdtCurveFlagElement, TdtCurveFlagToolElement, TdtDiagonalArrowElement, TdtDiagonalArrowToolElement, TdtDoubleArrowElement, TdtDoubleArrowToolElement, TdtDoveTailDiagonalArrowElement, TdtDoveTailDiagonalArrowToolElement, TdtDoveTailStraightArrowElement, TdtDoveTailStraightArrowToolElement, TdtGatheringPlaceElement, TdtGatheringPlaceToolElement, TdtGridlineLayerElement, TdtHandDrawingToolElement, TdtInfoWindowElement, TdtLabelElement, TdtLayerGroupElement, TdtMapElement, TdtMarkToolElement, TdtMarkerClustererElement, TdtMarkerElement, TdtPaintBrushToolElement, TdtParallelSearchElement, TdtParallelSearchToolElement, TdtPolygonElement, TdtPolygonToolElement, TdtPolylineArrowElement, TdtPolylineArrowToolElement, TdtPolylineElement, TdtPolylineToolElement, TdtRectFlagElement, TdtRectFlagToolElement, TdtRectangleElement, TdtRectangleToolElement, TdtRoundRectElement, TdtRoundRectToolElement, TdtSectorElement, TdtSectorSearchElement, TdtSectorSearchToolElement, TdtSectorToolElement, TdtStraightArrowElement, TdtStraightArrowToolElement, TdtTileLayerElement, TdtTileLayerTdtElement, TdtTileLayerWmsElement, TdtTriangleFlagElement, TdtTriangleFlagToolElement, lnglatConverter, registerComponents };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,771 @@
|
|
|
1
|
+
import { MAP_EVENT_NAMES, arcDef, arcToolDef, bezierCurve2Def, bezierCurve2ToolDef, bezierCurve3Def, bezierCurve3ToolDef, bezierCurveArrowDef, bezierCurveArrowToolDef, bezierCurveNDef, bezierCurveNToolDef, bindEventNames, cardinalCurveArrowDef, cardinalCurveArrowToolDef, cardinalCurveDef, cardinalCurveToolDef, circleDef, circleToolDef, closeCurveDef, closeCurveToolDef, cloudMarkerDef, compact, copyrightDef, createInfoWindow, createMapSession, createWhenReady, curveFlagDef, curveFlagToolDef, diagonalArrowDef, diagonalArrowToolDef, doubleArrowDef, doubleArrowToolDef, doveTailDiagonalArrowDef, doveTailDiagonalArrowToolDef, doveTailStraightArrowDef, doveTailStraightArrowToolDef, gatheringPlaceDef, gatheringPlaceToolDef, gridlineLayerDef, handDrawingToolDef, labelDef, layerGroupDef, mapTypeDef, markToolDef, markerClustererDef, markerDef, mountOverlay, mountTileLayer, mountTool, overviewMapDef, paintBrushToolDef, parallelSearchDef, parallelSearchToolDef, parseLnglat, polygonDef, polygonToolDef, polylineArrowDef, polylineArrowToolDef, polylineDef, polylineToolDef, rectFlagDef, rectFlagToolDef, rectangleDef, rectangleToolDef, roundRectDef, roundRectToolDef, scaleDef, sectorDef, sectorSearchDef, sectorSearchToolDef, sectorToolDef, straightArrowDef, straightArrowToolDef, tileLayerDef, tileLayerTdtDef, tileLayerWmsDef, toLngLat, triangleFlagDef, triangleFlagToolDef, zoomDef } from "@tianditu/core";
|
|
2
|
+
import { LitElement, html } from "lit";
|
|
3
|
+
//#region src/context.ts
|
|
4
|
+
/** SDK 事件 → `tdt-<name>` CustomEvent(detail 为原生事件对象) */
|
|
5
|
+
function dispatchTdtEvent(el) {
|
|
6
|
+
return (name, event) => {
|
|
7
|
+
el.dispatchEvent(new CustomEvent(`tdt-${name}`, {
|
|
8
|
+
detail: event,
|
|
9
|
+
bubbles: true,
|
|
10
|
+
composed: true
|
|
11
|
+
}));
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/** 就近查找地图容器 */
|
|
15
|
+
function findMap(el) {
|
|
16
|
+
return el.closest("tdt-map");
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 就近解析覆盖物收集容器:layer-group 优先于 marker-clusterer
|
|
20
|
+
* (与 Vue 适配层的「内层容器就近收编」一致)。无容器时 undefined。
|
|
21
|
+
*/
|
|
22
|
+
function resolveCollector(el) {
|
|
23
|
+
const source = el.closest("tdt-layer-group") ?? el.closest("tdt-marker-clusterer");
|
|
24
|
+
if (!source) return Promise.resolve(void 0);
|
|
25
|
+
return customElements.whenDefined(source.localName).then(async () => {
|
|
26
|
+
const host = source;
|
|
27
|
+
const instance = await host.whenInstance();
|
|
28
|
+
return host.collectorFor(instance);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/** 向上查找最近的覆盖物宿主(InfoWindow 嵌套在覆盖物元素内时由宿主打开) */
|
|
32
|
+
function resolveHostOverlay(el) {
|
|
33
|
+
let current = el.parentElement;
|
|
34
|
+
while (current) {
|
|
35
|
+
if (typeof current.whenInstance === "function") {
|
|
36
|
+
const host = current;
|
|
37
|
+
return customElements.whenDefined(host.localName).then(() => host.whenInstance());
|
|
38
|
+
}
|
|
39
|
+
current = current.parentElement;
|
|
40
|
+
}
|
|
41
|
+
return Promise.resolve(void 0);
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/factory.ts
|
|
45
|
+
/** defs 中立 props → lit reactive properties */
|
|
46
|
+
function litProperties(props) {
|
|
47
|
+
const out = {};
|
|
48
|
+
for (const key in props) {
|
|
49
|
+
const def = props[key];
|
|
50
|
+
if (!def.attribute) {
|
|
51
|
+
out[key] = {
|
|
52
|
+
type: Object,
|
|
53
|
+
attribute: false
|
|
54
|
+
};
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
out[key] = {
|
|
58
|
+
type: def.type ?? Object,
|
|
59
|
+
attribute: def.attribute,
|
|
60
|
+
...def.converter ? { converter: (value) => value == null ? void 0 : def.converter(value) } : {},
|
|
61
|
+
...def.reflect ? { reflect: true } : {}
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
/** 从元素自身的 property 值收集 defs 形状的 props */
|
|
67
|
+
function collectProps(el, props) {
|
|
68
|
+
const out = {};
|
|
69
|
+
for (const key in props) out[key] = el[key];
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
/** 构造期默认值落位:attribute 未提供时 defs 的 default 生效 */
|
|
73
|
+
function applyDefaults(el, props) {
|
|
74
|
+
for (const key in props) {
|
|
75
|
+
const { default: fallback } = props[key];
|
|
76
|
+
if (fallback !== void 0) el[key] = typeof fallback === "function" ? fallback() : fallback;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* lit property 变更 diff → sync setter。lit 无响应式追踪(core 的
|
|
81
|
+
* createPropsSync 面向响应式 getter,仅 vue 适配层使用),在 updated
|
|
82
|
+
* 里手动驱动:变更的 key 即 diff 结果,旧值取 lit 记录的上一帧。
|
|
83
|
+
*/
|
|
84
|
+
function applySyncDiff(instance, sync, changed, props) {
|
|
85
|
+
for (const [key, prev] of changed) {
|
|
86
|
+
const apply = sync[key];
|
|
87
|
+
if (apply) apply(instance, props[key], prev);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/** 实例就绪 deferred:whenInstance 惰性建 promise,落定时放行(三族元素工厂共用) */
|
|
91
|
+
function deferredInstance() {
|
|
92
|
+
let resolve;
|
|
93
|
+
const promise = new Promise((res) => resolve = res);
|
|
94
|
+
return {
|
|
95
|
+
when: () => promise,
|
|
96
|
+
resolve: (value) => resolve(value)
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 覆盖物元素工厂。生命周期与 vue 的 defineOverlayComponent 同构:
|
|
101
|
+
* createWhenReady 守卫构造(SDK 扩展类异步加载)→ 解析收集容器 →
|
|
102
|
+
* mountOverlay 编排挂载/同步/事件 → 卸载清理。
|
|
103
|
+
*/
|
|
104
|
+
function makeOverlayElement(def, options) {
|
|
105
|
+
class OverlayElement extends LitElement {
|
|
106
|
+
static {
|
|
107
|
+
this.properties = litProperties(def.props);
|
|
108
|
+
}
|
|
109
|
+
constructor() {
|
|
110
|
+
super();
|
|
111
|
+
this.deferred = deferredInstance();
|
|
112
|
+
applyDefaults(this, def.props);
|
|
113
|
+
}
|
|
114
|
+
/** SDK 实例就绪 promise(容器收编子级、InfoWindow 宿主等待) */
|
|
115
|
+
whenInstance() {
|
|
116
|
+
return this.deferred.when();
|
|
117
|
+
}
|
|
118
|
+
/** 当前 SDK 实例;未挂载时 undefined */
|
|
119
|
+
get instance() {
|
|
120
|
+
return this.handle?.instance;
|
|
121
|
+
}
|
|
122
|
+
collectorFor(instance) {
|
|
123
|
+
if (!options?.collector) throw new Error(`<${def.tag}> 不是覆盖物收集容器`);
|
|
124
|
+
return options.collector(instance);
|
|
125
|
+
}
|
|
126
|
+
props() {
|
|
127
|
+
return collectProps(this, def.props);
|
|
128
|
+
}
|
|
129
|
+
connectedCallback() {
|
|
130
|
+
super.connectedCallback();
|
|
131
|
+
const container = findMap(this);
|
|
132
|
+
if (!container) return;
|
|
133
|
+
Promise.all([container.whenReady().then((map) => createWhenReady(() => def.create(this.props(), { map }))), resolveCollector(this)]).then(([created, collector]) => {
|
|
134
|
+
const map = container.map;
|
|
135
|
+
if (!map || this.handle || !this.isConnected) return;
|
|
136
|
+
this.handle = mountOverlay({
|
|
137
|
+
map,
|
|
138
|
+
collector
|
|
139
|
+
}, {
|
|
140
|
+
props: () => this.props(),
|
|
141
|
+
events: def.events,
|
|
142
|
+
dispatch: dispatchTdtEvent(this),
|
|
143
|
+
create: () => created,
|
|
144
|
+
attach: def.attach,
|
|
145
|
+
detach: def.detach
|
|
146
|
+
});
|
|
147
|
+
this.deferred.resolve(this.handle.instance);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
updated(changed) {
|
|
151
|
+
if (!this.handle || !def.sync || changed.size === 0) return;
|
|
152
|
+
applySyncDiff(this.handle.instance, def.sync, changed, this.props());
|
|
153
|
+
}
|
|
154
|
+
disconnectedCallback() {
|
|
155
|
+
super.disconnectedCallback();
|
|
156
|
+
this.handle?.destroy();
|
|
157
|
+
this.handle = void 0;
|
|
158
|
+
}
|
|
159
|
+
render() {
|
|
160
|
+
return html``;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return OverlayElement;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* 鼠标工具元素工厂。受控 active attribute(presence 语义 + reflect)驱动
|
|
167
|
+
* mountTool 的开关;attribute 变化在 updated 统一应用——session 未就绪时
|
|
168
|
+
* 由落定回调读取当前值,最后写入胜出。
|
|
169
|
+
*/
|
|
170
|
+
function makeToolElement(def) {
|
|
171
|
+
class ToolElement extends LitElement {
|
|
172
|
+
constructor(..._args) {
|
|
173
|
+
super(..._args);
|
|
174
|
+
this.active = false;
|
|
175
|
+
this.deferred = deferredInstance();
|
|
176
|
+
}
|
|
177
|
+
static {
|
|
178
|
+
this.properties = {
|
|
179
|
+
active: {
|
|
180
|
+
type: Boolean,
|
|
181
|
+
reflect: true
|
|
182
|
+
},
|
|
183
|
+
...litProperties(def.props)
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/** SDK 工具实例就绪 promise */
|
|
187
|
+
whenInstance() {
|
|
188
|
+
return this.deferred.when();
|
|
189
|
+
}
|
|
190
|
+
props() {
|
|
191
|
+
return collectProps(this, def.props);
|
|
192
|
+
}
|
|
193
|
+
connectedCallback() {
|
|
194
|
+
super.connectedCallback();
|
|
195
|
+
const container = findMap(this);
|
|
196
|
+
if (!container) return;
|
|
197
|
+
container.whenReady().then((map) => createWhenReady(() => def.create(this.props(), map))).then((created) => {
|
|
198
|
+
if (this.session || !this.isConnected) return;
|
|
199
|
+
this.session = mountTool({
|
|
200
|
+
map: container.map,
|
|
201
|
+
create: () => created,
|
|
202
|
+
events: def.events,
|
|
203
|
+
dispatch: dispatchTdtEvent(this),
|
|
204
|
+
activate: def.activate,
|
|
205
|
+
deactivate: def.deactivate
|
|
206
|
+
});
|
|
207
|
+
this.deferred.resolve(this.session.tool);
|
|
208
|
+
this.session.setActive(this.active);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
updated(changed) {
|
|
212
|
+
if (changed.has("active")) this.session?.setActive(this.active);
|
|
213
|
+
}
|
|
214
|
+
disconnectedCallback() {
|
|
215
|
+
super.disconnectedCallback();
|
|
216
|
+
this.session?.destroy();
|
|
217
|
+
this.session = void 0;
|
|
218
|
+
}
|
|
219
|
+
render() {
|
|
220
|
+
return html``;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return ToolElement;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* 控件元素工厂:attribute → SDK 控件构造并 addControl,卸载 removeControl。
|
|
227
|
+
* 与 vue 的 defineControlComponent 同构:构造经 createWhenReady 守卫。
|
|
228
|
+
*/
|
|
229
|
+
function makeControlElement(def) {
|
|
230
|
+
class ControlElement extends LitElement {
|
|
231
|
+
static {
|
|
232
|
+
this.properties = litProperties(def.props);
|
|
233
|
+
}
|
|
234
|
+
constructor() {
|
|
235
|
+
super();
|
|
236
|
+
applyDefaults(this, def.props);
|
|
237
|
+
}
|
|
238
|
+
get instance() {
|
|
239
|
+
return this.control;
|
|
240
|
+
}
|
|
241
|
+
props() {
|
|
242
|
+
return collectProps(this, def.props);
|
|
243
|
+
}
|
|
244
|
+
connectedCallback() {
|
|
245
|
+
super.connectedCallback();
|
|
246
|
+
const container = findMap(this);
|
|
247
|
+
if (!container) return;
|
|
248
|
+
container.whenReady().then((map) => createWhenReady(() => def.create(this.props())).then((control) => {
|
|
249
|
+
if (this.control || !this.isConnected) return;
|
|
250
|
+
this.control = control;
|
|
251
|
+
map.addControl(control);
|
|
252
|
+
})).catch(() => {});
|
|
253
|
+
}
|
|
254
|
+
disconnectedCallback() {
|
|
255
|
+
super.disconnectedCallback();
|
|
256
|
+
const map = findMap(this)?.map;
|
|
257
|
+
if (this.control && map) map.removeControl(this.control);
|
|
258
|
+
this.control = void 0;
|
|
259
|
+
}
|
|
260
|
+
render() {
|
|
261
|
+
return html``;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
return ControlElement;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* 瓦片图层元素工厂:create → mountTileLayer 上屏与事件;props 变更在
|
|
268
|
+
* updated 里 diff 应用 sync(defs 默认为 url/opacity/zIndex 同步表)。
|
|
269
|
+
*/
|
|
270
|
+
function makeLayerElement(def) {
|
|
271
|
+
class LayerElement extends LitElement {
|
|
272
|
+
static {
|
|
273
|
+
this.properties = litProperties(def.props);
|
|
274
|
+
}
|
|
275
|
+
constructor() {
|
|
276
|
+
super();
|
|
277
|
+
this.deferred = deferredInstance();
|
|
278
|
+
applyDefaults(this, def.props);
|
|
279
|
+
}
|
|
280
|
+
whenInstance() {
|
|
281
|
+
return this.deferred.when();
|
|
282
|
+
}
|
|
283
|
+
get instance() {
|
|
284
|
+
return this.layer;
|
|
285
|
+
}
|
|
286
|
+
props() {
|
|
287
|
+
return collectProps(this, def.props);
|
|
288
|
+
}
|
|
289
|
+
connectedCallback() {
|
|
290
|
+
super.connectedCallback();
|
|
291
|
+
const container = findMap(this);
|
|
292
|
+
if (!container) return;
|
|
293
|
+
container.whenReady().then((map) => createWhenReady(() => def.create(this.props())).then((layer) => {
|
|
294
|
+
if (this.layer || !this.isConnected) return;
|
|
295
|
+
this.layer = layer;
|
|
296
|
+
this.unmount = mountTileLayer({
|
|
297
|
+
map,
|
|
298
|
+
layer,
|
|
299
|
+
events: def.events,
|
|
300
|
+
dispatch: dispatchTdtEvent(this)
|
|
301
|
+
});
|
|
302
|
+
this.deferred.resolve(layer);
|
|
303
|
+
})).catch(() => {});
|
|
304
|
+
}
|
|
305
|
+
updated(changed) {
|
|
306
|
+
if (!this.layer || !def.sync || changed.size === 0) return;
|
|
307
|
+
applySyncDiff(this.layer, def.sync, changed, this.props());
|
|
308
|
+
}
|
|
309
|
+
disconnectedCallback() {
|
|
310
|
+
super.disconnectedCallback();
|
|
311
|
+
this.unmount?.();
|
|
312
|
+
this.unmount = void 0;
|
|
313
|
+
this.layer = void 0;
|
|
314
|
+
}
|
|
315
|
+
render() {
|
|
316
|
+
return html``;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
return LayerElement;
|
|
320
|
+
}
|
|
321
|
+
//#endregion
|
|
322
|
+
//#region src/controls.ts
|
|
323
|
+
/**
|
|
324
|
+
* 控件元素:定义(props/构造)见 core defs,attribute 声明与 addControl/
|
|
325
|
+
* removeControl 生命周期编排已在 factory 的 makeControlElement。
|
|
326
|
+
*/
|
|
327
|
+
const TdtControlZoomElement = makeControlElement(zoomDef);
|
|
328
|
+
const TdtControlScaleElement = makeControlElement(scaleDef);
|
|
329
|
+
const TdtControlCopyrightElement = makeControlElement(copyrightDef);
|
|
330
|
+
const TdtControlOverviewMapElement = makeControlElement(overviewMapDef);
|
|
331
|
+
const TdtControlMapTypeElement = makeControlElement(mapTypeDef);
|
|
332
|
+
//#endregion
|
|
333
|
+
//#region src/tdt-map.ts
|
|
334
|
+
/**
|
|
335
|
+
* 地图容器。light DOM 渲染(createRenderRoot 返回自身):SDK 直接持有
|
|
336
|
+
* 容器并挂载控件、覆盖物与窗体,shadow 边界会隔离 SDK 的样式与 DOM 操作。
|
|
337
|
+
*
|
|
338
|
+
* 子组件经 closest("tdt-map") 取容器、经 whenReady() 等待 SDK 就绪;
|
|
339
|
+
* 地图事件以 `tdt-<官方事件名>` 的 CustomEvent 转发(detail 为 SDK 原生
|
|
340
|
+
* 事件对象),避免与标准 DOM 事件同名混淆。
|
|
341
|
+
*/
|
|
342
|
+
/** "lng,lat" 字符串 → [lng, lat] 数组;attribute 不传时为 undefined(回退默认中心) */
|
|
343
|
+
function lnglatConverter(value) {
|
|
344
|
+
return value ? parseLnglat(value) : void 0;
|
|
345
|
+
}
|
|
346
|
+
function locateConverter(value) {
|
|
347
|
+
if (value === null) return false;
|
|
348
|
+
if (value === "") return true;
|
|
349
|
+
return value;
|
|
350
|
+
}
|
|
351
|
+
var TdtMapElement = class extends LitElement {
|
|
352
|
+
constructor(..._args) {
|
|
353
|
+
super(..._args);
|
|
354
|
+
this.tk = "";
|
|
355
|
+
this.locate = false;
|
|
356
|
+
this.zoom = 12;
|
|
357
|
+
}
|
|
358
|
+
/** 当前地图实例;SDK 就绪前为 undefined */
|
|
359
|
+
get map() {
|
|
360
|
+
return this.session?.map;
|
|
361
|
+
}
|
|
362
|
+
static {
|
|
363
|
+
this.properties = {
|
|
364
|
+
tk: { type: String },
|
|
365
|
+
center: { converter: lnglatConverter },
|
|
366
|
+
locate: { converter: locateConverter },
|
|
367
|
+
zoom: { type: Number },
|
|
368
|
+
minZoom: { type: Number },
|
|
369
|
+
maxZoom: { type: Number }
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
createRenderRoot() {
|
|
373
|
+
return this;
|
|
374
|
+
}
|
|
375
|
+
/** SDK 与地图实例就绪的 promise;子组件挂载前等待 */
|
|
376
|
+
whenReady() {
|
|
377
|
+
return this.ready ??= this.init();
|
|
378
|
+
}
|
|
379
|
+
async init() {
|
|
380
|
+
const session = await createMapSession(this, {
|
|
381
|
+
tk: this.tk,
|
|
382
|
+
center: this.center,
|
|
383
|
+
locate: this.locate,
|
|
384
|
+
zoom: this.zoom,
|
|
385
|
+
minZoom: this.minZoom,
|
|
386
|
+
maxZoom: this.maxZoom
|
|
387
|
+
});
|
|
388
|
+
this.session = session;
|
|
389
|
+
this.unbindEvents = bindEventNames(session.map, MAP_EVENT_NAMES, (name, event) => {
|
|
390
|
+
this.dispatchEvent(new CustomEvent(`tdt-${name}`, {
|
|
391
|
+
detail: event,
|
|
392
|
+
bubbles: true,
|
|
393
|
+
composed: true
|
|
394
|
+
}));
|
|
395
|
+
});
|
|
396
|
+
return session.map;
|
|
397
|
+
}
|
|
398
|
+
connectedCallback() {
|
|
399
|
+
super.connectedCallback();
|
|
400
|
+
this.style.display = "block";
|
|
401
|
+
this.style.isolation = "isolate";
|
|
402
|
+
if (this.tk) this.whenReady();
|
|
403
|
+
}
|
|
404
|
+
disconnectedCallback() {
|
|
405
|
+
super.disconnectedCallback();
|
|
406
|
+
this.unbindEvents?.();
|
|
407
|
+
this.unbindEvents = void 0;
|
|
408
|
+
this.session?.destroy();
|
|
409
|
+
this.session = void 0;
|
|
410
|
+
this.ready = void 0;
|
|
411
|
+
}
|
|
412
|
+
updated(changed) {
|
|
413
|
+
const session = this.session;
|
|
414
|
+
if (!session) return;
|
|
415
|
+
if (changed.has("center") && this.center) session.setCenter(this.center);
|
|
416
|
+
if (changed.has("zoom")) session.map.setZoom(this.zoom);
|
|
417
|
+
}
|
|
418
|
+
render() {
|
|
419
|
+
return html``;
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
//#endregion
|
|
423
|
+
//#region src/info-window.ts
|
|
424
|
+
/**
|
|
425
|
+
* 信息窗元素。内容为元素自身的子节点(light DOM),经 MutationObserver
|
|
426
|
+
* 克隆进窗体容器:SDK 在 open 时会搬移内容容器,克隆可保持元素内原始
|
|
427
|
+
* 子节点稳定,且避免 observer 被搬移触发误清窗口(vue 适配层同款方案)。
|
|
428
|
+
* 独立使用时经 lnglat 属性由地图打开;嵌套在覆盖物元素内时由宿主打开。
|
|
429
|
+
* attribute 随官方 InfoWindowOptions 字段(kebab-case)。
|
|
430
|
+
*/
|
|
431
|
+
/** "x,y" 属性 → T.Point */
|
|
432
|
+
function pointConverter(value) {
|
|
433
|
+
if (!value) return;
|
|
434
|
+
const [x, y] = value.split(",").map(Number);
|
|
435
|
+
return new T.Point(x, y);
|
|
436
|
+
}
|
|
437
|
+
var TdtInfoWindowElement = class extends LitElement {
|
|
438
|
+
constructor(..._args) {
|
|
439
|
+
super(..._args);
|
|
440
|
+
this.open = false;
|
|
441
|
+
}
|
|
442
|
+
static {
|
|
443
|
+
this.properties = {
|
|
444
|
+
open: {
|
|
445
|
+
type: Boolean,
|
|
446
|
+
reflect: true
|
|
447
|
+
},
|
|
448
|
+
lnglat: { converter: lnglatConverter },
|
|
449
|
+
minWidth: {
|
|
450
|
+
type: Number,
|
|
451
|
+
attribute: "min-width"
|
|
452
|
+
},
|
|
453
|
+
maxWidth: {
|
|
454
|
+
type: Number,
|
|
455
|
+
attribute: "max-width"
|
|
456
|
+
},
|
|
457
|
+
maxHeight: {
|
|
458
|
+
type: Number,
|
|
459
|
+
attribute: "max-height"
|
|
460
|
+
},
|
|
461
|
+
autoPan: {
|
|
462
|
+
type: Boolean,
|
|
463
|
+
attribute: "auto-pan"
|
|
464
|
+
},
|
|
465
|
+
closeButton: {
|
|
466
|
+
type: Boolean,
|
|
467
|
+
attribute: "close-button"
|
|
468
|
+
},
|
|
469
|
+
offset: { converter: pointConverter },
|
|
470
|
+
autoPanPadding: {
|
|
471
|
+
converter: pointConverter,
|
|
472
|
+
attribute: "auto-pan-padding"
|
|
473
|
+
},
|
|
474
|
+
closeOnClick: {
|
|
475
|
+
type: Boolean,
|
|
476
|
+
attribute: "close-on-click"
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
connectedCallback() {
|
|
481
|
+
super.connectedCallback();
|
|
482
|
+
this.style.display = "none";
|
|
483
|
+
const container = findMap(this);
|
|
484
|
+
if (!container) return;
|
|
485
|
+
const dispatch = dispatchTdtEvent(this);
|
|
486
|
+
Promise.all([container.whenReady(), resolveHostOverlay(this)]).then(([map, host]) => {
|
|
487
|
+
this.map = map;
|
|
488
|
+
this.host = host;
|
|
489
|
+
return createWhenReady(() => createInfoWindow(compact({
|
|
490
|
+
minWidth: this.minWidth,
|
|
491
|
+
maxWidth: this.maxWidth,
|
|
492
|
+
maxHeight: this.maxHeight,
|
|
493
|
+
autoPan: this.autoPan,
|
|
494
|
+
closeButton: this.closeButton,
|
|
495
|
+
offset: this.offset,
|
|
496
|
+
autoPanPadding: this.autoPanPadding,
|
|
497
|
+
closeOnClick: this.closeOnClick
|
|
498
|
+
}), (name) => {
|
|
499
|
+
dispatch(name, void 0);
|
|
500
|
+
if (name === "close") this.open = false;
|
|
501
|
+
}));
|
|
502
|
+
}).then((created) => {
|
|
503
|
+
if (this.handle || !this.isConnected) return;
|
|
504
|
+
this.handle = created;
|
|
505
|
+
this.observer = new MutationObserver(() => this.syncContent());
|
|
506
|
+
this.observer.observe(this, {
|
|
507
|
+
childList: true,
|
|
508
|
+
subtree: true,
|
|
509
|
+
characterData: true
|
|
510
|
+
});
|
|
511
|
+
this.syncContent();
|
|
512
|
+
this.syncOpen();
|
|
513
|
+
}).catch(() => {});
|
|
514
|
+
}
|
|
515
|
+
disconnectedCallback() {
|
|
516
|
+
super.disconnectedCallback();
|
|
517
|
+
this.observer?.disconnect();
|
|
518
|
+
this.observer = void 0;
|
|
519
|
+
this.handle?.destroy();
|
|
520
|
+
this.handle = void 0;
|
|
521
|
+
}
|
|
522
|
+
/** 把元素子节点克隆进窗体容器 */
|
|
523
|
+
syncContent() {
|
|
524
|
+
if (this.handle) this.handle.container.replaceChildren(...Array.from(this.childNodes, (node) => node.cloneNode(true)));
|
|
525
|
+
}
|
|
526
|
+
syncOpen() {
|
|
527
|
+
if (!this.handle || !this.map) return;
|
|
528
|
+
if (this.open) if (this.lnglat) this.handle.openOn(this.map, toLngLat(this.lnglat));
|
|
529
|
+
else if (this.host) this.handle.openOn(this.host);
|
|
530
|
+
else this.handle.openOn(this.map);
|
|
531
|
+
else if (this.handle.isOpen()) this.handle.close();
|
|
532
|
+
}
|
|
533
|
+
updated() {
|
|
534
|
+
this.syncOpen();
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
//#endregion
|
|
538
|
+
//#region src/layers.ts
|
|
539
|
+
/**
|
|
540
|
+
* 瓦片图层元素:定义(props/构造/sync/事件表)见 core defs,元素只承载
|
|
541
|
+
* attribute 声明与生命周期桥接。url 为必填 attribute;bounds 用
|
|
542
|
+
* "swLng,swLat;neLng,neLat" 形态;格网图层的样式对象用 JSON。
|
|
543
|
+
*/
|
|
544
|
+
const TdtTileLayerElement = makeLayerElement(tileLayerDef);
|
|
545
|
+
const TdtTileLayerWmsElement = makeLayerElement(tileLayerWmsDef);
|
|
546
|
+
const TdtTileLayerTdtElement = makeLayerElement(tileLayerTdtDef);
|
|
547
|
+
const TdtGridlineLayerElement = makeLayerElement(gridlineLayerDef);
|
|
548
|
+
//#endregion
|
|
549
|
+
//#region src/overlays.ts
|
|
550
|
+
/**
|
|
551
|
+
* 覆盖物元素:定义(props/构造/sync/事件表)见 core defs,元素只承载
|
|
552
|
+
* attribute 声明与生命周期桥接。attribute 命名随官方 Options 字段
|
|
553
|
+
* (kebab-case);坐标 "lng,lat"、集合 "lng,lat;…"、对象 JSON。
|
|
554
|
+
*/
|
|
555
|
+
const TdtMarkerElement = makeOverlayElement(markerDef);
|
|
556
|
+
const TdtPolylineElement = makeOverlayElement(polylineDef);
|
|
557
|
+
const TdtPolygonElement = makeOverlayElement(polygonDef);
|
|
558
|
+
const TdtRectangleElement = makeOverlayElement(rectangleDef);
|
|
559
|
+
const TdtLabelElement = makeOverlayElement(labelDef);
|
|
560
|
+
const TdtCircleElement = makeOverlayElement(circleDef);
|
|
561
|
+
const TdtCloudMarkerElement = makeOverlayElement(cloudMarkerDef);
|
|
562
|
+
/** 点聚合容器:子级 tdt-marker 经 DOM 就近收编加入聚合而非直接上屏 */
|
|
563
|
+
const TdtMarkerClustererElement = makeOverlayElement(markerClustererDef, { collector: (cluster) => ({
|
|
564
|
+
addMarker: (marker) => cluster.addMarker(marker),
|
|
565
|
+
removeMarker: (marker) => cluster.removeMarker(marker)
|
|
566
|
+
}) });
|
|
567
|
+
/** 图层组容器:子级覆盖物加入容器,容器卸载时随 clearLayers 清空 */
|
|
568
|
+
const TdtLayerGroupElement = makeOverlayElement(layerGroupDef, { collector: (group) => ({
|
|
569
|
+
addMarker: (marker) => group.addLayer(marker),
|
|
570
|
+
removeMarker: (marker) => group.removeLayer(marker)
|
|
571
|
+
}) });
|
|
572
|
+
//#endregion
|
|
573
|
+
//#region src/plot-entities.ts
|
|
574
|
+
/**
|
|
575
|
+
* 标绘覆盖物元素:定义(props/构造/sync)见 core defs,vue/wc 共享。
|
|
576
|
+
* attribute path 形如 "lng,lat;lng,lat";样式 props 仅构造时生效。
|
|
577
|
+
*/
|
|
578
|
+
const TdtArcElement = makeOverlayElement(arcDef);
|
|
579
|
+
const TdtBezierCurve2Element = makeOverlayElement(bezierCurve2Def);
|
|
580
|
+
const TdtBezierCurve3Element = makeOverlayElement(bezierCurve3Def);
|
|
581
|
+
const TdtBezierCurveArrowElement = makeOverlayElement(bezierCurveArrowDef);
|
|
582
|
+
const TdtBezierCurveNElement = makeOverlayElement(bezierCurveNDef);
|
|
583
|
+
const TdtCardinalCurveElement = makeOverlayElement(cardinalCurveDef);
|
|
584
|
+
const TdtCardinalCurveArrowElement = makeOverlayElement(cardinalCurveArrowDef);
|
|
585
|
+
const TdtParallelSearchElement = makeOverlayElement(parallelSearchDef);
|
|
586
|
+
const TdtPolylineArrowElement = makeOverlayElement(polylineArrowDef);
|
|
587
|
+
const TdtSectorSearchElement = makeOverlayElement(sectorSearchDef);
|
|
588
|
+
const TdtCloseCurveElement = makeOverlayElement(closeCurveDef);
|
|
589
|
+
const TdtCurveFlagElement = makeOverlayElement(curveFlagDef);
|
|
590
|
+
const TdtDiagonalArrowElement = makeOverlayElement(diagonalArrowDef);
|
|
591
|
+
const TdtDoubleArrowElement = makeOverlayElement(doubleArrowDef);
|
|
592
|
+
const TdtDoveTailDiagonalArrowElement = makeOverlayElement(doveTailDiagonalArrowDef);
|
|
593
|
+
const TdtDoveTailStraightArrowElement = makeOverlayElement(doveTailStraightArrowDef);
|
|
594
|
+
const TdtGatheringPlaceElement = makeOverlayElement(gatheringPlaceDef);
|
|
595
|
+
const TdtRectFlagElement = makeOverlayElement(rectFlagDef);
|
|
596
|
+
const TdtRoundRectElement = makeOverlayElement(roundRectDef);
|
|
597
|
+
const TdtSectorElement = makeOverlayElement(sectorDef);
|
|
598
|
+
const TdtStraightArrowElement = makeOverlayElement(straightArrowDef);
|
|
599
|
+
const TdtTriangleFlagElement = makeOverlayElement(triangleFlagDef);
|
|
600
|
+
//#endregion
|
|
601
|
+
//#region src/plot-tools.ts
|
|
602
|
+
/**
|
|
603
|
+
* 标绘工具元素族:定义见 core defs,vue/wc 共享。active attribute
|
|
604
|
+
* (presence 语义)受控开关,事件以 `tdt-<官方事件名>` 转发(如 tdt-dbclick)。
|
|
605
|
+
*/
|
|
606
|
+
const TdtArcToolElement = makeToolElement(arcToolDef);
|
|
607
|
+
const TdtBezierCurve2ToolElement = makeToolElement(bezierCurve2ToolDef);
|
|
608
|
+
const TdtBezierCurve3ToolElement = makeToolElement(bezierCurve3ToolDef);
|
|
609
|
+
const TdtBezierCurveArrowToolElement = makeToolElement(bezierCurveArrowToolDef);
|
|
610
|
+
const TdtBezierCurveNToolElement = makeToolElement(bezierCurveNToolDef);
|
|
611
|
+
const TdtCardinalCurveArrowToolElement = makeToolElement(cardinalCurveArrowToolDef);
|
|
612
|
+
const TdtCardinalCurveToolElement = makeToolElement(cardinalCurveToolDef);
|
|
613
|
+
const TdtCloseCurveToolElement = makeToolElement(closeCurveToolDef);
|
|
614
|
+
const TdtCurveFlagToolElement = makeToolElement(curveFlagToolDef);
|
|
615
|
+
const TdtDiagonalArrowToolElement = makeToolElement(diagonalArrowToolDef);
|
|
616
|
+
const TdtDoubleArrowToolElement = makeToolElement(doubleArrowToolDef);
|
|
617
|
+
const TdtDoveTailDiagonalArrowToolElement = makeToolElement(doveTailDiagonalArrowToolDef);
|
|
618
|
+
const TdtDoveTailStraightArrowToolElement = makeToolElement(doveTailStraightArrowToolDef);
|
|
619
|
+
const TdtGatheringPlaceToolElement = makeToolElement(gatheringPlaceToolDef);
|
|
620
|
+
const TdtHandDrawingToolElement = makeToolElement(handDrawingToolDef);
|
|
621
|
+
const TdtParallelSearchToolElement = makeToolElement(parallelSearchToolDef);
|
|
622
|
+
const TdtPolylineArrowToolElement = makeToolElement(polylineArrowToolDef);
|
|
623
|
+
const TdtRectFlagToolElement = makeToolElement(rectFlagToolDef);
|
|
624
|
+
const TdtRoundRectToolElement = makeToolElement(roundRectToolDef);
|
|
625
|
+
const TdtSectorSearchToolElement = makeToolElement(sectorSearchToolDef);
|
|
626
|
+
const TdtSectorToolElement = makeToolElement(sectorToolDef);
|
|
627
|
+
const TdtStraightArrowToolElement = makeToolElement(straightArrowToolDef);
|
|
628
|
+
const TdtTriangleFlagToolElement = makeToolElement(triangleFlagToolDef);
|
|
629
|
+
//#endregion
|
|
630
|
+
//#region src/tools.ts
|
|
631
|
+
/**
|
|
632
|
+
* 鼠标工具元素:定义见 core defs;active attribute(presence 语义)受控
|
|
633
|
+
* 开关。事件以 `tdt-<官方事件名>` 转发(如 tdt-draw)。
|
|
634
|
+
*/
|
|
635
|
+
const TdtPolylineToolElement = makeToolElement(polylineToolDef);
|
|
636
|
+
const TdtPolygonToolElement = makeToolElement(polygonToolDef);
|
|
637
|
+
const TdtCircleToolElement = makeToolElement(circleToolDef);
|
|
638
|
+
const TdtRectangleToolElement = makeToolElement(rectangleToolDef);
|
|
639
|
+
const TdtMarkToolElement = makeToolElement(markToolDef);
|
|
640
|
+
const TdtPaintBrushToolElement = makeToolElement(paintBrushToolDef);
|
|
641
|
+
/**
|
|
642
|
+
* 坐标拾取元素(官方 CoordinatePickup):非 Mousetool 体系,以
|
|
643
|
+
* addEvent/removeEvent 开关;官方 Options.callback 转写为 tdt-pick 事件
|
|
644
|
+
* (SDK 点击地图即调用 callback,未设置时点击会抛错,故构造必传)。
|
|
645
|
+
*/
|
|
646
|
+
var TdtCoordinatePickupElement = class extends LitElement {
|
|
647
|
+
constructor(..._args) {
|
|
648
|
+
super(..._args);
|
|
649
|
+
this.active = false;
|
|
650
|
+
this.callback = (lnglat) => {
|
|
651
|
+
dispatchTdtEvent(this)("pick", lnglat);
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
static {
|
|
655
|
+
this.properties = { active: {
|
|
656
|
+
type: Boolean,
|
|
657
|
+
reflect: true
|
|
658
|
+
} };
|
|
659
|
+
}
|
|
660
|
+
connectedCallback() {
|
|
661
|
+
super.connectedCallback();
|
|
662
|
+
const container = findMap(this);
|
|
663
|
+
if (!container) return;
|
|
664
|
+
container.whenReady().then((map) => createWhenReady(() => new T.CoordinatePickup(map, { callback: this.callback }))).then((created) => {
|
|
665
|
+
if (this.pickup || !this.isConnected) return;
|
|
666
|
+
this.pickup = created;
|
|
667
|
+
if (this.active) created.addEvent();
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
updated(changed) {
|
|
671
|
+
if (!changed.has("active") || !this.pickup) return;
|
|
672
|
+
if (this.active) this.pickup.addEvent();
|
|
673
|
+
else this.pickup.removeEvent();
|
|
674
|
+
}
|
|
675
|
+
disconnectedCallback() {
|
|
676
|
+
super.disconnectedCallback();
|
|
677
|
+
this.pickup?.removeEvent();
|
|
678
|
+
this.pickup = void 0;
|
|
679
|
+
}
|
|
680
|
+
render() {
|
|
681
|
+
return html``;
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
//#endregion
|
|
685
|
+
//#region src/index.ts
|
|
686
|
+
/** tag → 元素类注册表(registerComponents 与副作用注册共用) */
|
|
687
|
+
const ELEMENTS = [
|
|
688
|
+
["tdt-map", TdtMapElement],
|
|
689
|
+
["tdt-marker", TdtMarkerElement],
|
|
690
|
+
["tdt-polyline", TdtPolylineElement],
|
|
691
|
+
["tdt-polygon", TdtPolygonElement],
|
|
692
|
+
["tdt-rectangle", TdtRectangleElement],
|
|
693
|
+
["tdt-label", TdtLabelElement],
|
|
694
|
+
["tdt-circle", TdtCircleElement],
|
|
695
|
+
["tdt-cloud-marker", TdtCloudMarkerElement],
|
|
696
|
+
["tdt-marker-clusterer", TdtMarkerClustererElement],
|
|
697
|
+
["tdt-layer-group", TdtLayerGroupElement],
|
|
698
|
+
["tdt-control-zoom", TdtControlZoomElement],
|
|
699
|
+
["tdt-control-scale", TdtControlScaleElement],
|
|
700
|
+
["tdt-control-copyright", TdtControlCopyrightElement],
|
|
701
|
+
["tdt-control-overview-map", TdtControlOverviewMapElement],
|
|
702
|
+
["tdt-control-map-type", TdtControlMapTypeElement],
|
|
703
|
+
["tdt-info-window", TdtInfoWindowElement],
|
|
704
|
+
["tdt-tile-layer", TdtTileLayerElement],
|
|
705
|
+
["tdt-tile-layer-wms", TdtTileLayerWmsElement],
|
|
706
|
+
["tdt-tile-layer-tdt", TdtTileLayerTdtElement],
|
|
707
|
+
["tdt-gridline-layer", TdtGridlineLayerElement],
|
|
708
|
+
["tdt-arc", TdtArcElement],
|
|
709
|
+
["tdt-bezier-curve2", TdtBezierCurve2Element],
|
|
710
|
+
["tdt-bezier-curve3", TdtBezierCurve3Element],
|
|
711
|
+
["tdt-bezier-curve-arrow", TdtBezierCurveArrowElement],
|
|
712
|
+
["tdt-bezier-curve-n", TdtBezierCurveNElement],
|
|
713
|
+
["tdt-cardinal-curve", TdtCardinalCurveElement],
|
|
714
|
+
["tdt-cardinal-curve-arrow", TdtCardinalCurveArrowElement],
|
|
715
|
+
["tdt-parallel-search", TdtParallelSearchElement],
|
|
716
|
+
["tdt-polyline-arrow", TdtPolylineArrowElement],
|
|
717
|
+
["tdt-sector-search", TdtSectorSearchElement],
|
|
718
|
+
["tdt-close-curve", TdtCloseCurveElement],
|
|
719
|
+
["tdt-curve-flag", TdtCurveFlagElement],
|
|
720
|
+
["tdt-diagonal-arrow", TdtDiagonalArrowElement],
|
|
721
|
+
["tdt-double-arrow", TdtDoubleArrowElement],
|
|
722
|
+
["tdt-dove-tail-diagonal-arrow", TdtDoveTailDiagonalArrowElement],
|
|
723
|
+
["tdt-dove-tail-straight-arrow", TdtDoveTailStraightArrowElement],
|
|
724
|
+
["tdt-gathering-place", TdtGatheringPlaceElement],
|
|
725
|
+
["tdt-rect-flag", TdtRectFlagElement],
|
|
726
|
+
["tdt-round-rect", TdtRoundRectElement],
|
|
727
|
+
["tdt-sector", TdtSectorElement],
|
|
728
|
+
["tdt-straight-arrow", TdtStraightArrowElement],
|
|
729
|
+
["tdt-triangle-flag", TdtTriangleFlagElement],
|
|
730
|
+
["tdt-polyline-tool", TdtPolylineToolElement],
|
|
731
|
+
["tdt-polygon-tool", TdtPolygonToolElement],
|
|
732
|
+
["tdt-circle-tool", TdtCircleToolElement],
|
|
733
|
+
["tdt-rectangle-tool", TdtRectangleToolElement],
|
|
734
|
+
["tdt-mark-tool", TdtMarkToolElement],
|
|
735
|
+
["tdt-paint-brush-tool", TdtPaintBrushToolElement],
|
|
736
|
+
["tdt-coordinate-pickup", TdtCoordinatePickupElement],
|
|
737
|
+
["tdt-arc-tool", TdtArcToolElement],
|
|
738
|
+
["tdt-bezier-curve2-tool", TdtBezierCurve2ToolElement],
|
|
739
|
+
["tdt-bezier-curve3-tool", TdtBezierCurve3ToolElement],
|
|
740
|
+
["tdt-bezier-curve-arrow-tool", TdtBezierCurveArrowToolElement],
|
|
741
|
+
["tdt-bezier-curve-n-tool", TdtBezierCurveNToolElement],
|
|
742
|
+
["tdt-cardinal-curve-tool", TdtCardinalCurveToolElement],
|
|
743
|
+
["tdt-cardinal-curve-arrow-tool", TdtCardinalCurveArrowToolElement],
|
|
744
|
+
["tdt-close-curve-tool", TdtCloseCurveToolElement],
|
|
745
|
+
["tdt-curve-flag-tool", TdtCurveFlagToolElement],
|
|
746
|
+
["tdt-diagonal-arrow-tool", TdtDiagonalArrowToolElement],
|
|
747
|
+
["tdt-double-arrow-tool", TdtDoubleArrowToolElement],
|
|
748
|
+
["tdt-dove-tail-diagonal-arrow-tool", TdtDoveTailDiagonalArrowToolElement],
|
|
749
|
+
["tdt-dove-tail-straight-arrow-tool", TdtDoveTailStraightArrowToolElement],
|
|
750
|
+
["tdt-gathering-place-tool", TdtGatheringPlaceToolElement],
|
|
751
|
+
["tdt-hand-drawing-tool", TdtHandDrawingToolElement],
|
|
752
|
+
["tdt-parallel-search-tool", TdtParallelSearchToolElement],
|
|
753
|
+
["tdt-polyline-arrow-tool", TdtPolylineArrowToolElement],
|
|
754
|
+
["tdt-rect-flag-tool", TdtRectFlagToolElement],
|
|
755
|
+
["tdt-round-rect-tool", TdtRoundRectToolElement],
|
|
756
|
+
["tdt-sector-search-tool", TdtSectorSearchToolElement],
|
|
757
|
+
["tdt-sector-tool", TdtSectorToolElement],
|
|
758
|
+
["tdt-straight-arrow-tool", TdtStraightArrowToolElement],
|
|
759
|
+
["tdt-triangle-flag-tool", TdtTriangleFlagToolElement]
|
|
760
|
+
];
|
|
761
|
+
/**
|
|
762
|
+
* 注册全部自定义元素;已注册的 tag 自动跳过(重复 import 安全)。
|
|
763
|
+
* SSR/Node 环境无 customElements,静默跳过(客户端水合后再调用)。
|
|
764
|
+
*/
|
|
765
|
+
function registerComponents() {
|
|
766
|
+
if (typeof customElements === "undefined") return;
|
|
767
|
+
for (const [tag, ctor] of ELEMENTS) if (!customElements.get(tag)) customElements.define(tag, ctor);
|
|
768
|
+
}
|
|
769
|
+
registerComponents();
|
|
770
|
+
//#endregion
|
|
771
|
+
export { ELEMENTS, TdtArcElement, TdtArcToolElement, TdtBezierCurve2Element, TdtBezierCurve2ToolElement, TdtBezierCurve3Element, TdtBezierCurve3ToolElement, TdtBezierCurveArrowElement, TdtBezierCurveArrowToolElement, TdtBezierCurveNElement, TdtBezierCurveNToolElement, TdtCardinalCurveArrowElement, TdtCardinalCurveArrowToolElement, TdtCardinalCurveElement, TdtCardinalCurveToolElement, TdtCircleElement, TdtCircleToolElement, TdtCloseCurveElement, TdtCloseCurveToolElement, TdtCloudMarkerElement, TdtControlCopyrightElement, TdtControlMapTypeElement, TdtControlOverviewMapElement, TdtControlScaleElement, TdtControlZoomElement, TdtCoordinatePickupElement, TdtCurveFlagElement, TdtCurveFlagToolElement, TdtDiagonalArrowElement, TdtDiagonalArrowToolElement, TdtDoubleArrowElement, TdtDoubleArrowToolElement, TdtDoveTailDiagonalArrowElement, TdtDoveTailDiagonalArrowToolElement, TdtDoveTailStraightArrowElement, TdtDoveTailStraightArrowToolElement, TdtGatheringPlaceElement, TdtGatheringPlaceToolElement, TdtGridlineLayerElement, TdtHandDrawingToolElement, TdtInfoWindowElement, TdtLabelElement, TdtLayerGroupElement, TdtMapElement, TdtMarkToolElement, TdtMarkerClustererElement, TdtMarkerElement, TdtPaintBrushToolElement, TdtParallelSearchElement, TdtParallelSearchToolElement, TdtPolygonElement, TdtPolygonToolElement, TdtPolylineArrowElement, TdtPolylineArrowToolElement, TdtPolylineElement, TdtPolylineToolElement, TdtRectFlagElement, TdtRectFlagToolElement, TdtRectangleElement, TdtRectangleToolElement, TdtRoundRectElement, TdtRoundRectToolElement, TdtSectorElement, TdtSectorSearchElement, TdtSectorSearchToolElement, TdtSectorToolElement, TdtStraightArrowElement, TdtStraightArrowToolElement, TdtTileLayerElement, TdtTileLayerTdtElement, TdtTileLayerWmsElement, TdtTriangleFlagElement, TdtTriangleFlagToolElement, lnglatConverter, registerComponents };
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tianditu/web-components",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Web Components for the tianditu map — Lit-based custom elements for any framework or plain HTML, sharing one core definition with the Vue adapter",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"control",
|
|
7
|
+
"custom-elements",
|
|
8
|
+
"gis",
|
|
9
|
+
"infowindow",
|
|
10
|
+
"lbs",
|
|
11
|
+
"lit",
|
|
12
|
+
"map",
|
|
13
|
+
"marker",
|
|
14
|
+
"overlay",
|
|
15
|
+
"plot",
|
|
16
|
+
"polygon",
|
|
17
|
+
"polyline",
|
|
18
|
+
"tianditu",
|
|
19
|
+
"tile-layer",
|
|
20
|
+
"typescript",
|
|
21
|
+
"web-components"
|
|
22
|
+
],
|
|
23
|
+
"homepage": "https://github.com/DemoMacro/tianditu#readme",
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/DemoMacro/tianditu/issues"
|
|
26
|
+
},
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"author": {
|
|
29
|
+
"name": "Demo Macro",
|
|
30
|
+
"email": "abc@imst.xyz",
|
|
31
|
+
"url": "https://www.demomacro.com/"
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/DemoMacro/tianditu.git"
|
|
36
|
+
},
|
|
37
|
+
"files": [
|
|
38
|
+
"dist"
|
|
39
|
+
],
|
|
40
|
+
"main": "dist/index.mjs",
|
|
41
|
+
"types": "dist/index.d.mts",
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"lit": "3.1.0",
|
|
44
|
+
"@tianditu/core": "0.1.0"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "vp pack",
|
|
48
|
+
"demo": "vp dev"
|
|
49
|
+
}
|
|
50
|
+
}
|