my-openlayer 2.5.4 → 3.0.1
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/CHANGELOG.md +68 -0
- package/MyOl.d.ts +3 -22
- package/MyOl.js +52 -112
- package/README.md +116 -29
- package/core/line/Line.d.ts +24 -5
- package/core/line/Line.js +38 -10
- package/core/map/ConfigManager.d.ts +169 -89
- package/core/map/ConfigManager.js +157 -175
- package/core/map/MapBaseLayers.d.ts +6 -0
- package/core/map/MapBaseLayers.js +9 -0
- package/core/map/MapTools.d.ts +17 -1
- package/core/map/MapTools.js +39 -5
- package/core/point/Point.d.ts +54 -14
- package/core/point/Point.js +132 -76
- package/core/point/PointOverlay.d.ts +2 -4
- package/core/point/PointOverlay.js +2 -1
- package/core/point/PointPulseLayer.js +6 -4
- package/core/polygon/Polygon.d.ts +32 -17
- package/core/polygon/Polygon.js +87 -64
- package/core/polygon/PolygonHeatmapLayer.js +15 -2
- package/core/polygon/PolygonMaskLayer.d.ts +2 -2
- package/core/polygon/PolygonMaskLayer.js +3 -1
- package/core/polygon/PolygonStyleFactory.d.ts +4 -3
- package/core/projection/ProjectionManager.d.ts +66 -0
- package/core/projection/ProjectionManager.js +144 -0
- package/core/projection/index.d.ts +2 -0
- package/core/projection/index.js +1 -0
- package/core/select/SelectHandler.d.ts +1 -1
- package/core/vue-template-point/VueTemplatePoint.d.ts +2 -4
- package/core/vue-template-point/VueTemplatePoint.js +16 -2
- package/docs/.vitepress/config.mts +1 -0
- package/docs/Line.md +4 -4
- package/docs/MIGRATION-3.0.md +221 -0
- package/docs/Point.md +24 -6
- package/docs/Polygon.md +14 -5
- package/index.d.ts +6 -3
- package/index.js +4 -1
- package/package.json +6 -3
- package/types/base.d.ts +4 -4
- package/types/common.d.ts +8 -6
- package/types/handle.d.ts +34 -0
- package/types/handle.js +1 -0
- package/types/index.d.ts +1 -0
- package/types/line.d.ts +3 -2
- package/types/map.d.ts +1 -1
- package/types/point.d.ts +11 -3
- package/utils/ErrorHandler.d.ts +12 -0
- package/utils/ErrorHandler.js +21 -0
package/core/line/Line.js
CHANGED
|
@@ -61,6 +61,15 @@ export default class Line {
|
|
|
61
61
|
this.map.addLayer(layer);
|
|
62
62
|
return layer;
|
|
63
63
|
}
|
|
64
|
+
/** *********************统一句柄:静态线图层*********************/
|
|
65
|
+
toLayerHandle(layer) {
|
|
66
|
+
const map = this.map;
|
|
67
|
+
return {
|
|
68
|
+
layer,
|
|
69
|
+
setVisible(visible) { layer.setVisible(visible); },
|
|
70
|
+
remove() { map.removeLayer(layer); }
|
|
71
|
+
};
|
|
72
|
+
}
|
|
64
73
|
/**
|
|
65
74
|
* 注册流动线句柄。
|
|
66
75
|
*/
|
|
@@ -73,26 +82,32 @@ export default class Line {
|
|
|
73
82
|
unregisterFlowLineHandle(layerName) {
|
|
74
83
|
this.flowLineRegistry.delete(layerName);
|
|
75
84
|
}
|
|
76
|
-
|
|
85
|
+
/** *********************创建静态线图层*********************/
|
|
86
|
+
createLineLayer(data, options) {
|
|
77
87
|
ValidationUtils.validateRequired(data, 'GeoJSON data is required');
|
|
78
88
|
const mergedOptions = this.mergeDefaultOptions(options);
|
|
79
89
|
const features = new GeoJSON().readFeatures(data, ProjectionUtils.getGeoJSONReadOptions(mergedOptions));
|
|
80
90
|
return this.createStaticLayer(new VectorSource({ features }), mergedOptions);
|
|
81
91
|
}
|
|
82
|
-
|
|
92
|
+
/** *********************添加静态线图层*********************/
|
|
93
|
+
addLine(data, options) {
|
|
94
|
+
return this.toLayerHandle(this.createLineLayer(data, options));
|
|
95
|
+
}
|
|
96
|
+
/** *********************从 URL 添加静态线图层*********************/
|
|
97
|
+
async addLineByUrl(url, options) {
|
|
83
98
|
ValidationUtils.validateNonEmptyString(url, 'Line url is required');
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return this.
|
|
99
|
+
const response = await fetch(url);
|
|
100
|
+
if (!response.ok) {
|
|
101
|
+
throw new Error(`Failed to fetch line GeoJSON: ${response.status}`);
|
|
102
|
+
}
|
|
103
|
+
const json = await response.json();
|
|
104
|
+
return this.addLine(json, options);
|
|
90
105
|
}
|
|
91
106
|
removeLineLayer(layerName) {
|
|
92
107
|
ValidationUtils.validateLayerName(layerName);
|
|
93
108
|
MapTools.removeLayer(this.map, layerName);
|
|
94
109
|
}
|
|
95
|
-
addFlowLine(data, options
|
|
110
|
+
addFlowLine(data, options) {
|
|
96
111
|
const mergedOptions = this.mergeFlowLineOptions(options);
|
|
97
112
|
const layerName = mergedOptions.layerName;
|
|
98
113
|
try {
|
|
@@ -113,7 +128,7 @@ export default class Line {
|
|
|
113
128
|
return null;
|
|
114
129
|
}
|
|
115
130
|
}
|
|
116
|
-
async addFlowLineByUrl(url, options
|
|
131
|
+
async addFlowLineByUrl(url, options) {
|
|
117
132
|
const mergedOptions = this.mergeFlowLineOptions(options);
|
|
118
133
|
try {
|
|
119
134
|
ValidationUtils.validateNonEmptyString(url, 'Flow line url is required');
|
|
@@ -141,4 +156,17 @@ export default class Line {
|
|
|
141
156
|
}
|
|
142
157
|
MapTools.removeLayer(this.map, [layerName, `${layerName}__flow-animation`]);
|
|
143
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* 销毁本实例创建的所有流动线动画。供 MyOl.destroy 调用,
|
|
161
|
+
* 确保地图销毁后所有 requestAnimationFrame / postrender 监听被回收。
|
|
162
|
+
*/
|
|
163
|
+
destroyAllFlowLines() {
|
|
164
|
+
Array.from(this.flowLineRegistry.values()).forEach(handle => {
|
|
165
|
+
try {
|
|
166
|
+
handle.remove();
|
|
167
|
+
}
|
|
168
|
+
catch { /* ignore */ }
|
|
169
|
+
});
|
|
170
|
+
this.flowLineRegistry.clear();
|
|
171
|
+
}
|
|
144
172
|
}
|
|
@@ -1,36 +1,160 @@
|
|
|
1
|
+
import type { Positioning } from "ol/Overlay";
|
|
2
|
+
/**
|
|
3
|
+
* P2-1:内部默认配置存储与 setDefaults 覆盖机制。
|
|
4
|
+
*
|
|
5
|
+
* 设计要点:
|
|
6
|
+
* - 每组默认值都通过 getter 暴露,运行时 setDefaults 可叠加 partial 覆盖
|
|
7
|
+
* - 旧 callsite 直接 spread `ConfigManager.DEFAULT_X` 不需要改一行代码
|
|
8
|
+
* - 嵌套对象(如 flowSymbol)做深合并
|
|
9
|
+
*/
|
|
10
|
+
interface DefaultsRegistry {
|
|
11
|
+
POINT_OPTIONS: {
|
|
12
|
+
visible: boolean;
|
|
13
|
+
zIndex: number;
|
|
14
|
+
};
|
|
15
|
+
POINT_TEXT_OPTIONS: {
|
|
16
|
+
textFont: string;
|
|
17
|
+
textFillColor: string;
|
|
18
|
+
textStrokeColor: string;
|
|
19
|
+
textStrokeWidth: number;
|
|
20
|
+
textOffsetY: number;
|
|
21
|
+
};
|
|
22
|
+
POINT_ICON_SCALE: number;
|
|
23
|
+
CLUSTER_OPTIONS: {
|
|
24
|
+
distance: number;
|
|
25
|
+
minDistance: number;
|
|
26
|
+
zIndex: number;
|
|
27
|
+
};
|
|
28
|
+
DOM_POINT_OVERLAY_OPTIONS: {
|
|
29
|
+
positioning: Positioning;
|
|
30
|
+
stopEvent: boolean;
|
|
31
|
+
};
|
|
32
|
+
LINE_OPTIONS: {
|
|
33
|
+
type: string;
|
|
34
|
+
strokeColor: string;
|
|
35
|
+
strokeWidth: number;
|
|
36
|
+
visible: boolean;
|
|
37
|
+
layerName: string;
|
|
38
|
+
zIndex: number;
|
|
39
|
+
};
|
|
40
|
+
FLOW_LINE_OPTIONS: any;
|
|
41
|
+
POLYGON_OPTIONS: {
|
|
42
|
+
zIndex: number;
|
|
43
|
+
visible: boolean;
|
|
44
|
+
textFont: string;
|
|
45
|
+
textFillColor: string;
|
|
46
|
+
textStrokeColor: string;
|
|
47
|
+
textStrokeWidth: number;
|
|
48
|
+
};
|
|
49
|
+
POLYGON_COLOR_MAP: Record<string, string>;
|
|
50
|
+
IMAGE_OPTIONS: {
|
|
51
|
+
opacity: number;
|
|
52
|
+
visible: boolean;
|
|
53
|
+
layerName: string;
|
|
54
|
+
zIndex: number;
|
|
55
|
+
};
|
|
56
|
+
MASK_OPTIONS: {
|
|
57
|
+
fillColor: string;
|
|
58
|
+
opacity: number;
|
|
59
|
+
visible: boolean;
|
|
60
|
+
layerName: string;
|
|
61
|
+
zIndex: number;
|
|
62
|
+
};
|
|
63
|
+
TEXT_OPTIONS: {
|
|
64
|
+
textFont: string;
|
|
65
|
+
textFillColor: string;
|
|
66
|
+
textStrokeColor: string;
|
|
67
|
+
textStrokeWidth: number;
|
|
68
|
+
};
|
|
69
|
+
HEATMAP_OPTIONS: {
|
|
70
|
+
blur: number;
|
|
71
|
+
radius: number;
|
|
72
|
+
zIndex: number;
|
|
73
|
+
opacity: number;
|
|
74
|
+
};
|
|
75
|
+
HEATMAP_VALUE_KEY: string;
|
|
76
|
+
TIANDITU_CONFIG: {
|
|
77
|
+
BASE_URL: string;
|
|
78
|
+
PROJECTION: string;
|
|
79
|
+
DEFAULT_ZINDEX: number;
|
|
80
|
+
ANNOTATION_ZINDEX_OFFSET: number;
|
|
81
|
+
};
|
|
82
|
+
MAP_LAYERS_OPTIONS: {
|
|
83
|
+
zIndex: number;
|
|
84
|
+
annotation: boolean;
|
|
85
|
+
mapClip: boolean;
|
|
86
|
+
mapClipData: any;
|
|
87
|
+
};
|
|
88
|
+
MYOL_OPTIONS: {
|
|
89
|
+
layers: any;
|
|
90
|
+
zoom: number;
|
|
91
|
+
center: number[];
|
|
92
|
+
extent: any;
|
|
93
|
+
};
|
|
94
|
+
VUE_TEMPLATE_POINT_OPTIONS: {
|
|
95
|
+
positioning: Positioning;
|
|
96
|
+
stopEvent: boolean;
|
|
97
|
+
visible: boolean;
|
|
98
|
+
zIndex: number;
|
|
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
|
+
}
|
|
1
122
|
/**
|
|
2
123
|
* 配置管理类
|
|
3
124
|
* 用于统一管理默认配置和验证
|
|
125
|
+
*
|
|
126
|
+
* 运行时修改默认值:调用 ConfigManager.setDefaults('LINE_OPTIONS', { strokeWidth: 4 })
|
|
127
|
+
* 之后所有新创建的 Line/FlowLine 都将以此为默认。
|
|
4
128
|
*/
|
|
5
129
|
export default class ConfigManager {
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
static
|
|
130
|
+
/** 运行时覆盖默认配置。partial 会与现有 default 做深合并,未提到的键保持原值。 */
|
|
131
|
+
static setDefaults<K extends keyof DefaultsRegistry>(group: K, partial: Partial<DefaultsRegistry[K]>): void;
|
|
132
|
+
/** 取当前运行时 default(含 setDefaults 覆盖后的结果),返回深拷贝避免被外部修改。 */
|
|
133
|
+
static getDefaults<K extends keyof DefaultsRegistry>(group: K): DefaultsRegistry[K];
|
|
134
|
+
/** 把所有 setDefaults 覆盖清掉,恢复到内置默认值。 */
|
|
135
|
+
static resetDefaults(group?: keyof DefaultsRegistry): void;
|
|
136
|
+
static get DEFAULT_POINT_OPTIONS(): {
|
|
10
137
|
visible: boolean;
|
|
11
138
|
zIndex: number;
|
|
12
139
|
};
|
|
13
|
-
static
|
|
140
|
+
static get DEFAULT_POINT_TEXT_OPTIONS(): {
|
|
14
141
|
textFont: string;
|
|
15
142
|
textFillColor: string;
|
|
16
143
|
textStrokeColor: string;
|
|
17
144
|
textStrokeWidth: number;
|
|
18
145
|
textOffsetY: number;
|
|
19
146
|
};
|
|
20
|
-
static
|
|
21
|
-
static
|
|
147
|
+
static get DEFAULT_POINT_ICON_SCALE(): number;
|
|
148
|
+
static get DEFAULT_CLUSTER_OPTIONS(): {
|
|
22
149
|
distance: number;
|
|
23
150
|
minDistance: number;
|
|
24
151
|
zIndex: number;
|
|
25
152
|
};
|
|
26
|
-
static
|
|
27
|
-
|
|
28
|
-
|
|
153
|
+
static get DEFAULT_DOM_POINT_OVERLAY_OPTIONS(): {
|
|
154
|
+
positioning: Positioning;
|
|
155
|
+
stopEvent: boolean;
|
|
29
156
|
};
|
|
30
|
-
|
|
31
|
-
* 默认线配置
|
|
32
|
-
*/
|
|
33
|
-
static readonly DEFAULT_LINE_OPTIONS: {
|
|
157
|
+
static get DEFAULT_LINE_OPTIONS(): {
|
|
34
158
|
type: string;
|
|
35
159
|
strokeColor: string;
|
|
36
160
|
strokeWidth: number;
|
|
@@ -38,34 +162,8 @@ export default class ConfigManager {
|
|
|
38
162
|
layerName: string;
|
|
39
163
|
zIndex: number;
|
|
40
164
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
*/
|
|
44
|
-
static readonly DEFAULT_FLOW_LINE_OPTIONS: {
|
|
45
|
-
readonly duration: 4000;
|
|
46
|
-
readonly loop: true;
|
|
47
|
-
readonly autoStart: true;
|
|
48
|
-
readonly showBaseLine: true;
|
|
49
|
-
readonly animationMode: "icon";
|
|
50
|
-
readonly flowSymbol: {
|
|
51
|
-
readonly scale: 0.8;
|
|
52
|
-
readonly rotateWithView: true;
|
|
53
|
-
readonly count: 1;
|
|
54
|
-
readonly spacing: 0.15;
|
|
55
|
-
};
|
|
56
|
-
readonly trailEnabled: false;
|
|
57
|
-
readonly trailLength: 0;
|
|
58
|
-
readonly zIndex: 16;
|
|
59
|
-
readonly type: string;
|
|
60
|
-
readonly strokeColor: string;
|
|
61
|
-
readonly strokeWidth: number;
|
|
62
|
-
readonly visible: boolean;
|
|
63
|
-
readonly layerName: string;
|
|
64
|
-
};
|
|
65
|
-
/**
|
|
66
|
-
* 默认面配置
|
|
67
|
-
*/
|
|
68
|
-
static readonly DEFAULT_POLYGON_OPTIONS: {
|
|
165
|
+
static get DEFAULT_FLOW_LINE_OPTIONS(): any;
|
|
166
|
+
static get DEFAULT_POLYGON_OPTIONS(): {
|
|
69
167
|
zIndex: number;
|
|
70
168
|
visible: boolean;
|
|
71
169
|
textFont: string;
|
|
@@ -73,78 +171,59 @@ export default class ConfigManager {
|
|
|
73
171
|
textStrokeColor: string;
|
|
74
172
|
textStrokeWidth: number;
|
|
75
173
|
};
|
|
76
|
-
static
|
|
77
|
-
|
|
78
|
-
'1': string;
|
|
79
|
-
'2': string;
|
|
80
|
-
'3': string;
|
|
81
|
-
};
|
|
82
|
-
/**
|
|
83
|
-
* 默认图片图层配置
|
|
84
|
-
*/
|
|
85
|
-
static readonly DEFAULT_IMAGE_OPTIONS: {
|
|
174
|
+
static get DEFAULT_POLYGON_COLOR_MAP(): Record<string, string>;
|
|
175
|
+
static get DEFAULT_IMAGE_OPTIONS(): {
|
|
86
176
|
opacity: number;
|
|
87
177
|
visible: boolean;
|
|
88
178
|
layerName: string;
|
|
89
179
|
zIndex: number;
|
|
90
180
|
};
|
|
91
|
-
|
|
92
|
-
* 默认遮罩图层配置
|
|
93
|
-
*/
|
|
94
|
-
static readonly DEFAULT_MASK_OPTIONS: {
|
|
181
|
+
static get DEFAULT_MASK_OPTIONS(): {
|
|
95
182
|
fillColor: string;
|
|
96
183
|
opacity: number;
|
|
97
184
|
visible: boolean;
|
|
98
185
|
layerName: string;
|
|
186
|
+
zIndex: number;
|
|
99
187
|
};
|
|
100
|
-
|
|
101
|
-
* 默认文本配置
|
|
102
|
-
*/
|
|
103
|
-
static readonly DEFAULT_TEXT_OPTIONS: {
|
|
188
|
+
static get DEFAULT_TEXT_OPTIONS(): {
|
|
104
189
|
textFont: string;
|
|
105
190
|
textFillColor: string;
|
|
106
191
|
textStrokeColor: string;
|
|
107
192
|
textStrokeWidth: number;
|
|
108
193
|
};
|
|
109
|
-
static
|
|
194
|
+
static get DEFAULT_HEATMAP_OPTIONS(): {
|
|
110
195
|
blur: number;
|
|
111
196
|
radius: number;
|
|
112
197
|
zIndex: number;
|
|
113
198
|
opacity: number;
|
|
114
199
|
};
|
|
115
|
-
static
|
|
116
|
-
static
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
200
|
+
static get DEFAULT_HEATMAP_VALUE_KEY(): string;
|
|
201
|
+
static get TIANDITU_CONFIG(): {
|
|
202
|
+
BASE_URL: string;
|
|
203
|
+
PROJECTION: string;
|
|
204
|
+
DEFAULT_ZINDEX: number;
|
|
205
|
+
ANNOTATION_ZINDEX_OFFSET: number;
|
|
121
206
|
};
|
|
122
|
-
static
|
|
123
|
-
zIndex:
|
|
207
|
+
static get DEFAULT_MAP_LAYERS_OPTIONS(): {
|
|
208
|
+
zIndex: number;
|
|
124
209
|
annotation: boolean;
|
|
125
210
|
mapClip: boolean;
|
|
126
|
-
mapClipData:
|
|
211
|
+
mapClipData: any;
|
|
127
212
|
};
|
|
128
|
-
static
|
|
129
|
-
layers:
|
|
213
|
+
static get DEFAULT_MYOL_OPTIONS(): {
|
|
214
|
+
layers: any;
|
|
130
215
|
zoom: number;
|
|
131
216
|
center: number[];
|
|
132
|
-
extent:
|
|
133
|
-
};
|
|
134
|
-
static
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
};
|
|
140
|
-
static
|
|
141
|
-
|
|
142
|
-
2: number;
|
|
143
|
-
3: number;
|
|
144
|
-
4: number;
|
|
145
|
-
5: number;
|
|
146
|
-
};
|
|
147
|
-
static readonly DEFAULT_RIVER_LAYERS_BY_ZOOM_OPTIONS: {
|
|
217
|
+
extent: any;
|
|
218
|
+
};
|
|
219
|
+
static get DEFAULT_VUE_TEMPLATE_POINT_OPTIONS(): {
|
|
220
|
+
positioning: Positioning;
|
|
221
|
+
stopEvent: boolean;
|
|
222
|
+
visible: boolean;
|
|
223
|
+
zIndex: number;
|
|
224
|
+
};
|
|
225
|
+
static get DEFAULT_RIVER_LEVEL_WIDTH_MAP(): Record<number, number>;
|
|
226
|
+
static get DEFAULT_RIVER_LAYERS_BY_ZOOM_OPTIONS(): {
|
|
148
227
|
type: string;
|
|
149
228
|
levelCount: number;
|
|
150
229
|
zoomOffset: number;
|
|
@@ -155,7 +234,7 @@ export default class ConfigManager {
|
|
|
155
234
|
layerName: string;
|
|
156
235
|
removeExisting: boolean;
|
|
157
236
|
};
|
|
158
|
-
static
|
|
237
|
+
static get DEFAULT_RIVER_WIDTH_BY_LEVEL_OPTIONS(): {
|
|
159
238
|
type: string;
|
|
160
239
|
layerName: string;
|
|
161
240
|
strokeColor: string;
|
|
@@ -184,3 +263,4 @@ export default class ConfigManager {
|
|
|
184
263
|
*/
|
|
185
264
|
static deepClone<T>(obj: T): T;
|
|
186
265
|
}
|
|
266
|
+
export {};
|