my-openlayer 2.4.7 → 2.4.9

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +208 -101
  2. package/MyOl.js +1 -1
  3. package/README.md +156 -156
  4. package/core/Point.js +21 -3
  5. package/docs/.vitepress/cache/deps/@theme_index.js +275 -0
  6. package/docs/.vitepress/cache/deps/@theme_index.js.map +7 -0
  7. package/docs/.vitepress/cache/deps/_metadata.json +40 -0
  8. package/docs/.vitepress/cache/deps/chunk-LW4I4DCF.js +12542 -0
  9. package/docs/.vitepress/cache/deps/chunk-LW4I4DCF.js.map +7 -0
  10. package/docs/.vitepress/cache/deps/chunk-Z5QSWKN2.js +9719 -0
  11. package/docs/.vitepress/cache/deps/chunk-Z5QSWKN2.js.map +7 -0
  12. package/docs/.vitepress/cache/deps/package.json +3 -0
  13. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +4505 -0
  14. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +7 -0
  15. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +583 -0
  16. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +7 -0
  17. package/docs/.vitepress/cache/deps/vue.js +343 -0
  18. package/docs/.vitepress/cache/deps/vue.js.map +7 -0
  19. package/docs/.vitepress/config.mts +57 -0
  20. package/docs/ConfigManager.md +71 -40
  21. package/docs/ErrorHandler.md +106 -45
  22. package/docs/EventManager.md +142 -52
  23. package/docs/Line.md +187 -52
  24. package/docs/MapBaseLayers.md +198 -48
  25. package/docs/MapTools.md +172 -48
  26. package/docs/MeasureHandler.md +87 -47
  27. package/docs/MyOl.md +247 -62
  28. package/docs/Point.md +165 -58
  29. package/docs/Polygon.md +241 -65
  30. package/docs/RiverLayerManager.md +187 -59
  31. package/docs/SelectHandler.md +147 -126
  32. package/docs/ValidationUtils.md +83 -38
  33. package/docs/VueTemplatePoint.md +214 -85
  34. package/docs/index.md +78 -0
  35. package/package.json +7 -4
  36. package/types.d.ts +2 -0
  37. package/AI_CONTEXT.md +0 -147
@@ -1,85 +1,214 @@
1
- # VueTemplatePoint Vue 组件点位类
2
-
3
- `VueTemplatePoint` 允许将 Vue 组件直接渲染为地图上的点位覆盖物(Overlay),支持 Vue 2 和 Vue 3
4
-
5
- ## 方法
6
-
7
- - **addVueTemplatePoint(pointDataList: any[], template: any, options?)**: 添加 Vue 组件点位。
8
- - `pointDataList`: 点位数据列表。
9
- - `template`: Vue 组件对象。
10
- - `options`:
11
- - `positioning`: 覆盖物定位点(如 `'center-center'`)。
12
- - `stopEvent`: 是否阻止事件冒泡。
13
-
14
- ### 返回值
15
-
16
- 该方法返回一个控制对象,包含以下方法:
17
-
18
- - **setVisible(visible: boolean)**: 设置所有点位的可见性。
19
- - **setOneVisibleByProp(propName: string, propValue: any, visible: boolean)**: 根据属性值控制特定点位的可见性。
20
- - **remove()**: 移除所有点位并销毁组件实例。
21
- - **getPoints()**: 获取底层点位实例列表。
22
-
23
- ## 使用示例
24
-
25
- ### Vue 3 示例
26
-
27
- ```typescript
28
- import { MyOl } from 'my-openlayer';
29
- import MyPopup from './MyPopup.vue'; // 你的 Vue 组件
30
-
31
- const pointData = [
32
- { lgtd: 120.1, lttd: 30.2, title: '位置1', status: 'normal' },
33
- { lgtd: 120.2, lttd: 30.3, title: '位置2', status: 'warning' }
34
- ];
35
-
36
- // 添加组件点位
37
- const vuePoints = map.getPoint().addVueTemplatePoint(
38
- pointData,
39
- MyPopup,
40
- {
41
- positioning: 'bottom-center',
42
- stopEvent: true // 允许点击组件交互
43
- }
44
- );
45
-
46
- // 控制显示隐藏
47
- vuePoints.setVisible(false);
48
-
49
- // 根据属性控制
50
- vuePoints.setOneVisibleByProp('status', 'warning', true);
51
-
52
- // 移除
53
- // vuePoints.remove();
54
- ```
55
-
56
- ### Vue 组件编写规范 (MyPopup.vue)
57
-
58
- 组件会接收 `pointData` 作为 props。
59
-
60
- ```vue
61
- <template>
62
- <div class="popup">
63
- <h3>{{ pointData.title }}</h3>
64
- <p>状态: {{ pointData.status }}</p>
65
- </div>
66
- </template>
67
-
68
- <script setup>
69
- defineProps({
70
- pointData: {
71
- type: Object,
72
- required: true
73
- }
74
- });
75
- </script>
76
-
77
- <style scoped>
78
- .popup {
79
- background: white;
80
- padding: 10px;
81
- border-radius: 4px;
82
- box-shadow: 0 2px 10px rgba(0,0,0,0.2);
83
- }
84
- </style>
85
- ```
1
+ # VueTemplatePoint Vue 组件点位类
2
+
3
+ `VueTemplatePoint` 允许将 Vue 组件直接渲染为地图上的点位覆盖物(Overlay),支持 Vue 2 和 Vue 3。它通过创建 Overlay 并将 Vue 组件挂载到 Overlay 的 DOM 元素中来实现。
4
+
5
+ ## 构造函数
6
+
7
+ ```typescript
8
+ constructor(map: Map)
9
+ ```
10
+
11
+ - **参数**:
12
+ - `map` (Map): OpenLayers 地图实例。
13
+
14
+ ## 接口定义
15
+
16
+ ### VueTemplatePointOptions
17
+
18
+ 配置 Vue 模版点位的选项接口。
19
+
20
+ | 属性 | 类型 | 必填 | 默认值 | 描述 |
21
+ | :--- | :--- | :--- | :--- | :--- |
22
+ | Template | `any` | 是 | - | Vue 组件模版对象。 |
23
+ | lgtd | `number` | 是 | - | 经度。 |
24
+ | lttd | `number` | 是 | - | 纬度。 |
25
+ | props | `Record<string, any>` | 否 | - | 传递给组件的 props。 |
26
+ | positioning | `string` | 否 | `'center-center'` | 覆盖物相对于位置的锚点。可选值见 OpenLayers Overlay positioning。 |
27
+ | stopEvent | `boolean` | 否 | `false` | 是否阻止地图事件冒泡。 |
28
+ | zIndex | `number` | 否 | - | DOM 元素的 z-index。 |
29
+ | className | `string` | | - | DOM 元素的 CSS 类名。 |
30
+ | visible | `boolean` | 否 | `true` | 初始可见性。 |
31
+
32
+ ## 方法
33
+
34
+ ### addVueTemplatePoint
35
+
36
+ 添加一组 Vue 组件点位。
37
+
38
+ ```typescript
39
+ addVueTemplatePoint(
40
+ pointDataList: any[],
41
+ template: any,
42
+ options?: {
43
+ positioning?: string,
44
+ stopEvent?: boolean
45
+ }
46
+ ): VueTemplatePointController
47
+ ```
48
+
49
+ - **参数**:
50
+ - `pointDataList` (any[]): 点位数据列表。列表中的每个对象都必须包含 `lgtd` (经度) 和 `lttd` (纬度) 属性。
51
+ - `template` (any): Vue 组件对象。
52
+ - `options` (Object): 可选配置。
53
+ - `positioning`: 覆盖物定位点(如 `'center-center'`, `'bottom-center'` 等)。
54
+ - `stopEvent`: 是否阻止事件冒泡(默认 `false`)。
55
+
56
+ - **返回值**:
57
+ 返回一个控制对象 `VueTemplatePointController`,用于批量管理这组点位。
58
+
59
+ ### VueTemplatePointController 接口
60
+
61
+ `addVueTemplatePoint` 返回的对象包含以下方法:
62
+
63
+ | 方法 | 描述 |
64
+ | :--- | :--- |
65
+ | `setVisible(visible: boolean): void` | 设置该组所有点位的可见性。 |
66
+ | `setOneVisibleByProp(propName: string, propValue: any, visible: boolean): void` | 根据点位数据中的属性值控制特定点位的可见性。 |
67
+ | `remove(): void` | 移除该组所有点位并销毁组件实例。 |
68
+ | `getPoints(): VueTemplatePointInstance[]` | 获取该组创建的所有底层点位实例列表。 |
69
+
70
+ ### getPointById
71
+
72
+ 根据 ID 获取单个点位实例。
73
+
74
+ ```typescript
75
+ getPointById(id: string): VueTemplatePointInstance | undefined
76
+ ```
77
+
78
+ ### getAllPoints
79
+
80
+ 获取所有管理的点位实例。
81
+
82
+ ```typescript
83
+ getAllPoints(): VueTemplatePointInstance[]
84
+ ```
85
+
86
+ ### removeAllPoints
87
+
88
+ 移除并销毁所有点位。
89
+
90
+ ```typescript
91
+ removeAllPoints(): void
92
+ ```
93
+
94
+ ### getPointCount
95
+
96
+ 获取当前管理的点位数量。
97
+
98
+ ```typescript
99
+ getPointCount(): number
100
+ ```
101
+
102
+ ## VueTemplatePointInstance 实例方法
103
+
104
+ 单个点位实例 (`VueTemplatePointInstance`) 提供的操作方法:
105
+
106
+ | 方法 | 描述 |
107
+ | :--- | :--- |
108
+ | `setVisible(visible: boolean): void` | 设置当前点位可见性。 |
109
+ | `isVisible(): boolean` | 获取当前可见性状态。 |
110
+ | `updatePosition(lgtd: number, lttd: number): void` | 更新点位经纬度位置。 |
111
+ | `getPosition(): number[]` | 获取当前位置 `[lgtd, lttd]`。 |
112
+ | `updateProps(newProps: Record<string, any>): void` | 更新传递给组件的 props。 |
113
+ | `setStyle(styles: Partial<CSSStyleDeclaration>): void` | 设置 DOM 元素的 CSS 样式。 |
114
+ | `addClass(className: string): void` | 添加 CSS 类名。 |
115
+ | `removeClass(className: string): void` | 移除 CSS 类名。 |
116
+ | `remove(): void` | 移除并销毁当前点位。 |
117
+ | `getId(): string` | 获取点位唯一 ID。 |
118
+ | `getDomElement(): HTMLElement` | 获取点位对应的 DOM 元素。 |
119
+
120
+ ## 使用示例
121
+
122
+ ### Vue 3 示例
123
+
124
+ ```typescript
125
+ import { MyOl } from 'my-openlayer';
126
+ import MyPopup from './MyPopup.vue'; // 你的 Vue 组件
127
+
128
+ const map = new MyOl('map-container');
129
+ const vuePointManager = map.getPoint();
130
+
131
+ const pointData = [
132
+ { lgtd: 120.1, lttd: 30.2, title: '位置1', status: 'normal' },
133
+ { lgtd: 120.2, lttd: 30.3, title: '位置2', status: 'warning' }
134
+ ];
135
+
136
+ // 1. 添加组件点位
137
+ const pointsController = vuePointManager.addVueTemplatePoint(
138
+ pointData,
139
+ MyPopup,
140
+ {
141
+ positioning: 'bottom-center',
142
+ stopEvent: true // 允许点击组件交互,阻止地图点击事件
143
+ }
144
+ );
145
+
146
+ // 2. 批量控制显示隐藏
147
+ pointsController.setVisible(false);
148
+
149
+ // 3. 根据属性控制特定点位
150
+ pointsController.setOneVisibleByProp('status', 'warning', true);
151
+
152
+ // 4. 获取单个实例进行精细控制
153
+ const instances = pointsController.getPoints();
154
+ if (instances.length > 0) {
155
+ const firstPoint = instances[0];
156
+
157
+ // 更新位置
158
+ firstPoint.updatePosition(120.15, 30.25);
159
+
160
+ // 更新 Props
161
+ firstPoint.updateProps({
162
+ pointData: { ...pointData[0], title: '更新后的标题' }
163
+ });
164
+
165
+ // 添加样式类
166
+ firstPoint.addClass('highlight-point');
167
+ }
168
+
169
+ // 5. 移除这组点位
170
+ // pointsController.remove();
171
+ ```
172
+
173
+ ### Vue 组件编写规范 (MyPopup.vue)
174
+
175
+ 组件会接收 `pointData` 作为 props,内容为传入 `pointDataList` 中的对应数据项。
176
+
177
+ ```vue
178
+ <template>
179
+ <div class="popup" :class="pointData.status">
180
+ <h3>{{ pointData.title }}</h3>
181
+ <p>状态: {{ pointData.status }}</p>
182
+ <button @click="handleClick">详情</button>
183
+ </div>
184
+ </template>
185
+
186
+ <script setup>
187
+ import { defineProps } from 'vue';
188
+
189
+ const props = defineProps({
190
+ pointData: {
191
+ type: Object,
192
+ required: true
193
+ }
194
+ });
195
+
196
+ const handleClick = () => {
197
+ console.log('Clicked point:', props.pointData.title);
198
+ };
199
+ </script>
200
+
201
+ <style scoped>
202
+ .popup {
203
+ background: white;
204
+ padding: 10px;
205
+ border-radius: 4px;
206
+ box-shadow: 0 2px 10px rgba(0,0,0,0.2);
207
+ min-width: 150px;
208
+ transform: translate(-50%, -100%); /* 配合 bottom-center 定位 */
209
+ }
210
+ .popup.warning {
211
+ border: 2px solid orange;
212
+ }
213
+ </style>
214
+ ```
package/docs/index.md ADDED
@@ -0,0 +1,78 @@
1
+ # My OpenLayers
2
+
3
+ My OpenLayers 是一个基于 OpenLayers 的轻量级地图封装库,旨在简化地图开发流程,提供开箱即用的常用功能。它集成了点、线、面绘制,测量工具,选择交互,Vue 组件覆盖物等功能,特别优化了 Vue 项目的集成体验。
4
+
5
+ ## 特性
6
+
7
+ - **开箱即用**: 封装了常用的地图功能,减少样板代码。
8
+ - **Vue 集成**: 支持使用 Vue 组件作为地图覆盖物,轻松创建复杂的交互式标记。
9
+ - **TypeScript**: 完全使用 TypeScript 编写,提供完整的类型定义。
10
+ - **工具丰富**: 内置测量、选择、裁剪、遮罩等实用工具。
11
+ - **扩展性强**: 提供基础类和接口,方便二次封装和扩展。
12
+
13
+ ## 安装
14
+
15
+ ```bash
16
+ npm install my-openlayer
17
+ # 或者
18
+ yarn add my-openlayer
19
+ # 或者
20
+ pnpm add my-openlayer
21
+ ```
22
+
23
+ ## 快速开始
24
+
25
+ ```typescript
26
+ import { MyOl } from 'my-openlayer';
27
+ import 'ol/ol.css'; // 引入 OpenLayers 样式
28
+
29
+ // 初始化地图
30
+ const map = new MyOl('map-container', {
31
+ center: [120.2, 30.3],
32
+ zoom: 12,
33
+ projection: 'EPSG:4326'
34
+ });
35
+
36
+ // 获取原生 Map 实例
37
+ const olMap = map.map;
38
+
39
+ // 添加一个点
40
+ const point = map.getPoint();
41
+ point.addPoint([{
42
+ lgtd: 120.2,
43
+ lttd: 30.3,
44
+ style: {
45
+ icon: 'path/to/icon.png'
46
+ }
47
+ }]);
48
+ ```
49
+
50
+ ## 核心模块
51
+
52
+ - **[MyOl](./MyOl.md)**: 核心入口类,负责地图初始化和模块管理。
53
+ - **[Point](./Point.md)**: 点位管理,支持图标、文本、聚合等。
54
+ - **[Line](./Line.md)**: 线条绘制,支持不同样式和动画。
55
+ - **[Polygon](./Polygon.md)**: 多边形绘制,支持遮罩、热力图等。
56
+ - **[VueTemplatePoint](./VueTemplatePoint.md)**: 使用 Vue 组件作为地图点位覆盖物。
57
+
58
+ ## 工具模块
59
+
60
+ - **[MapTools](./MapTools.md)**: 通用地图工具,如裁剪、定位、导出图片等。
61
+ - **[MeasureHandler](./MeasureHandler.md)**: 距离和面积测量工具。
62
+ - **[SelectHandler](./SelectHandler.md)**: 要素选择交互工具。
63
+ - **[MapBaseLayers](./MapBaseLayers.md)**: 底图切换和管理。
64
+
65
+ ## 基础设施
66
+
67
+ - **[ConfigManager](./ConfigManager.md)**: 全局配置管理。
68
+ - **[EventManager](./EventManager.md)**: 统一事件管理系统。
69
+ - **[ErrorHandler](./ErrorHandler.md)**: 错误处理和日志系统。
70
+ - **[ValidationUtils](./ValidationUtils.md)**: 参数验证工具。
71
+
72
+ ## 贡献
73
+
74
+ 欢迎提交 Issue 和 Pull Request!
75
+
76
+ ## 许可证
77
+
78
+ MIT License
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "my-openlayer",
3
3
  "private": false,
4
- "version": "2.4.7",
4
+ "version": "2.4.9",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "main": "index.js",
@@ -20,13 +20,12 @@
20
20
  "bugs": {
21
21
  "url": "https://github.com/cuteyuchen/my-openlayer/issues"
22
22
  },
23
- "homepage": "https://github.com/cuteyuchen/my-openlayer#readme",
23
+ "homepage": "https://cuteyuchen.github.io/my-openlayer/",
24
24
  "files": [
25
25
  "**/*",
26
26
  "LICENSE",
27
27
  "README.md",
28
28
  "CHANGELOG.md",
29
- "AI_CONTEXT.md",
30
29
  "docs",
31
30
  "package.json"
32
31
  ],
@@ -36,7 +35,10 @@
36
35
  "preview": "vite preview",
37
36
  "prepare-publish": "node scripts/prepare-publish.cjs",
38
37
  "publish-flat": "npm run build && npm run prepare-publish && cd temp-publish && npm publish",
39
- "publish-flat-dry": "npm run build && npm run prepare-publish && cd temp-publish && npm publish --dry-run"
38
+ "publish-flat-dry": "npm run build && npm run prepare-publish && cd temp-publish && npm publish --dry-run",
39
+ "docs:dev": "vitepress dev docs",
40
+ "docs:build": "vitepress build docs",
41
+ "docs:preview": "vitepress preview docs"
40
42
  },
41
43
  "dependencies": {
42
44
  "@turf/turf": "^7.2.0",
@@ -50,6 +52,7 @@
50
52
  "vite": "^5.4.10",
51
53
  "vite-plugin-css-modules": "^0.0.1",
52
54
  "vite-plugin-libcss": "^1.1.1",
55
+ "vitepress": "^1.6.4",
53
56
  "vue-tsc": "^2.0.6"
54
57
  },
55
58
  "peerDependencies": {
package/types.d.ts CHANGED
@@ -236,6 +236,8 @@ export interface ClusterOptions extends PointOptions {
236
236
  */
237
237
  export interface TwinkleItem extends PointData {
238
238
  className?: string;
239
+ /** 自定义DOM元素,可以是HTMLElement或者返回HTMLElement的函数 */
240
+ element?: HTMLElement | ((item: TwinkleItem) => HTMLElement);
239
241
  [key: string]: any;
240
242
  }
241
243
  /**
package/AI_CONTEXT.md DELETED
@@ -1,147 +0,0 @@
1
- # AI Context for my-openlayer
2
-
3
- Use this context to understand how to use the `my-openlayer` library.
4
-
5
- ## Project Overview
6
-
7
- `my-openlayer` is a modern map component library based on OpenLayers, designed for Web GIS applications. It provides a modular, TypeScript-ready wrapper around OpenLayers features.
8
-
9
- - **Core Dependency**: `ol` (OpenLayers)
10
- - **Key Features**: Map initialization, Tianditu (天地图) support, Point/Line/Polygon management, Event handling, Selection, Measurement, Vue component markers.
11
-
12
- ## Core Architecture
13
-
14
- - **MyOl**: The main entry class. Initializes the map and provides access to sub-modules.
15
- - **Modules** (Lazy loaded via getters):
16
- - `MapBaseLayers`: Base map switching (Vector, Image, Terrain) and Annotation layers.
17
- - `Point`: Point features, clusters, DOM markers.
18
- - `Line`: Line features, river layers.
19
- - `Polygon`: Polygon features, heatmaps, image layers, masks.
20
- - `MapTools`: General tools (Zoom, Fit, Layer management).
21
- - `MeasureHandler`: Distance and Area measurement.
22
- - `SelectHandler`: Feature selection interaction.
23
- - `EventManager`: Unified event listener management.
24
- - **Utils**: `ConfigManager`, `ErrorHandler`, `ValidationUtils`.
25
-
26
- ## Quick Start (Minimal Example)
27
-
28
- ```typescript
29
- import MyOl, { MapInitType } from 'my-openlayer';
30
-
31
- // 1. Configuration
32
- const config: MapInitType = {
33
- target: 'map-container', // ID of the DIV
34
- center: [119.81, 29.969], // [Longitude, Latitude]
35
- zoom: 10,
36
- token: 'YOUR_TIANDITU_TOKEN', // Required for Tianditu base maps
37
- annotation: true // Show annotation layer by default
38
- };
39
-
40
- // 2. Initialize
41
- const map = new MyOl('map-container', config);
42
-
43
- // 3. Access Modules & Add Features
44
- map.getPoint().addPoint([{ lgtd: 119.81, lttd: 29.969, name: 'Demo' }], {
45
- layerName: 'demo-layer',
46
- img: 'marker.png'
47
- });
48
- ```
49
-
50
- ## API Reference (Condensed)
51
-
52
- ### `MyOl` (Main Class)
53
- - `constructor(id: string | HTMLElement, options?: MapInitType)`
54
- - `getPoint()`: Returns `Point` instance.
55
- - `getLine()`: Returns `Line` instance.
56
- - `getPolygon()`: Returns `Polygon` instance.
57
- - `getMapBaseLayers()`: Returns `MapBaseLayers` instance.
58
- - `getTools()`: Returns `MapTools` instance.
59
- - `getSelectHandler()`: Returns `SelectHandler` instance.
60
- - `getEventManager()`: Returns `EventManager` instance.
61
- - `locationAction(lon, lat, zoom, duration)`: Animate to location.
62
-
63
- ### `MapBaseLayers`
64
- - `switchBaseLayer(type: 'vec_c' | 'img_c' | 'ter_c')`: Switch base map.
65
- - `setAnnotationVisible(visible: boolean)`: Toggle text annotations.
66
- - `addGeoServerLayer(url, layerName, options)`: Add WMS layer.
67
-
68
- ### `Point`
69
- - `addPoint(data: PointData[], options: PointOptions)`: Add markers.
70
- - `addClusterPoint(data, options)`: Add clustered markers.
71
- - `addVueTemplatePoint(data, Component, options)`: Use Vue component as marker.
72
-
73
- ### `Line`
74
- - `addLine(geoJson, options)`: Add lines from GeoJSON.
75
- - `addLineByUrl(url, options)`: Load GeoJSON from URL.
76
-
77
- ### `Polygon`
78
- - `addPolygon(geoJson, options)`: Add polygons.
79
- - `addBorderPolygon(geoJson, options)`: Add boundary lines.
80
- - `updateFeatureColor(layerName, colorMap, options)`: Update colors dynamically.
81
- - `addHeatmap(data, options)`: Add heatmap.
82
-
83
- ### `SelectHandler`
84
- - `enableSelect(mode: 'click'|'hover', options)`: Enable selection.
85
- - `selectByIds(ids, options)`: Programmatic selection.
86
-
87
- ### `MeasureHandler`
88
- - **Important**: Must be instantiated manually if not exposed via `MyOl`.
89
- - `new MeasureHandler(map.map)`
90
- - `start('LineString' | 'Polygon')`
91
- - `end()`, `clean()`
92
-
93
- ## Key Type Definitions (TypeScript)
94
-
95
- Use these interfaces to ensure type safety.
96
-
97
- ```typescript
98
- export interface MapInitType {
99
- layers?: LayerItem[] | { [key: string]: LayerItem[] };
100
- zoom?: number;
101
- center?: number[]; // [lon, lat]
102
- minZoom?: number;
103
- maxZoom?: number;
104
- token?: string; // Tianditu Token
105
- annotation?: boolean;
106
- }
107
-
108
- export interface BaseOptions {
109
- layerName?: string;
110
- zIndex?: number;
111
- visible?: boolean;
112
- opacity?: number;
113
- }
114
-
115
- export interface PointOptions extends BaseOptions {
116
- textKey?: string; // Property key for label text
117
- img?: string; // Icon URL
118
- scale?: number;
119
- textFillColor?: string;
120
- }
121
-
122
- export interface PointData {
123
- lgtd: number;
124
- lttd: number;
125
- [key: string]: any;
126
- }
127
-
128
- export interface LineOptions extends BaseOptions {
129
- strokeColor?: string;
130
- strokeWidth?: number;
131
- lineDash?: number[];
132
- }
133
-
134
- export interface PolygonOptions extends BaseOptions {
135
- fillColor?: string;
136
- strokeColor?: string;
137
- textKey?: string;
138
- }
139
- ```
140
-
141
- ## Best Practices
142
-
143
- 1. **Use Modules**: Access functionality through `map.getPoint()`, `map.getLine()`, etc., rather than manipulating the `ol.Map` directly when possible.
144
- 2. **Layer Names**: Always provide a unique `layerName` in options to easily retrieve or remove layers later (`map.getTools().removeLayer('my-layer')`).
145
- 3. **Coordinate System**: The library defaults to `EPSG:4326` (WGS84) for input coordinates (lon/lat) and `CGCS2000` internally where applicable.
146
- 4. **Vue Integration**: Use `addVueTemplatePoint` for complex markers requiring interactivity or dynamic content.
147
- 5. **Event Handling**: Use `map.getEventManager().on('click', ...)` instead of native listeners for better management.