my-openlayer 2.4.2 → 2.4.3
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/AI_CONTEXT.md +147 -0
- package/CHANGELOG.md +53 -0
- package/README.md +156 -1502
- package/core/SelectHandler.d.ts +6 -0
- package/core/SelectHandler.js +27 -2
- package/docs/ConfigManager.md +40 -0
- package/docs/ErrorHandler.md +45 -0
- package/docs/EventManager.md +52 -0
- package/docs/Line.md +52 -0
- package/docs/MapBaseLayers.md +48 -0
- package/docs/MapTools.md +48 -0
- package/docs/MeasureHandler.md +47 -0
- package/docs/MyOl.md +62 -0
- package/docs/Point.md +58 -0
- package/docs/Polygon.md +65 -0
- package/docs/RiverLayerManager.md +59 -0
- package/docs/SelectHandler.md +59 -0
- package/docs/ValidationUtils.md +38 -0
- package/docs/VueTemplatePoint.md +85 -0
- package/package.json +4 -1
package/core/SelectHandler.d.ts
CHANGED
|
@@ -145,6 +145,12 @@ export default class SelectHandler {
|
|
|
145
145
|
* @returns SelectHandler 实例(支持链式调用)
|
|
146
146
|
*/
|
|
147
147
|
updateSelectStyle(selectStyle: Style | Style[] | ((feature: FeatureLike) => Style | Style[])): this;
|
|
148
|
+
/**
|
|
149
|
+
* 确保 Select 交互已创建
|
|
150
|
+
* 如果当前未启用选择交互,则创建一个不响应用户操作的交互实例用于编程式选择
|
|
151
|
+
* @private
|
|
152
|
+
*/
|
|
153
|
+
private ensureSelectInteraction;
|
|
148
154
|
/**
|
|
149
155
|
* 附加事件监听器
|
|
150
156
|
* @private
|
package/core/SelectHandler.js
CHANGED
|
@@ -151,8 +151,10 @@ export default class SelectHandler {
|
|
|
151
151
|
*/
|
|
152
152
|
selectByIds(featureIds, options) {
|
|
153
153
|
try {
|
|
154
|
+
// 确保交互实例存在
|
|
155
|
+
this.ensureSelectInteraction();
|
|
154
156
|
if (!this.selectInteraction) {
|
|
155
|
-
|
|
157
|
+
// 理论上 ensureSelectInteraction 后不应为空,这里做双重保险
|
|
156
158
|
return this;
|
|
157
159
|
}
|
|
158
160
|
if (!featureIds || featureIds.length === 0) {
|
|
@@ -215,8 +217,10 @@ export default class SelectHandler {
|
|
|
215
217
|
*/
|
|
216
218
|
selectByProperty(propertyName, propertyValue, options) {
|
|
217
219
|
try {
|
|
220
|
+
// 确保交互实例存在
|
|
221
|
+
this.ensureSelectInteraction();
|
|
218
222
|
if (!this.selectInteraction) {
|
|
219
|
-
|
|
223
|
+
// 理论上 ensureSelectInteraction 后不应为空,这里做双重保险
|
|
220
224
|
return this;
|
|
221
225
|
}
|
|
222
226
|
if (!propertyName) {
|
|
@@ -463,6 +467,27 @@ export default class SelectHandler {
|
|
|
463
467
|
throw error;
|
|
464
468
|
}
|
|
465
469
|
}
|
|
470
|
+
/**
|
|
471
|
+
* 确保 Select 交互已创建
|
|
472
|
+
* 如果当前未启用选择交互,则创建一个不响应用户操作的交互实例用于编程式选择
|
|
473
|
+
* @private
|
|
474
|
+
*/
|
|
475
|
+
ensureSelectInteraction() {
|
|
476
|
+
if (this.selectInteraction) {
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
// 创建一个不响应任何用户操作的 Select 交互
|
|
480
|
+
// condition 返回 false 表示不响应任何事件
|
|
481
|
+
this.selectInteraction = new Select({
|
|
482
|
+
condition: () => false,
|
|
483
|
+
style: this.createSelectStyle()
|
|
484
|
+
});
|
|
485
|
+
this.map.addInteraction(this.selectInteraction);
|
|
486
|
+
this.isEnabled = true;
|
|
487
|
+
// 注意:这里我们不设置 currentMode,因为这是一种特殊的编程式模式
|
|
488
|
+
// 也不需要 attachEventListeners,因为这种交互不会触发用户事件
|
|
489
|
+
this.errorHandler.debug('已自动创建编程式选择交互实例');
|
|
490
|
+
}
|
|
466
491
|
/**
|
|
467
492
|
* 附加事件监听器
|
|
468
493
|
* @private
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# ConfigManager 配置管理类
|
|
2
|
+
|
|
3
|
+
`ConfigManager` 用于统一管理库的默认配置项,提供配置合并和 ID 生成工具。
|
|
4
|
+
|
|
5
|
+
## 静态属性 (默认配置)
|
|
6
|
+
|
|
7
|
+
- **DEFAULT_POINT_OPTIONS**: 默认点位配置。
|
|
8
|
+
- **DEFAULT_LINE_OPTIONS**: 默认线要素配置。
|
|
9
|
+
- **DEFAULT_POLYGON_OPTIONS**: 默认面要素配置。
|
|
10
|
+
- **DEFAULT_CLUSTER_OPTIONS**: 默认聚合配置。
|
|
11
|
+
- **DEFAULT_HEATMAP_OPTIONS**: 默认热力图配置。
|
|
12
|
+
- **DEFAULT_IMAGE_OPTIONS**: 默认图片图层配置。
|
|
13
|
+
- **DEFAULT_MASK_OPTIONS**: 默认遮罩配置。
|
|
14
|
+
- **TIANDITU_CONFIG**: 天地图服务配置。
|
|
15
|
+
|
|
16
|
+
## 静态方法
|
|
17
|
+
|
|
18
|
+
- **mergeOptions<T>(defaultOptions: T, userOptions?: Partial<T>)**: 合并用户配置与默认配置。
|
|
19
|
+
- **generateId(prefix?: string)**: 生成带前缀的唯一 ID。
|
|
20
|
+
- **deepClone<T>(obj: T)**: 深度克隆对象。
|
|
21
|
+
|
|
22
|
+
## 使用示例
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { ConfigManager, PointOptions } from 'my-openlayer';
|
|
26
|
+
|
|
27
|
+
// 1. 合并用户配置与默认配置
|
|
28
|
+
const userOptions: PointOptions = {
|
|
29
|
+
layerName: 'my-points',
|
|
30
|
+
visible: true
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const finalOptions = ConfigManager.mergeOptions(
|
|
34
|
+
ConfigManager.DEFAULT_POINT_OPTIONS,
|
|
35
|
+
userOptions
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
// 2. 生成唯一 ID
|
|
39
|
+
const pointId = ConfigManager.generateId('point'); // 例如: point_169...
|
|
40
|
+
```
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# ErrorHandler 错误处理类
|
|
2
|
+
|
|
3
|
+
`ErrorHandler` 是一个单例类,提供全局的错误捕获、日志记录和回调分发机制。
|
|
4
|
+
|
|
5
|
+
## 方法
|
|
6
|
+
|
|
7
|
+
- **getInstance()**: 获取单例实例。
|
|
8
|
+
- **addErrorCallback(callback)**: 添加全局错误监听回调。
|
|
9
|
+
- **handleError(error: MyOpenLayersError)**: 手动触发错误处理。
|
|
10
|
+
- **validate(condition, message, context)**: 断言验证,失败则抛出错误。
|
|
11
|
+
- **setEnabled(enabled: boolean)**: 启用/禁用日志。
|
|
12
|
+
- **setLogLevel(level)**: 设置日志级别 (`debug`, `info`, `warn`, `error`)。
|
|
13
|
+
|
|
14
|
+
## 静态验证方法
|
|
15
|
+
|
|
16
|
+
- **validateMap(map)**: 验证地图实例。
|
|
17
|
+
- **validateCoordinates(lng, lat)**: 验证经纬度有效性。
|
|
18
|
+
- **validateLayerName(name)**: 验证图层名称。
|
|
19
|
+
|
|
20
|
+
## 使用示例
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { ErrorHandler, MyOpenLayersError } from 'my-openlayer';
|
|
24
|
+
|
|
25
|
+
// 1. 获取实例
|
|
26
|
+
const errorHandler = ErrorHandler.getInstance();
|
|
27
|
+
|
|
28
|
+
// 2. 注册全局错误监听
|
|
29
|
+
errorHandler.addErrorCallback((error) => {
|
|
30
|
+
console.error('地图组件发生错误:', error.message);
|
|
31
|
+
// 上报错误监控系统
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// 3. 手动验证数据
|
|
35
|
+
try {
|
|
36
|
+
ErrorHandler.validateCoordinates(200, 0); // 将抛出错误,因为经度超出范围
|
|
37
|
+
} catch (e) {
|
|
38
|
+
// 处理验证错误
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// 4. 手动触发错误
|
|
42
|
+
errorHandler.handleError(
|
|
43
|
+
new MyOpenLayersError('自定义错误消息', 'CUSTOM_ERROR', { detail: '...' })
|
|
44
|
+
);
|
|
45
|
+
```
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# EventManager 事件管理类
|
|
2
|
+
|
|
3
|
+
`EventManager` 提供统一的地图事件监听和管理功能,支持事件过滤、一次性监听和自动计数。
|
|
4
|
+
|
|
5
|
+
## 方法
|
|
6
|
+
|
|
7
|
+
- **on(type: MapEventType, callback: EventCallback, options?: { once?: boolean; filter?: (event: MapEventData) => boolean })**: 注册事件监听器。
|
|
8
|
+
- 支持的事件类型: `click`, `dblclick`, `hover`, `moveend`, `zoomend`, `pointermove`, `rendercomplete`, `error`。
|
|
9
|
+
- **off(id: string)**: 根据 ID 移除事件监听器。
|
|
10
|
+
- **offAll(type: MapEventType)**: 移除指定类型的所有监听器。
|
|
11
|
+
- **clear()**: 清除所有事件监听器。
|
|
12
|
+
- **getListenerCount(type: MapEventType)**: 获取指定类型的监听器数量。
|
|
13
|
+
|
|
14
|
+
## 类型定义
|
|
15
|
+
|
|
16
|
+
### MapEventData
|
|
17
|
+
包含事件的详细信息:
|
|
18
|
+
- `type`: 事件类型。
|
|
19
|
+
- `coordinate`: 地理坐标。
|
|
20
|
+
- `pixel`: 屏幕像素坐标。
|
|
21
|
+
- `feature`: 触发事件的要素(如有)。
|
|
22
|
+
- `features`: 触发事件的所有要素列表。
|
|
23
|
+
- `zoom`: 当前缩放级别。
|
|
24
|
+
|
|
25
|
+
## 使用示例
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
const eventManager = map.getEventManager();
|
|
29
|
+
|
|
30
|
+
// 1. 监听点击事件
|
|
31
|
+
const clickListenerId = eventManager.on('click', (event) => {
|
|
32
|
+
console.log('点击坐标:', event.coordinate);
|
|
33
|
+
if (event.feature) {
|
|
34
|
+
console.log('点击到的要素:', event.feature.getProperties());
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// 2. 监听一次性事件
|
|
39
|
+
eventManager.on('rendercomplete', () => {
|
|
40
|
+
console.log('地图渲染完成');
|
|
41
|
+
}, { once: true });
|
|
42
|
+
|
|
43
|
+
// 3. 带过滤器的监听
|
|
44
|
+
eventManager.on('click', (event) => {
|
|
45
|
+
console.log('点击了特定图层的要素');
|
|
46
|
+
}, {
|
|
47
|
+
filter: (e) => e.feature && e.feature.get('layerName') === 'target-layer'
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// 4. 移除监听
|
|
51
|
+
eventManager.off(clickListenerId);
|
|
52
|
+
```
|
package/docs/Line.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Line 线要素类
|
|
2
|
+
|
|
3
|
+
`Line` 类用于在地图上绘制线要素,支持 GeoJSON 数据加载。
|
|
4
|
+
|
|
5
|
+
## 方法
|
|
6
|
+
|
|
7
|
+
- **addLine(data: MapJSONData, options?: LineOptions)**: 添加线要素图层。
|
|
8
|
+
- `data`: GeoJSON 格式的数据。
|
|
9
|
+
- `options`: 配置项,支持 `strokeColor` (颜色), `strokeWidth` (宽度), `lineDash` (虚线) 等。
|
|
10
|
+
|
|
11
|
+
- **addLineByUrl(url: string, options?: LineOptions)**: 从 URL 加载并添加线要素图层。
|
|
12
|
+
|
|
13
|
+
- **removeLineLayer(layerName: string)**: 根据图层名称移除线图层。
|
|
14
|
+
|
|
15
|
+
## 使用示例
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
const lineModule = map.getLine();
|
|
19
|
+
|
|
20
|
+
// GeoJSON 数据
|
|
21
|
+
const lineData = {
|
|
22
|
+
type: 'FeatureCollection',
|
|
23
|
+
features: [
|
|
24
|
+
{
|
|
25
|
+
type: 'Feature',
|
|
26
|
+
geometry: {
|
|
27
|
+
type: 'LineString',
|
|
28
|
+
coordinates: [[119.8, 29.9], [119.9, 30.0]]
|
|
29
|
+
},
|
|
30
|
+
properties: { name: '线路1' }
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// 1. 添加线图层
|
|
36
|
+
lineModule.addLine(lineData, {
|
|
37
|
+
layerName: 'my-line-layer',
|
|
38
|
+
strokeColor: '#ff0000',
|
|
39
|
+
strokeWidth: 4,
|
|
40
|
+
lineDash: [10, 10], // 虚线样式
|
|
41
|
+
zIndex: 10
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// 2. 从 URL 加载
|
|
45
|
+
lineModule.addLineByUrl('http://example.com/lines.json', {
|
|
46
|
+
layerName: 'url-line-layer',
|
|
47
|
+
strokeColor: 'blue'
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// 3. 移除图层
|
|
51
|
+
lineModule.removeLineLayer('my-line-layer');
|
|
52
|
+
```
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# MapBaseLayers 底图管理类
|
|
2
|
+
|
|
3
|
+
`MapBaseLayers` 用于管理地图底图(如天地图)和注记图层,支持图层切换和自定义图层。
|
|
4
|
+
|
|
5
|
+
## 方法
|
|
6
|
+
|
|
7
|
+
### 底图操作
|
|
8
|
+
|
|
9
|
+
- **switchBaseLayer(type: string)**: 切换底图类型(如 `vec_c`, `img_c`, `ter_c`)。
|
|
10
|
+
- **getCurrentBaseLayerType()**: 获取当前底图类型。
|
|
11
|
+
|
|
12
|
+
### 注记操作
|
|
13
|
+
|
|
14
|
+
- **addAnnotationLayer(options: AnnotationLayerOptions)**: 添加注记图层。
|
|
15
|
+
- **switchAnnotationLayer(annotationType: AnnotationType)**: 切换注记类型(如 `cva_c`)。
|
|
16
|
+
- **setAnnotationVisible(visible: boolean)**: 设置注记图层可见性。
|
|
17
|
+
- **isAnnotationVisible()**: 检查注记图层是否可见。
|
|
18
|
+
|
|
19
|
+
### 其他图层
|
|
20
|
+
|
|
21
|
+
- **addGeoServerLayer(url: string, layerName: string, options: GeoServerLayerOptions)**: 添加 GeoServer WMS 图层。
|
|
22
|
+
- **removeLayersByType(type: string)**: 移除指定类型的图层。
|
|
23
|
+
- **clearAllLayers()**: 清除所有底图和注记图层。
|
|
24
|
+
- **getLayerStats()**: 获取图层统计信息。
|
|
25
|
+
|
|
26
|
+
## 使用示例
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
const baseLayers = map.getMapBaseLayers();
|
|
30
|
+
|
|
31
|
+
// 1. 切换底图
|
|
32
|
+
// vec_c: 矢量底图, img_c: 影像底图, ter_c: 地形底图
|
|
33
|
+
baseLayers.switchBaseLayer('img_c');
|
|
34
|
+
|
|
35
|
+
// 2. 控制注记图层
|
|
36
|
+
baseLayers.setAnnotationVisible(false); // 隐藏注记
|
|
37
|
+
baseLayers.switchAnnotationLayer('cia_c'); // 切换为影像注记
|
|
38
|
+
|
|
39
|
+
// 3. 添加 GeoServer WMS 图层
|
|
40
|
+
baseLayers.addGeoServerLayer(
|
|
41
|
+
'http://localhost:8080/geoserver/wms',
|
|
42
|
+
'workspace:layer_name',
|
|
43
|
+
{
|
|
44
|
+
visible: true,
|
|
45
|
+
zIndex: 5
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
```
|
package/docs/MapTools.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# MapTools 地图工具类
|
|
2
|
+
|
|
3
|
+
`MapTools` 提供通用的地图操作工具,如图层查找、移除、显隐控制、地图裁剪和视图自适应。
|
|
4
|
+
|
|
5
|
+
## 方法
|
|
6
|
+
|
|
7
|
+
### 图层管理
|
|
8
|
+
|
|
9
|
+
- **getLayerByLayerName(layerName: string | string[])**: 根据名称获取图层对象(支持模糊匹配)。
|
|
10
|
+
- **removeLayer(layerName: string | string[])**: 移除指定名称的图层。
|
|
11
|
+
- **setLayerVisible(layerName: string, visible: boolean)**: 设置图层可见性。
|
|
12
|
+
|
|
13
|
+
### 视图操作
|
|
14
|
+
|
|
15
|
+
- **locationAction(lgtd: number, lttd: number, zoom?: number, duration?: number)**: 视图定位。
|
|
16
|
+
- **fitToLayers(layerNameOrLayers: string | string[] | Layer[], fitOptions?)**: 缩放地图以适应指定图层的范围。
|
|
17
|
+
- **fitByData(jsonData: MapJSONData, fitOptions?)**: 缩放地图以适应 GeoJSON 数据的范围。
|
|
18
|
+
|
|
19
|
+
### 其他
|
|
20
|
+
|
|
21
|
+
- **setMapClip(baseLayer: any, data: MapJSONData)**: 设置地图裁剪区域(Canvas 级裁剪)。
|
|
22
|
+
|
|
23
|
+
## 使用示例
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
const tools = map.getTools();
|
|
27
|
+
|
|
28
|
+
// 1. 获取图层
|
|
29
|
+
const layers = tools.getLayerByLayerName('my-layer');
|
|
30
|
+
if (layers.length > 0) {
|
|
31
|
+
console.log('找到图层:', layers[0]);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// 2. 移除图层
|
|
35
|
+
tools.removeLayer('temp-layer');
|
|
36
|
+
|
|
37
|
+
// 3. 视图自适应图层
|
|
38
|
+
tools.fitToLayers('target-layer', {
|
|
39
|
+
padding: [50, 50, 50, 50],
|
|
40
|
+
duration: 1000
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// 4. 根据数据缩放
|
|
44
|
+
tools.fitByData(geoJsonData);
|
|
45
|
+
|
|
46
|
+
// 5. 设置可见性
|
|
47
|
+
tools.setLayerVisible('background-layer', false);
|
|
48
|
+
```
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# MeasureHandler 测量工具类
|
|
2
|
+
|
|
3
|
+
`MeasureHandler` 提供在地图上进行距离和面积测量的功能。
|
|
4
|
+
|
|
5
|
+
## 方法
|
|
6
|
+
|
|
7
|
+
- **start(type: 'LineString' | 'Polygon')**: 开始测量。
|
|
8
|
+
- `'LineString'`: 测量距离(单位:m/km)。
|
|
9
|
+
- `'Polygon'`: 测量面积(单位:m²/km²)。
|
|
10
|
+
- **end()**: 结束当前的绘制测量操作。
|
|
11
|
+
- **clean()**: 清除所有测量结果和绘制的图形。
|
|
12
|
+
- **destory()**: 销毁测量工具,释放资源。
|
|
13
|
+
|
|
14
|
+
## 交互说明
|
|
15
|
+
|
|
16
|
+
- 单击开始绘制。
|
|
17
|
+
- 双击结束绘制。
|
|
18
|
+
- 移动鼠标会显示实时测量提示。
|
|
19
|
+
|
|
20
|
+
## 使用示例
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { MeasureHandler } from 'my-openlayer';
|
|
24
|
+
|
|
25
|
+
// 实例化测量工具(需要传入原生 ol.Map 对象)
|
|
26
|
+
const measure = new MeasureHandler(map.map);
|
|
27
|
+
|
|
28
|
+
// 1. 开始测距
|
|
29
|
+
document.getElementById('measure-dist-btn').onclick = () => {
|
|
30
|
+
measure.start('LineString');
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// 2. 开始测面
|
|
34
|
+
document.getElementById('measure-area-btn').onclick = () => {
|
|
35
|
+
measure.start('Polygon');
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// 3. 结束测量(停止绘制,保留图形)
|
|
39
|
+
document.getElementById('end-btn').onclick = () => {
|
|
40
|
+
measure.end();
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// 4. 清除结果(移除图形和提示)
|
|
44
|
+
document.getElementById('clear-btn').onclick = () => {
|
|
45
|
+
measure.clean();
|
|
46
|
+
};
|
|
47
|
+
```
|
package/docs/MyOl.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# MyOl 核心类
|
|
2
|
+
|
|
3
|
+
`MyOl` 是地图组件库的入口类,负责初始化地图实例并提供对各个功能模块的访问入口。
|
|
4
|
+
|
|
5
|
+
## 构造函数
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
new MyOl(id: string | HTMLElement, options?: MapInitType)
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
- **id**: 地图容器的 ID 或 DOM 元素。
|
|
12
|
+
- **options**: 地图初始化配置项。
|
|
13
|
+
|
|
14
|
+
## 方法
|
|
15
|
+
|
|
16
|
+
### 模块获取
|
|
17
|
+
|
|
18
|
+
- **getPoint()**: 获取点要素操作实例 `Point`。
|
|
19
|
+
- **getLine()**: 获取线要素操作实例 `Line`。
|
|
20
|
+
- **getPolygon()**: 获取面要素操作实例 `Polygon`。
|
|
21
|
+
- **getMapBaseLayers()**: 获取底图管理实例 `MapBaseLayers`。
|
|
22
|
+
- **getTools()**: 获取地图工具实例 `MapTools`。
|
|
23
|
+
- **getSelectHandler()**: 获取要素选择实例 `SelectHandler`。
|
|
24
|
+
- **getEventManager()**: 获取事件管理实例 `EventManager`。
|
|
25
|
+
- **getErrorHandler()**: 获取错误处理实例 `ErrorHandler`。
|
|
26
|
+
- **getConfigManager()**: 获取配置管理实例 `ConfigManager`。
|
|
27
|
+
|
|
28
|
+
### 地图操作
|
|
29
|
+
|
|
30
|
+
- **locationAction(longitude: number, latitude: number, zoom?: number, duration?: number)**: 地图定位到指定坐标。
|
|
31
|
+
- **resetPosition(duration?: number)**: 重置地图位置到初始中心点。
|
|
32
|
+
- **destroy()**: 销毁地图实例及相关资源。
|
|
33
|
+
|
|
34
|
+
### 静态方法
|
|
35
|
+
|
|
36
|
+
- **createView(options: MapInitType)**: 创建地图视图。
|
|
37
|
+
|
|
38
|
+
## 使用示例
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
import MyOl, { MapInitType } from 'my-openlayer';
|
|
42
|
+
|
|
43
|
+
// 1. 定义配置
|
|
44
|
+
const options: MapInitType = {
|
|
45
|
+
center: [119.81, 29.969],
|
|
46
|
+
zoom: 10,
|
|
47
|
+
minZoom: 3,
|
|
48
|
+
maxZoom: 18,
|
|
49
|
+
token: '您的天地图Token', // 可选,用于加载天地图
|
|
50
|
+
annotation: true // 是否显示注记
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// 2. 初始化地图
|
|
54
|
+
const map = new MyOl('map-container', options);
|
|
55
|
+
|
|
56
|
+
// 3. 获取功能模块
|
|
57
|
+
const pointModule = map.getPoint();
|
|
58
|
+
const lineModule = map.getLine();
|
|
59
|
+
|
|
60
|
+
// 4. 地图操作
|
|
61
|
+
map.locationAction(120.15, 30.28, 12); // 定位到杭州
|
|
62
|
+
```
|
package/docs/Point.md
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Point 点要素类
|
|
2
|
+
|
|
3
|
+
`Point` 类用于在地图上添加和管理点位要素,支持普通点位、聚合点位、DOM 点位和 Vue 组件点位。
|
|
4
|
+
|
|
5
|
+
## 方法
|
|
6
|
+
|
|
7
|
+
### 普通点位
|
|
8
|
+
|
|
9
|
+
- **addPoint(pointData: PointData[], options: PointOptions)**: 添加普通点位图层。
|
|
10
|
+
- `pointData`: 点位数据数组,需包含 `lgtd` (经度) 和 `lttd` (纬度)。
|
|
11
|
+
- `options`: 配置项,包括图标 `img`、文本 `textKey` 等。
|
|
12
|
+
|
|
13
|
+
### 聚合点位
|
|
14
|
+
|
|
15
|
+
- **addClusterPoint(pointData: PointData[], options: ClusterOptions)**: 添加聚合点位图层。
|
|
16
|
+
- 会根据地图缩放级别自动聚合临近的点位。
|
|
17
|
+
- `options.distance`: 聚合距离。
|
|
18
|
+
|
|
19
|
+
### DOM 与组件点位
|
|
20
|
+
|
|
21
|
+
- **addVueTemplatePoint(pointDataList: PointData[], template: any, options?)**: 添加 Vue 组件点位(推荐)。
|
|
22
|
+
- 返回控制对象,包含 `setVisible`, `remove`, `getPoints` 等方法。
|
|
23
|
+
- **addDomPoint(twinkleList: TwinkleItem[], callback?)**: 添加原生 DOM 点位(底层实现)。
|
|
24
|
+
|
|
25
|
+
### 其他
|
|
26
|
+
|
|
27
|
+
- **locationAction(lgtd: number, lttd: number, zoom?: number, duration?: number)**: 定位到指定点。
|
|
28
|
+
|
|
29
|
+
## 使用示例
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
const pointModule = map.getPoint();
|
|
33
|
+
|
|
34
|
+
// 1. 添加普通点位
|
|
35
|
+
const points = [
|
|
36
|
+
{ lgtd: 119.81, lttd: 29.969, name: '点A', type: 'station' },
|
|
37
|
+
{ lgtd: 119.82, lttd: 29.970, name: '点B', type: 'station' }
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
pointModule.addPoint(points, {
|
|
41
|
+
layerName: 'station-layer',
|
|
42
|
+
img: 'path/to/icon.png', // 图标路径
|
|
43
|
+
scale: 0.8,
|
|
44
|
+
textKey: 'name', // 显示 'name' 字段作为标注
|
|
45
|
+
textFillColor: '#000',
|
|
46
|
+
textOffsetY: 25
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// 2. 添加聚合点位
|
|
50
|
+
pointModule.addClusterPoint(points, {
|
|
51
|
+
layerName: 'cluster-layer',
|
|
52
|
+
distance: 40, // 聚合像素距离
|
|
53
|
+
img: 'path/to/cluster-icon.png'
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// 3. 定位
|
|
57
|
+
pointModule.locationAction(119.81, 29.969, 15);
|
|
58
|
+
```
|
package/docs/Polygon.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Polygon 面要素类
|
|
2
|
+
|
|
3
|
+
`Polygon` 类用于在地图上绘制面要素、热力图、图片图层和遮罩层。
|
|
4
|
+
|
|
5
|
+
## 方法
|
|
6
|
+
|
|
7
|
+
### 面要素操作
|
|
8
|
+
|
|
9
|
+
- **addPolygon(dataJSON: MapJSONData, options?: PolygonOptions)**: 添加多边形图层。
|
|
10
|
+
- 支持填充色 `fillColor`、边框 `strokeColor`、文本标注 `textKey` 等配置。
|
|
11
|
+
- **addPolygonByUrl(url: string, options?: PolygonOptions)**: 从 URL 加载多边形图层。
|
|
12
|
+
- **addBorderPolygon(data: MapJSONData, options?: PolygonOptions)**: 添加边界图层(通常用于行政区划边界)。
|
|
13
|
+
- **addBorderPolygonByUrl(url: string, options?: PolygonOptions)**: 从 URL 加载边界图层。
|
|
14
|
+
- **removePolygonLayer(layerName: string)**: 移除面图层。
|
|
15
|
+
|
|
16
|
+
### 样式更新
|
|
17
|
+
|
|
18
|
+
- **updateFeatureColor(layerName: string, colorObj?: { [propName: string]: string }, options?: FeatureColorUpdateOptions)**: 动态更新面要素颜色,常用于数据可视化展示。
|
|
19
|
+
|
|
20
|
+
### 高级图层
|
|
21
|
+
|
|
22
|
+
- **addImageLayer(imageData: ImageLayerData, options?: PolygonOptions)**: 添加图片图层(ImageStatic)。
|
|
23
|
+
- 支持将图片叠加在特定地理范围 `extent` 上。
|
|
24
|
+
- **addHeatmap(pointData: PointData[], options?: HeatMapOptions)**: 添加热力图。
|
|
25
|
+
- **addMaskLayer(data: any, options?: MaskLayerOptions)**: 添加遮罩图层(反向裁剪效果)。
|
|
26
|
+
- **setOutLayer(data: MapJSONData, options?)**: 设置外围蒙版图层(擦除效果)。
|
|
27
|
+
|
|
28
|
+
## 使用示例
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
const polygonModule = map.getPolygon();
|
|
32
|
+
|
|
33
|
+
// 1. 添加面图层
|
|
34
|
+
polygonModule.addPolygon(geoJsonData, {
|
|
35
|
+
layerName: 'area-layer',
|
|
36
|
+
fillColor: 'rgba(0, 0, 255, 0.1)',
|
|
37
|
+
strokeColor: 'blue',
|
|
38
|
+
strokeWidth: 2,
|
|
39
|
+
textKey: 'name', // 显示名称
|
|
40
|
+
textFillColor: '#fff'
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// 2. 动态更新颜色(数据可视化)
|
|
44
|
+
// 假设 'area-layer' 中的要素有 'name' 属性,我们将 '区域A' 设为红色
|
|
45
|
+
polygonModule.updateFeatureColor(
|
|
46
|
+
'area-layer',
|
|
47
|
+
{
|
|
48
|
+
'区域A': 'rgba(255, 0, 0, 0.5)',
|
|
49
|
+
'区域B': 'rgba(0, 255, 0, 0.5)'
|
|
50
|
+
},
|
|
51
|
+
{ textKey: 'name' }
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
// 3. 添加热力图
|
|
55
|
+
const heatPoints = [
|
|
56
|
+
{ lgtd: 119.8, lttd: 29.9, value: 100 },
|
|
57
|
+
{ lgtd: 119.9, lttd: 30.0, value: 50 }
|
|
58
|
+
];
|
|
59
|
+
polygonModule.addHeatmap(heatPoints, {
|
|
60
|
+
layerName: 'heatmap',
|
|
61
|
+
radius: 20,
|
|
62
|
+
blur: 15,
|
|
63
|
+
valueKey: 'value' // 权重字段
|
|
64
|
+
});
|
|
65
|
+
```
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# RiverLayerManager 河流图层管理类
|
|
2
|
+
|
|
3
|
+
`RiverLayerManager` 专门用于处理河流数据的分级显示和样式管理。
|
|
4
|
+
|
|
5
|
+
## 方法
|
|
6
|
+
|
|
7
|
+
### 分级显示 (Zoom-based)
|
|
8
|
+
|
|
9
|
+
根据地图缩放级别自动显示不同等级的河流。
|
|
10
|
+
|
|
11
|
+
- **addRiverLayersByZoom(fyRiverJson: MapJSONData, options?: RiverLayerOptions)**: 添加分级河流图层。
|
|
12
|
+
- `options.levelCount`: 河流等级总数。
|
|
13
|
+
- `options.zoomOffset`: 缩放级别偏移量,控制何时显示哪一级。
|
|
14
|
+
- **addRiverLayersByZoomByUrl(url: string, options?)**: 从 URL 加载分级河流。
|
|
15
|
+
- **showRiverLayer(show: boolean)**: 控制分级河流图层的总开关。
|
|
16
|
+
|
|
17
|
+
### 宽度分级 (Level-based Width)
|
|
18
|
+
|
|
19
|
+
根据河流等级属性渲染不同宽度的线条。
|
|
20
|
+
|
|
21
|
+
- **addRiverWidthByLevel(data: MapJSONData, options?)**: 添加按等级设定宽度的河流。
|
|
22
|
+
- **addRiverWidthByLevelByUrl(url: string, options?)**: 从 URL 加载。
|
|
23
|
+
|
|
24
|
+
### 管理
|
|
25
|
+
|
|
26
|
+
- **clearRiverLayers()**: 清除所有由该管理器创建的河流图层。
|
|
27
|
+
- **getRiverLayerVisibility()**: 获取当前可见性状态。
|
|
28
|
+
|
|
29
|
+
## 使用示例
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
// 需要单独实例化,或扩展 MyOl
|
|
33
|
+
import { RiverLayerManager } from 'my-openlayer';
|
|
34
|
+
|
|
35
|
+
const riverManager = new RiverLayerManager(map.map);
|
|
36
|
+
|
|
37
|
+
// 1. 添加分级河流(随缩放显示更多细节)
|
|
38
|
+
riverManager.addRiverLayersByZoom(riverGeoJSON, {
|
|
39
|
+
layerName: 'main-river',
|
|
40
|
+
levelCount: 5, // 数据中包含 level 1-5
|
|
41
|
+
zoomOffset: 8, // level 1 在 zoom > 9 (1+8) 显示
|
|
42
|
+
strokeColor: '#0071FF',
|
|
43
|
+
strokeWidth: 2
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// 2. 控制显隐
|
|
47
|
+
riverManager.showRiverLayer(true);
|
|
48
|
+
|
|
49
|
+
// 3. 添加按等级设定宽度的河流(静态显示)
|
|
50
|
+
riverManager.addRiverWidthByLevel(riverGeoJSON, {
|
|
51
|
+
layerName: 'width-river',
|
|
52
|
+
strokeColor: '#0071FF',
|
|
53
|
+
levelWidthMap: {
|
|
54
|
+
1: 5, // 1级河流宽5px
|
|
55
|
+
2: 3,
|
|
56
|
+
3: 1
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
```
|