my-openlayer 3.0.1 → 3.0.2
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/README.md +0 -2
- package/core/line/index.d.ts +0 -2
- package/core/line/index.js +0 -1
- package/core/map/ConfigManager.d.ts +0 -42
- package/core/map/ConfigManager.js +1 -13
- package/docs/.vitepress/config.mts +1 -2
- package/index.d.ts +1 -2
- package/index.js +1 -1
- package/package.json +1 -1
- package/core/line/RiverLayerManager.d.ts +0 -93
- package/core/line/RiverLayerManager.js +0 -340
- package/docs/RiverLayerManager.md +0 -187
package/README.md
CHANGED
|
@@ -47,7 +47,6 @@ my-openlayer 是一个基于 [OpenLayers](https://openlayers.org/) 的现代地
|
|
|
47
47
|
- **线要素绘制 (Line)**:支持静态线、流光线、流动线图标动画,详见 [Line 动画文档](docs/Line.md#流动线--动态图标线)
|
|
48
48
|
- **面要素 (Polygon)**:面要素绘制、分区高亮、遮罩层
|
|
49
49
|
- **Vue组件支持 (VueTemplatePoint)**:支持将 Vue 组件作为地图点位渲染
|
|
50
|
-
- **河流图层 (RiverLayerManager)**:支持分级显示的河流图层管理
|
|
51
50
|
|
|
52
51
|
- **🛠️ 地图工具**
|
|
53
52
|
- **测量工具 (MeasureHandler)**:距离和面积测量
|
|
@@ -240,7 +239,6 @@ ConfigManager.resetDefaults('LINE_OPTIONS');
|
|
|
240
239
|
- **[Line](docs/Line.md)**: 线要素(含静态线、流动线、URL 异步加载)。
|
|
241
240
|
- **[Polygon](docs/Polygon.md)**: 面要素(含热力图、图片层、遮罩层、统一 Handle)。
|
|
242
241
|
- **[VueTemplatePoint](docs/VueTemplatePoint.md)**: Vue 组件点位。
|
|
243
|
-
- **[RiverLayerManager](docs/RiverLayerManager.md)**: 河流图层管理。
|
|
244
242
|
|
|
245
243
|
### 交互与工具
|
|
246
244
|
- **[SelectHandler](docs/SelectHandler.md)**: 要素选择交互(支持独立样式渲染、多选隔离)。
|
package/core/line/index.d.ts
CHANGED
|
@@ -2,5 +2,3 @@ export { default as Line } from './Line';
|
|
|
2
2
|
export { default as LineFlowAnimator } from './LineFlowAnimator';
|
|
3
3
|
export { default as LineFeatureFactory } from './LineFeatureFactory';
|
|
4
4
|
export { default as LineStyleFactory } from './LineStyleFactory';
|
|
5
|
-
export { default as RiverLayerManager } from './RiverLayerManager';
|
|
6
|
-
export type { RiverLayerOptions, RiverLevelWidthMap } from './RiverLayerManager';
|
package/core/line/index.js
CHANGED
|
@@ -2,4 +2,3 @@ export { default as Line } from './Line';
|
|
|
2
2
|
export { default as LineFlowAnimator } from './LineFlowAnimator';
|
|
3
3
|
export { default as LineFeatureFactory } from './LineFeatureFactory';
|
|
4
4
|
export { default as LineStyleFactory } from './LineStyleFactory';
|
|
5
|
-
export { default as RiverLayerManager } from './RiverLayerManager';
|
|
@@ -97,27 +97,6 @@ interface DefaultsRegistry {
|
|
|
97
97
|
visible: boolean;
|
|
98
98
|
zIndex: number;
|
|
99
99
|
};
|
|
100
|
-
RIVER_LEVEL_WIDTH_MAP: Record<number, number>;
|
|
101
|
-
RIVER_LAYERS_BY_ZOOM_OPTIONS: {
|
|
102
|
-
type: string;
|
|
103
|
-
levelCount: number;
|
|
104
|
-
zoomOffset: number;
|
|
105
|
-
strokeColor: string;
|
|
106
|
-
strokeWidth: number;
|
|
107
|
-
visible: boolean;
|
|
108
|
-
zIndex: number;
|
|
109
|
-
layerName: string;
|
|
110
|
-
removeExisting: boolean;
|
|
111
|
-
};
|
|
112
|
-
RIVER_WIDTH_BY_LEVEL_OPTIONS: {
|
|
113
|
-
type: string;
|
|
114
|
-
layerName: string;
|
|
115
|
-
strokeColor: string;
|
|
116
|
-
strokeWidth: number;
|
|
117
|
-
visible: boolean;
|
|
118
|
-
zIndex: number;
|
|
119
|
-
removeExisting: boolean;
|
|
120
|
-
};
|
|
121
100
|
}
|
|
122
101
|
/**
|
|
123
102
|
* 配置管理类
|
|
@@ -222,27 +201,6 @@ export default class ConfigManager {
|
|
|
222
201
|
visible: boolean;
|
|
223
202
|
zIndex: number;
|
|
224
203
|
};
|
|
225
|
-
static get DEFAULT_RIVER_LEVEL_WIDTH_MAP(): Record<number, number>;
|
|
226
|
-
static get DEFAULT_RIVER_LAYERS_BY_ZOOM_OPTIONS(): {
|
|
227
|
-
type: string;
|
|
228
|
-
levelCount: number;
|
|
229
|
-
zoomOffset: number;
|
|
230
|
-
strokeColor: string;
|
|
231
|
-
strokeWidth: number;
|
|
232
|
-
visible: boolean;
|
|
233
|
-
zIndex: number;
|
|
234
|
-
layerName: string;
|
|
235
|
-
removeExisting: boolean;
|
|
236
|
-
};
|
|
237
|
-
static get DEFAULT_RIVER_WIDTH_BY_LEVEL_OPTIONS(): {
|
|
238
|
-
type: string;
|
|
239
|
-
layerName: string;
|
|
240
|
-
strokeColor: string;
|
|
241
|
-
strokeWidth: number;
|
|
242
|
-
visible: boolean;
|
|
243
|
-
zIndex: number;
|
|
244
|
-
removeExisting: boolean;
|
|
245
|
-
};
|
|
246
204
|
/**
|
|
247
205
|
* 合并配置选项
|
|
248
206
|
* @param defaultOptions 默认配置
|
|
@@ -66,16 +66,7 @@ const BUILTIN_DEFAULTS = {
|
|
|
66
66
|
},
|
|
67
67
|
MAP_LAYERS_OPTIONS: { zIndex: 9, annotation: false, mapClip: false, mapClipData: undefined },
|
|
68
68
|
MYOL_OPTIONS: { layers: undefined, zoom: 10, center: [119.81, 29.969], extent: undefined },
|
|
69
|
-
VUE_TEMPLATE_POINT_OPTIONS: { positioning: 'center-center', stopEvent: false, visible: true, zIndex: 1 }
|
|
70
|
-
RIVER_LEVEL_WIDTH_MAP: { 1: 2, 2: 1, 3: 0.5, 4: 0.5, 5: 0.5 },
|
|
71
|
-
RIVER_LAYERS_BY_ZOOM_OPTIONS: {
|
|
72
|
-
type: 'river', levelCount: 5, zoomOffset: 8, strokeColor: 'rgb(0,113,255)', strokeWidth: 3,
|
|
73
|
-
visible: true, zIndex: 15, layerName: 'riverLayer', removeExisting: false
|
|
74
|
-
},
|
|
75
|
-
RIVER_WIDTH_BY_LEVEL_OPTIONS: {
|
|
76
|
-
type: 'river', layerName: 'river', strokeColor: 'rgba(3, 122, 255, 1)', strokeWidth: 2,
|
|
77
|
-
visible: true, zIndex: 15, removeExisting: false
|
|
78
|
-
}
|
|
69
|
+
VUE_TEMPLATE_POINT_OPTIONS: { positioning: 'center-center', stopEvent: false, visible: true, zIndex: 1 }
|
|
79
70
|
};
|
|
80
71
|
/**
|
|
81
72
|
* 当前生效的 defaults。运行时通过 setDefaults 修改这里的值,getter 再合并。
|
|
@@ -155,9 +146,6 @@ export default class ConfigManager {
|
|
|
155
146
|
static get DEFAULT_MAP_LAYERS_OPTIONS() { return currentDefaults.MAP_LAYERS_OPTIONS; }
|
|
156
147
|
static get DEFAULT_MYOL_OPTIONS() { return currentDefaults.MYOL_OPTIONS; }
|
|
157
148
|
static get DEFAULT_VUE_TEMPLATE_POINT_OPTIONS() { return currentDefaults.VUE_TEMPLATE_POINT_OPTIONS; }
|
|
158
|
-
static get DEFAULT_RIVER_LEVEL_WIDTH_MAP() { return currentDefaults.RIVER_LEVEL_WIDTH_MAP; }
|
|
159
|
-
static get DEFAULT_RIVER_LAYERS_BY_ZOOM_OPTIONS() { return currentDefaults.RIVER_LAYERS_BY_ZOOM_OPTIONS; }
|
|
160
|
-
static get DEFAULT_RIVER_WIDTH_BY_LEVEL_OPTIONS() { return currentDefaults.RIVER_WIDTH_BY_LEVEL_OPTIONS; }
|
|
161
149
|
/**
|
|
162
150
|
* 合并配置选项
|
|
163
151
|
* @param defaultOptions 默认配置
|
|
@@ -31,8 +31,7 @@ export default defineConfig({
|
|
|
31
31
|
{ text: 'Point 点要素', link: '/Point' },
|
|
32
32
|
{ text: 'Line 线要素', link: '/Line' },
|
|
33
33
|
{ text: 'Polygon 面要素', link: '/Polygon' },
|
|
34
|
-
{ text: 'VueTemplatePoint Vue点位', link: '/VueTemplatePoint' }
|
|
35
|
-
{ text: 'RiverLayerManager 河流图层', link: '/RiverLayerManager' }
|
|
34
|
+
{ text: 'VueTemplatePoint Vue点位', link: '/VueTemplatePoint' }
|
|
36
35
|
]
|
|
37
36
|
},
|
|
38
37
|
{
|
package/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
export { default } from './MyOl';
|
|
2
2
|
export { default as MyOl } from './MyOl';
|
|
3
3
|
export { Point } from './core/point';
|
|
4
|
-
export { Line
|
|
5
|
-
export type { RiverLayerOptions, RiverLevelWidthMap } from './core/line';
|
|
4
|
+
export { Line } from './core/line';
|
|
6
5
|
export { Polygon } from './core/polygon';
|
|
7
6
|
export { MapBaseLayers, MapTools, MeasureHandler, ConfigManager, EventManager } from './core/map';
|
|
8
7
|
export { VueTemplatePoint } from './core/vue-template-point';
|
package/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export { default } from './MyOl';
|
|
3
3
|
export { default as MyOl } from './MyOl';
|
|
4
4
|
export { Point } from './core/point';
|
|
5
|
-
export { Line
|
|
5
|
+
export { Line } from './core/line';
|
|
6
6
|
export { Polygon } from './core/polygon';
|
|
7
7
|
export { MapBaseLayers, MapTools, MeasureHandler, ConfigManager, EventManager } from './core/map';
|
|
8
8
|
export { VueTemplatePoint } from './core/vue-template-point';
|
package/package.json
CHANGED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import Map from "ol/Map";
|
|
2
|
-
import VectorSource from "ol/source/Vector";
|
|
3
|
-
import VectorLayer from "ol/layer/Vector";
|
|
4
|
-
import { LineOptions, MapJSONData } from "../../types";
|
|
5
|
-
import { EventManager } from "../map";
|
|
6
|
-
/**
|
|
7
|
-
* 河流图层管理类
|
|
8
|
-
* 用于创建与管理河流相关矢量图层(分级显示、按级别线宽、显示控制与清理)
|
|
9
|
-
*
|
|
10
|
-
* 注意:
|
|
11
|
-
* - 分级显示依赖地图缩放级别(zoom),通过 zoomOffset 控制显示阈值偏移
|
|
12
|
-
* - removeExisting 为 true 时,会清理本管理器创建的分级河流图层
|
|
13
|
-
*/
|
|
14
|
-
export interface RiverLevelWidthMap {
|
|
15
|
-
[level: number]: number;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* 河流图层配置选项
|
|
19
|
-
*/
|
|
20
|
-
export interface RiverLayerOptions extends LineOptions {
|
|
21
|
-
/** 河流级别数量,默认为 5 */
|
|
22
|
-
levelCount?: number;
|
|
23
|
-
/** 缩放级别偏移量,默认为 8 */
|
|
24
|
-
zoomOffset?: number;
|
|
25
|
-
/** 河流级别线宽映射,key 为 level,value 为线宽 */
|
|
26
|
-
levelWidthMap?: RiverLevelWidthMap;
|
|
27
|
-
/** 是否删除已有分级河流图层(本管理器创建的) */
|
|
28
|
-
removeExisting?: boolean;
|
|
29
|
-
}
|
|
30
|
-
export default class RiverLayerManager {
|
|
31
|
-
private readonly map;
|
|
32
|
-
private readonly eventManager;
|
|
33
|
-
private riverLayerList;
|
|
34
|
-
private riverLayerShow;
|
|
35
|
-
private riverZoomOffset;
|
|
36
|
-
private readonly defaultLevelWidthMap;
|
|
37
|
-
/**
|
|
38
|
-
* 构造函数
|
|
39
|
-
* @param map OpenLayers 地图实例
|
|
40
|
-
* @param eventManager 可选事件管理器,未传入则内部创建
|
|
41
|
-
*/
|
|
42
|
-
constructor(map: Map, eventManager?: EventManager);
|
|
43
|
-
/**
|
|
44
|
-
* 添加分级河流图层:根据缩放级别显示不同 level 的河流
|
|
45
|
-
* @param fyRiverJson 河流 GeoJSON 数据
|
|
46
|
-
* @param options 河流图层配置选项
|
|
47
|
-
*/
|
|
48
|
-
addRiverLayersByZoom(fyRiverJson: MapJSONData, options?: RiverLayerOptions): void;
|
|
49
|
-
/**
|
|
50
|
-
* 从 URL 添加分级河流图层:根据缩放级别显示不同 level 的河流
|
|
51
|
-
* @param url 河流数据 URL(GeoJSON)
|
|
52
|
-
* @param options 河流图层配置选项
|
|
53
|
-
*/
|
|
54
|
-
addRiverLayersByZoomByUrl(url: string, options?: RiverLayerOptions): void;
|
|
55
|
-
/**
|
|
56
|
-
* 设置分级河流图层是否显示
|
|
57
|
-
* @param show 是否显示
|
|
58
|
-
*/
|
|
59
|
-
showRiverLayer(show: boolean): void;
|
|
60
|
-
/**
|
|
61
|
-
* 根据当前 zoom 显示对应分级河流图层
|
|
62
|
-
* 缩放越大,显示的 riverLevel 越多
|
|
63
|
-
*/
|
|
64
|
-
showRiverLayerByZoom(): void;
|
|
65
|
-
/**
|
|
66
|
-
* 添加按级别显示不同宽度的河流图层
|
|
67
|
-
* @param data 河流 GeoJSON 数据
|
|
68
|
-
* @param options 河流图层配置选项
|
|
69
|
-
*/
|
|
70
|
-
addRiverWidthByLevel(data: MapJSONData, options?: RiverLayerOptions): VectorLayer<VectorSource>;
|
|
71
|
-
/**
|
|
72
|
-
* 从 URL 添加按级别显示不同宽度的河流图层
|
|
73
|
-
* @param url 河流数据 URL(GeoJSON)
|
|
74
|
-
* @param options 河流图层配置选项
|
|
75
|
-
*/
|
|
76
|
-
addRiverWidthByLevelByUrl(url: string, options?: RiverLayerOptions): VectorLayer<VectorSource>;
|
|
77
|
-
/**
|
|
78
|
-
* 清除本管理器创建的分级河流图层
|
|
79
|
-
*/
|
|
80
|
-
clearRiverLayers(): void;
|
|
81
|
-
/**
|
|
82
|
-
* 获取分级河流图层显示状态
|
|
83
|
-
*/
|
|
84
|
-
getRiverLayerVisibility(): boolean;
|
|
85
|
-
/**
|
|
86
|
-
* 获取分级河流图层列表副本
|
|
87
|
-
*/
|
|
88
|
-
getRiverLayers(): VectorLayer<VectorSource>[];
|
|
89
|
-
/**
|
|
90
|
-
* 销毁管理器,释放资源
|
|
91
|
-
*/
|
|
92
|
-
destroy(): void;
|
|
93
|
-
}
|
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
import VectorSource from "ol/source/Vector";
|
|
2
|
-
import GeoJSON from "ol/format/GeoJSON";
|
|
3
|
-
import VectorLayer from "ol/layer/Vector";
|
|
4
|
-
import { Stroke, Style } from "ol/style";
|
|
5
|
-
import { Feature } from "ol";
|
|
6
|
-
import ValidationUtils from "../../utils/ValidationUtils";
|
|
7
|
-
import { ErrorHandler } from "../../utils/ErrorHandler";
|
|
8
|
-
import { ConfigManager, EventManager, MapTools } from "../map";
|
|
9
|
-
export default class RiverLayerManager {
|
|
10
|
-
/**
|
|
11
|
-
* 构造函数
|
|
12
|
-
* @param map OpenLayers 地图实例
|
|
13
|
-
* @param eventManager 可选事件管理器,未传入则内部创建
|
|
14
|
-
*/
|
|
15
|
-
constructor(map, eventManager) {
|
|
16
|
-
//************* 状态:分级河流图层列表与显示控制 *************
|
|
17
|
-
this.riverLayerList = [];
|
|
18
|
-
this.riverLayerShow = false;
|
|
19
|
-
this.riverZoomOffset = 8;
|
|
20
|
-
//************* 默认配置:按 level 映射线宽 *************
|
|
21
|
-
this.defaultLevelWidthMap = ConfigManager.DEFAULT_RIVER_LEVEL_WIDTH_MAP;
|
|
22
|
-
ValidationUtils.validateMapInstance(map);
|
|
23
|
-
this.map = map;
|
|
24
|
-
this.eventManager = eventManager ?? new EventManager(map);
|
|
25
|
-
}
|
|
26
|
-
addRiverLayersByZoom(fyRiverJson, options = {}) {
|
|
27
|
-
ValidationUtils.validateGeoJSONData(fyRiverJson);
|
|
28
|
-
const defaultOptions = {
|
|
29
|
-
...ConfigManager.DEFAULT_RIVER_LAYERS_BY_ZOOM_OPTIONS,
|
|
30
|
-
removeExisting: options.removeExisting ?? false,
|
|
31
|
-
levelWidthMap: this.defaultLevelWidthMap
|
|
32
|
-
};
|
|
33
|
-
const mergedOptions = { ...defaultOptions, ...options };
|
|
34
|
-
this.riverZoomOffset = mergedOptions.zoomOffset;
|
|
35
|
-
if (mergedOptions.removeExisting) {
|
|
36
|
-
this.clearRiverLayers();
|
|
37
|
-
}
|
|
38
|
-
this.riverLayerShow = mergedOptions.visible;
|
|
39
|
-
this.riverLayerList = [];
|
|
40
|
-
for (let level = 1; level <= mergedOptions.levelCount; level++) {
|
|
41
|
-
const vectorSource = new VectorSource({
|
|
42
|
-
format: new GeoJSON(),
|
|
43
|
-
loader: () => {
|
|
44
|
-
const geojson = new GeoJSON();
|
|
45
|
-
fyRiverJson.features.forEach((feature) => {
|
|
46
|
-
if (feature.properties && feature.properties.level === level) {
|
|
47
|
-
try {
|
|
48
|
-
const olFeature = geojson.readFeature(feature);
|
|
49
|
-
if (Array.isArray(olFeature)) {
|
|
50
|
-
vectorSource.addFeatures(olFeature);
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
vectorSource.addFeature(olFeature);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
ErrorHandler.getInstance().warn(`Failed to load river feature at level ${level}:`, error);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
const riverLayer = new VectorLayer({
|
|
64
|
-
properties: {
|
|
65
|
-
name: mergedOptions.layerName,
|
|
66
|
-
layerName: mergedOptions.layerName,
|
|
67
|
-
riverLevel: level
|
|
68
|
-
},
|
|
69
|
-
source: vectorSource,
|
|
70
|
-
style: (feature) => {
|
|
71
|
-
if (feature instanceof Feature) {
|
|
72
|
-
feature.set("type", mergedOptions.layerName);
|
|
73
|
-
feature.set("layerName", mergedOptions.layerName);
|
|
74
|
-
}
|
|
75
|
-
if (mergedOptions.style) {
|
|
76
|
-
if (typeof mergedOptions.style === "function") {
|
|
77
|
-
return mergedOptions.style(feature);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
return mergedOptions.style;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return new Style({
|
|
84
|
-
stroke: new Stroke({
|
|
85
|
-
color: mergedOptions.strokeColor,
|
|
86
|
-
width: mergedOptions.strokeWidth
|
|
87
|
-
})
|
|
88
|
-
});
|
|
89
|
-
},
|
|
90
|
-
zIndex: mergedOptions.zIndex
|
|
91
|
-
});
|
|
92
|
-
riverLayer.setVisible(false);
|
|
93
|
-
this.riverLayerList.push(riverLayer);
|
|
94
|
-
this.map.addLayer(riverLayer);
|
|
95
|
-
}
|
|
96
|
-
this.eventManager.on("moveend", () => {
|
|
97
|
-
this.showRiverLayerByZoom();
|
|
98
|
-
});
|
|
99
|
-
this.showRiverLayerByZoom();
|
|
100
|
-
}
|
|
101
|
-
//************* 分级河流:按缩放级别显示(URL 加载) *************
|
|
102
|
-
/**
|
|
103
|
-
* 从 URL 添加分级河流图层:根据缩放级别显示不同 level 的河流
|
|
104
|
-
* @param url 河流数据 URL(GeoJSON)
|
|
105
|
-
* @param options 河流图层配置选项
|
|
106
|
-
*/
|
|
107
|
-
addRiverLayersByZoomByUrl(url, options = {}) {
|
|
108
|
-
const defaultOptions = {
|
|
109
|
-
...ConfigManager.DEFAULT_RIVER_LAYERS_BY_ZOOM_OPTIONS,
|
|
110
|
-
removeExisting: options.removeExisting ?? false,
|
|
111
|
-
levelWidthMap: this.defaultLevelWidthMap
|
|
112
|
-
};
|
|
113
|
-
const mergedOptions = { ...defaultOptions, ...options };
|
|
114
|
-
this.riverZoomOffset = mergedOptions.zoomOffset;
|
|
115
|
-
if (mergedOptions.removeExisting) {
|
|
116
|
-
this.clearRiverLayers();
|
|
117
|
-
}
|
|
118
|
-
this.riverLayerShow = mergedOptions.visible;
|
|
119
|
-
this.riverLayerList = [];
|
|
120
|
-
for (let level = 1; level <= mergedOptions.levelCount; level++) {
|
|
121
|
-
const vectorSource = new VectorSource({
|
|
122
|
-
url,
|
|
123
|
-
format: new GeoJSON(),
|
|
124
|
-
loader: function (extent, resolution, projection, success, failure) {
|
|
125
|
-
fetch(url)
|
|
126
|
-
.then(response => response.json())
|
|
127
|
-
.then(data => {
|
|
128
|
-
const geojson = new GeoJSON();
|
|
129
|
-
data.features.forEach((feature) => {
|
|
130
|
-
if (feature.properties && feature.properties.level === level) {
|
|
131
|
-
try {
|
|
132
|
-
const olFeature = geojson.readFeature(feature);
|
|
133
|
-
if (Array.isArray(olFeature)) {
|
|
134
|
-
vectorSource.addFeatures(olFeature);
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
vectorSource.addFeature(olFeature);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
catch (error) {
|
|
141
|
-
ErrorHandler.getInstance().warn(`Failed to load river feature at level ${level}:`, error);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
success?.(vectorSource.getFeatures());
|
|
146
|
-
})
|
|
147
|
-
.catch(error => {
|
|
148
|
-
ErrorHandler.getInstance().error("Error loading river data:", error);
|
|
149
|
-
failure?.();
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
const riverLayer = new VectorLayer({
|
|
154
|
-
properties: {
|
|
155
|
-
name: mergedOptions.layerName,
|
|
156
|
-
layerName: mergedOptions.layerName,
|
|
157
|
-
riverLevel: level
|
|
158
|
-
},
|
|
159
|
-
source: vectorSource,
|
|
160
|
-
style: (feature) => {
|
|
161
|
-
if (feature instanceof Feature) {
|
|
162
|
-
feature.set("type", mergedOptions.layerName);
|
|
163
|
-
feature.set("layerName", mergedOptions.layerName);
|
|
164
|
-
}
|
|
165
|
-
if (mergedOptions.style) {
|
|
166
|
-
if (typeof mergedOptions.style === "function") {
|
|
167
|
-
return mergedOptions.style(feature);
|
|
168
|
-
}
|
|
169
|
-
else {
|
|
170
|
-
return mergedOptions.style;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return new Style({
|
|
174
|
-
stroke: new Stroke({
|
|
175
|
-
color: mergedOptions.strokeColor,
|
|
176
|
-
width: mergedOptions.strokeWidth
|
|
177
|
-
})
|
|
178
|
-
});
|
|
179
|
-
},
|
|
180
|
-
zIndex: mergedOptions.zIndex
|
|
181
|
-
});
|
|
182
|
-
riverLayer.setVisible(false);
|
|
183
|
-
this.riverLayerList.push(riverLayer);
|
|
184
|
-
this.map.addLayer(riverLayer);
|
|
185
|
-
}
|
|
186
|
-
this.eventManager.on("moveend", () => {
|
|
187
|
-
this.showRiverLayerByZoom();
|
|
188
|
-
});
|
|
189
|
-
this.showRiverLayerByZoom();
|
|
190
|
-
}
|
|
191
|
-
//************* 分级河流:显示控制 *************
|
|
192
|
-
/**
|
|
193
|
-
* 设置分级河流图层是否显示
|
|
194
|
-
* @param show 是否显示
|
|
195
|
-
*/
|
|
196
|
-
showRiverLayer(show) {
|
|
197
|
-
this.riverLayerShow = show;
|
|
198
|
-
this.showRiverLayerByZoom();
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* 根据当前 zoom 显示对应分级河流图层
|
|
202
|
-
* 缩放越大,显示的 riverLevel 越多
|
|
203
|
-
*/
|
|
204
|
-
showRiverLayerByZoom() {
|
|
205
|
-
const zoom = this.map.getView().getZoom();
|
|
206
|
-
if (!zoom) {
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
this.riverLayerList.forEach((layer, index) => {
|
|
210
|
-
const displayThreshold = index + 1 + this.riverZoomOffset;
|
|
211
|
-
if (zoom > displayThreshold) {
|
|
212
|
-
layer.setVisible(this.riverLayerShow);
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
layer.setVisible(false);
|
|
216
|
-
}
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
addRiverWidthByLevel(data, options = {}) {
|
|
220
|
-
ValidationUtils.validateGeoJSONData(data);
|
|
221
|
-
const mergedOptions = {
|
|
222
|
-
...ConfigManager.DEFAULT_RIVER_WIDTH_BY_LEVEL_OPTIONS,
|
|
223
|
-
...options,
|
|
224
|
-
removeExisting: options.removeExisting ?? ConfigManager.DEFAULT_RIVER_WIDTH_BY_LEVEL_OPTIONS.removeExisting,
|
|
225
|
-
levelWidthMap: options.levelWidthMap ?? this.defaultLevelWidthMap,
|
|
226
|
-
};
|
|
227
|
-
if (mergedOptions.removeExisting && mergedOptions.layerName) {
|
|
228
|
-
MapTools.removeLayer(this.map, mergedOptions.layerName);
|
|
229
|
-
}
|
|
230
|
-
const features = new GeoJSON().readFeatures(data, mergedOptions.projectionOptOptions);
|
|
231
|
-
const riverLayer = new VectorLayer({
|
|
232
|
-
properties: {
|
|
233
|
-
name: mergedOptions.layerName,
|
|
234
|
-
layerName: mergedOptions.layerName
|
|
235
|
-
},
|
|
236
|
-
source: new VectorSource({ features }),
|
|
237
|
-
style: (feature) => {
|
|
238
|
-
if (mergedOptions.style) {
|
|
239
|
-
if (typeof mergedOptions.style === "function") {
|
|
240
|
-
return mergedOptions.style(feature);
|
|
241
|
-
}
|
|
242
|
-
else {
|
|
243
|
-
return mergedOptions.style;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
const level = feature.get("level");
|
|
247
|
-
const levelWidth = mergedOptions.levelWidthMap[Number(level)] || 1;
|
|
248
|
-
return new Style({
|
|
249
|
-
stroke: new Stroke({
|
|
250
|
-
color: mergedOptions.strokeColor,
|
|
251
|
-
width: levelWidth
|
|
252
|
-
})
|
|
253
|
-
});
|
|
254
|
-
},
|
|
255
|
-
zIndex: mergedOptions.zIndex
|
|
256
|
-
});
|
|
257
|
-
riverLayer.setVisible(mergedOptions.visible);
|
|
258
|
-
this.map.addLayer(riverLayer);
|
|
259
|
-
return riverLayer;
|
|
260
|
-
}
|
|
261
|
-
//************* 河流线宽:按 level 设置不同宽度(URL 加载) *************
|
|
262
|
-
/**
|
|
263
|
-
* 从 URL 添加按级别显示不同宽度的河流图层
|
|
264
|
-
* @param url 河流数据 URL(GeoJSON)
|
|
265
|
-
* @param options 河流图层配置选项
|
|
266
|
-
*/
|
|
267
|
-
addRiverWidthByLevelByUrl(url, options = {}) {
|
|
268
|
-
const mergedOptions = {
|
|
269
|
-
...ConfigManager.DEFAULT_RIVER_WIDTH_BY_LEVEL_OPTIONS,
|
|
270
|
-
...options,
|
|
271
|
-
removeExisting: options.removeExisting ?? ConfigManager.DEFAULT_RIVER_WIDTH_BY_LEVEL_OPTIONS.removeExisting,
|
|
272
|
-
levelWidthMap: options.levelWidthMap ?? this.defaultLevelWidthMap,
|
|
273
|
-
};
|
|
274
|
-
if (mergedOptions.removeExisting && mergedOptions.layerName) {
|
|
275
|
-
MapTools.removeLayer(this.map, mergedOptions.layerName);
|
|
276
|
-
}
|
|
277
|
-
const source = new VectorSource({
|
|
278
|
-
url,
|
|
279
|
-
format: new GeoJSON(options.projectionOptOptions)
|
|
280
|
-
});
|
|
281
|
-
const riverLayer = new VectorLayer({
|
|
282
|
-
properties: {
|
|
283
|
-
name: mergedOptions.layerName,
|
|
284
|
-
layerName: mergedOptions.layerName
|
|
285
|
-
},
|
|
286
|
-
source,
|
|
287
|
-
style: (feature) => {
|
|
288
|
-
if (mergedOptions.style) {
|
|
289
|
-
if (typeof mergedOptions.style === "function") {
|
|
290
|
-
return mergedOptions.style(feature);
|
|
291
|
-
}
|
|
292
|
-
else {
|
|
293
|
-
return mergedOptions.style;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
const level = feature.get("level");
|
|
297
|
-
const levelWidth = mergedOptions.levelWidthMap[Number(level)] || 1;
|
|
298
|
-
return new Style({
|
|
299
|
-
stroke: new Stroke({
|
|
300
|
-
color: mergedOptions.strokeColor,
|
|
301
|
-
width: levelWidth
|
|
302
|
-
})
|
|
303
|
-
});
|
|
304
|
-
},
|
|
305
|
-
zIndex: mergedOptions.zIndex
|
|
306
|
-
});
|
|
307
|
-
riverLayer.setVisible(mergedOptions.visible);
|
|
308
|
-
this.map.addLayer(riverLayer);
|
|
309
|
-
return riverLayer;
|
|
310
|
-
}
|
|
311
|
-
//************* 清理与状态查询 *************
|
|
312
|
-
/**
|
|
313
|
-
* 清除本管理器创建的分级河流图层
|
|
314
|
-
*/
|
|
315
|
-
clearRiverLayers() {
|
|
316
|
-
this.riverLayerList.forEach(layer => {
|
|
317
|
-
this.map.removeLayer(layer);
|
|
318
|
-
});
|
|
319
|
-
this.riverLayerList = [];
|
|
320
|
-
this.riverLayerShow = false;
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* 获取分级河流图层显示状态
|
|
324
|
-
*/
|
|
325
|
-
getRiverLayerVisibility() {
|
|
326
|
-
return this.riverLayerShow;
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* 获取分级河流图层列表副本
|
|
330
|
-
*/
|
|
331
|
-
getRiverLayers() {
|
|
332
|
-
return [...this.riverLayerList];
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* 销毁管理器,释放资源
|
|
336
|
-
*/
|
|
337
|
-
destroy() {
|
|
338
|
-
this.clearRiverLayers();
|
|
339
|
-
}
|
|
340
|
-
}
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
# RiverLayerManager 河流图层管理类
|
|
2
|
-
|
|
3
|
-
`RiverLayerManager` 专门用于处理河流数据的分级显示和样式管理。它支持基于地图缩放级别(Zoom-based)的动态分级显示,以及基于河流属性等级(Level-based)的固定线宽渲染。
|
|
4
|
-
|
|
5
|
-
## 构造函数
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
constructor(map: Map, eventManager?: EventManager)
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
- **参数**:
|
|
12
|
-
- `map` (Map): OpenLayers 地图实例。
|
|
13
|
-
- `eventManager` (EventManager): 可选。事件管理器实例,如果未提供则内部创建。
|
|
14
|
-
|
|
15
|
-
## 接口定义
|
|
16
|
-
|
|
17
|
-
### RiverLayerOptions
|
|
18
|
-
|
|
19
|
-
河流图层配置选项,继承自 `LineOptions`。
|
|
20
|
-
|
|
21
|
-
| 属性 | 类型 | 必填 | 默认值 | 描述 |
|
|
22
|
-
| :--- | :--- | :--- | :--- | :--- |
|
|
23
|
-
| levelCount | `number` | 否 | `5` | 河流等级总数。用于分级显示循环加载。 |
|
|
24
|
-
| zoomOffset | `number` | 否 | `8` | 缩放级别偏移量。控制何时显示哪一级河流 (Zoom > Level + Offset)。 |
|
|
25
|
-
| levelWidthMap | `RiverLevelWidthMap` | 否 | 默认映射 | 河流级别与线宽的映射对象。 |
|
|
26
|
-
| removeExisting | `boolean` | 否 | `false` | 添加前是否删除由本管理器创建的旧图层。 |
|
|
27
|
-
| layerName | `string` | 否 | - | 图层名称,用于标识和清理。 |
|
|
28
|
-
| visible | `boolean` | 否 | `true` | 初始可见性。 |
|
|
29
|
-
| strokeColor | `string` | 否 | - | 线条颜色。 |
|
|
30
|
-
| strokeWidth | `number` | 否 | - | 基础线宽(如果未使用 levelWidthMap)。 |
|
|
31
|
-
| zIndex | `number` | 否 | - | 图层 Z-Index。 |
|
|
32
|
-
| projectionOptOptions | `any` | 否 | - | GeoJSON 读取时的投影选项。 |
|
|
33
|
-
|
|
34
|
-
### RiverLevelWidthMap
|
|
35
|
-
|
|
36
|
-
河流级别线宽映射接口。
|
|
37
|
-
|
|
38
|
-
```typescript
|
|
39
|
-
interface RiverLevelWidthMap {
|
|
40
|
-
[level: number]: number;
|
|
41
|
-
}
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
默认映射 (`ConfigManager.DEFAULT_RIVER_LEVEL_WIDTH_MAP`) 通常为 `{1: 5, 2: 4, 3: 3, 4: 2, 5: 1}` 等类似结构。
|
|
45
|
-
|
|
46
|
-
## 方法
|
|
47
|
-
|
|
48
|
-
### 分级显示 (Zoom-based)
|
|
49
|
-
|
|
50
|
-
根据地图缩放级别自动显示不同等级的河流。通常用于实现“缩放越大约详细”的效果。
|
|
51
|
-
|
|
52
|
-
#### addRiverLayersByZoom
|
|
53
|
-
|
|
54
|
-
直接传递 GeoJSON 数据添加分级河流图层。
|
|
55
|
-
|
|
56
|
-
```typescript
|
|
57
|
-
addRiverLayersByZoom(fyRiverJson: MapJSONData, options?: RiverLayerOptions): void
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
- **参数**:
|
|
61
|
-
- `fyRiverJson`: 河流 GeoJSON 数据对象。
|
|
62
|
-
- `options`: 配置选项。
|
|
63
|
-
|
|
64
|
-
#### addRiverLayersByZoomByUrl
|
|
65
|
-
|
|
66
|
-
通过 URL 加载 GeoJSON 数据并添加分级河流图层。
|
|
67
|
-
|
|
68
|
-
```typescript
|
|
69
|
-
addRiverLayersByZoomByUrl(url: string, options?: RiverLayerOptions): void
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
#### showRiverLayer
|
|
73
|
-
|
|
74
|
-
控制分级河流图层的总开关。
|
|
75
|
-
|
|
76
|
-
```typescript
|
|
77
|
-
showRiverLayer(show: boolean): void
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
#### showRiverLayerByZoom
|
|
81
|
-
|
|
82
|
-
手动触发根据当前缩放级别更新图层可见性(通常不需要手动调用,已绑定 `moveend` 事件)。
|
|
83
|
-
|
|
84
|
-
```typescript
|
|
85
|
-
showRiverLayerByZoom(): void
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
### 宽度分级 (Level-based Width)
|
|
89
|
-
|
|
90
|
-
根据河流数据中的 `level` 属性渲染不同宽度的线条,通常用于静态展示不同等级河流的粗细差异。
|
|
91
|
-
|
|
92
|
-
#### addRiverWidthByLevel
|
|
93
|
-
|
|
94
|
-
直接传递 GeoJSON 数据添加按等级设定宽度的河流。
|
|
95
|
-
|
|
96
|
-
```typescript
|
|
97
|
-
addRiverWidthByLevel(data: MapJSONData, options?: RiverLayerOptions): VectorLayer<VectorSource>
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
- **返回值**: 创建的矢量图层。
|
|
101
|
-
|
|
102
|
-
#### addRiverWidthByLevelByUrl
|
|
103
|
-
|
|
104
|
-
通过 URL 加载 GeoJSON 数据并添加按等级设定宽度的河流。
|
|
105
|
-
|
|
106
|
-
```typescript
|
|
107
|
-
addRiverWidthByLevelByUrl(url: string, options?: RiverLayerOptions): VectorLayer<VectorSource>
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
### 管理与清理
|
|
111
|
-
|
|
112
|
-
#### clearRiverLayers
|
|
113
|
-
|
|
114
|
-
清除所有由该管理器创建的分级河流图层。
|
|
115
|
-
|
|
116
|
-
```typescript
|
|
117
|
-
clearRiverLayers(): void
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
#### getRiverLayerVisibility
|
|
121
|
-
|
|
122
|
-
获取当前分级河流图层的总显示状态。
|
|
123
|
-
|
|
124
|
-
```typescript
|
|
125
|
-
getRiverLayerVisibility(): boolean
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
#### getRiverLayers
|
|
129
|
-
|
|
130
|
-
获取当前管理的所有分级河流图层列表。
|
|
131
|
-
|
|
132
|
-
```typescript
|
|
133
|
-
getRiverLayers(): VectorLayer<VectorSource>[]
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
#### destroy
|
|
137
|
-
|
|
138
|
-
销毁管理器,清理所有图层和事件监听。
|
|
139
|
-
|
|
140
|
-
```typescript
|
|
141
|
-
destroy(): void
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
## 使用示例
|
|
145
|
-
|
|
146
|
-
```typescript
|
|
147
|
-
import { MyOl, RiverLayerManager } from 'my-openlayer';
|
|
148
|
-
|
|
149
|
-
const map = new MyOl('map-container');
|
|
150
|
-
const riverManager = new RiverLayerManager(map.map);
|
|
151
|
-
|
|
152
|
-
// 假设 riverGeoJSON 数据中每个 feature 都有 properties.level (1-5)
|
|
153
|
-
|
|
154
|
-
// 示例 1: 添加分级河流(随地图缩放自动显隐不同级别的河流)
|
|
155
|
-
// Level 1 在 Zoom > 9 (1+8) 显示
|
|
156
|
-
// Level 2 在 Zoom > 10 (2+8) 显示
|
|
157
|
-
// ...
|
|
158
|
-
riverManager.addRiverLayersByZoom(riverGeoJSON, {
|
|
159
|
-
layerName: 'dynamic-river',
|
|
160
|
-
levelCount: 5,
|
|
161
|
-
zoomOffset: 8,
|
|
162
|
-
strokeColor: '#0071FF',
|
|
163
|
-
strokeWidth: 2,
|
|
164
|
-
removeExisting: true
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
// 控制分级河流的总开关
|
|
168
|
-
riverManager.showRiverLayer(false); // 全部隐藏
|
|
169
|
-
riverManager.showRiverLayer(true); // 恢复并根据当前 Zoom 显示对应级别
|
|
170
|
-
|
|
171
|
-
// 示例 2: 添加静态河流,根据等级显示不同粗细
|
|
172
|
-
riverManager.addRiverWidthByLevel(riverGeoJSON, {
|
|
173
|
-
layerName: 'static-river',
|
|
174
|
-
strokeColor: '#0071FF',
|
|
175
|
-
levelWidthMap: {
|
|
176
|
-
1: 6, // 1级河流宽 6px
|
|
177
|
-
2: 5,
|
|
178
|
-
3: 4,
|
|
179
|
-
4: 3,
|
|
180
|
-
5: 1
|
|
181
|
-
},
|
|
182
|
-
zIndex: 10
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
// 清理资源
|
|
186
|
-
// riverManager.destroy();
|
|
187
|
-
```
|