my-openlayer 1.0.4 → 1.0.5
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/MyOl.d.ts +2 -9
- package/MyOl.js +17 -33
- package/core/DomPoint.d.ts +3 -10
- package/core/DomPoint.js +75 -31
- package/core/EventManager.d.ts +13 -3
- package/core/EventManager.js +77 -18
- package/core/Line.d.ts +2 -0
- package/core/Line.js +3 -1
- package/core/MapBaseLayers.d.ts +32 -2
- package/core/MapBaseLayers.js +91 -23
- package/core/MapTools.d.ts +1 -52
- package/core/MapTools.js +1 -153
- package/core/Point.d.ts +13 -10
- package/core/Point.js +16 -47
- package/core/Polygon.js +1 -1
- package/core/VueTemPoint.d.ts +163 -0
- package/core/VueTemPoint.js +432 -0
- package/core/VueTemplatePoint.d.ts +51 -0
- package/core/VueTemplatePoint.js +529 -0
- package/index.d.ts +2 -2
- package/index.js +1 -1
- package/package.json +6 -6
- package/types.d.ts +33 -13
- package/types.js +8 -8
package/core/MapBaseLayers.js
CHANGED
|
@@ -19,7 +19,7 @@ const TIANDITU_CONFIG = {
|
|
|
19
19
|
BASE_URL: '//t{0-7}.tianditu.gov.cn/DataServer',
|
|
20
20
|
PROJECTION: 'EPSG:4326',
|
|
21
21
|
DEFAULT_ZINDEX: 9,
|
|
22
|
-
ANNOTATION_ZINDEX_OFFSET:
|
|
22
|
+
ANNOTATION_ZINDEX_OFFSET: 10
|
|
23
23
|
};
|
|
24
24
|
/**
|
|
25
25
|
* 地图底图图层管理类
|
|
@@ -33,6 +33,8 @@ export default class MapBaseLayers {
|
|
|
33
33
|
constructor(map, options) {
|
|
34
34
|
this.layers = {};
|
|
35
35
|
this.currentBaseLayerType = null;
|
|
36
|
+
this.currentAnnotationLayer = null;
|
|
37
|
+
this.currentAnnotationType = null;
|
|
36
38
|
this.errorHandler = ErrorHandler.getInstance();
|
|
37
39
|
try {
|
|
38
40
|
// 参数验证
|
|
@@ -90,6 +92,14 @@ export default class MapBaseLayers {
|
|
|
90
92
|
this.switchBaseLayer(firstLayerType);
|
|
91
93
|
}
|
|
92
94
|
}
|
|
95
|
+
// 添加注记图层
|
|
96
|
+
if (this.options.annotation) {
|
|
97
|
+
if (!this.options.token) {
|
|
98
|
+
throw new Error('请配置token后才能使用天地图注记');
|
|
99
|
+
}
|
|
100
|
+
const { token, zIndex = TIANDITU_CONFIG.DEFAULT_ZINDEX } = this.options;
|
|
101
|
+
this.loadDefaultAnnotationLayer(token, zIndex);
|
|
102
|
+
}
|
|
93
103
|
}
|
|
94
104
|
/**
|
|
95
105
|
* 初始化天地图图层
|
|
@@ -105,10 +115,6 @@ export default class MapBaseLayers {
|
|
|
105
115
|
this.layers.vec_c = [this.createTiandituLayer({ type: 'vec_c', token, zIndex, visible: false })];
|
|
106
116
|
this.layers.img_c = [this.createTiandituLayer({ type: 'img_c', token, zIndex, visible: false })];
|
|
107
117
|
this.layers.ter_c = [this.createTiandituLayer({ type: 'ter_c', token, zIndex, visible: false })];
|
|
108
|
-
// 添加注记图层
|
|
109
|
-
if (this.options.annotation) {
|
|
110
|
-
this.addAnnotationLayers(token, zIndex);
|
|
111
|
-
}
|
|
112
118
|
}
|
|
113
119
|
catch (error) {
|
|
114
120
|
this.errorHandler.createAndHandleError(`Failed to initialize Tianditu layers: ${error}`, ErrorType.LAYER_ERROR, { token, zIndex, error });
|
|
@@ -116,31 +122,81 @@ export default class MapBaseLayers {
|
|
|
116
122
|
}
|
|
117
123
|
}
|
|
118
124
|
/**
|
|
119
|
-
*
|
|
125
|
+
* 加载默认注记图层(cia_c)
|
|
126
|
+
* @param token 天地图token
|
|
127
|
+
* @param baseZIndex 基础层级
|
|
128
|
+
* @private
|
|
129
|
+
*/
|
|
130
|
+
loadDefaultAnnotationLayer(token, baseZIndex) {
|
|
131
|
+
this.setAnnotationLayer('cia_c', token, baseZIndex);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* 切换注记类别
|
|
135
|
+
* @param annotationType 注记类型 ('cva_c' | 'cia_c' | 'cta_c')
|
|
136
|
+
*/
|
|
137
|
+
switchAnnotationLayer(annotationType) {
|
|
138
|
+
try {
|
|
139
|
+
if (!this.options.token) {
|
|
140
|
+
throw new Error('Token is required for annotation layer');
|
|
141
|
+
}
|
|
142
|
+
if (!this.options.annotation) {
|
|
143
|
+
throw new Error('Annotation is not enabled in options');
|
|
144
|
+
}
|
|
145
|
+
const baseZIndex = this.options.zIndex ?? TIANDITU_CONFIG.DEFAULT_ZINDEX;
|
|
146
|
+
this.setAnnotationLayer(annotationType, this.options.token, baseZIndex);
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
this.errorHandler.createAndHandleError(`Failed to switch annotation layer to '${annotationType}': ${error}`, ErrorType.LAYER_ERROR, { annotationType, error });
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* 设置注记图层(私有方法,用于消除代码重复)
|
|
154
|
+
* @param annotationType 注记类型
|
|
120
155
|
* @param token 天地图token
|
|
121
156
|
* @param baseZIndex 基础层级
|
|
122
157
|
* @private
|
|
123
158
|
*/
|
|
124
|
-
|
|
159
|
+
setAnnotationLayer(annotationType, token, baseZIndex) {
|
|
160
|
+
// 移除当前注记图层
|
|
161
|
+
if (this.currentAnnotationLayer) {
|
|
162
|
+
this.map.removeLayer(this.currentAnnotationLayer);
|
|
163
|
+
}
|
|
164
|
+
// 创建新的注记图层,确保层级在基本图层之上
|
|
125
165
|
const annotationZIndex = baseZIndex + TIANDITU_CONFIG.ANNOTATION_ZINDEX_OFFSET;
|
|
126
|
-
this.
|
|
127
|
-
type:
|
|
128
|
-
token,
|
|
129
|
-
zIndex: annotationZIndex,
|
|
130
|
-
visible: false
|
|
131
|
-
}));
|
|
132
|
-
this.layers.img_c?.push(this.createAnnotationLayer({
|
|
133
|
-
type: 'cia_c',
|
|
166
|
+
let annotationLayer = this.createAnnotationLayer({
|
|
167
|
+
type: annotationType,
|
|
134
168
|
token,
|
|
135
169
|
zIndex: annotationZIndex,
|
|
136
|
-
visible:
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
170
|
+
visible: true
|
|
171
|
+
});
|
|
172
|
+
// 应用剪切处理
|
|
173
|
+
annotationLayer = this.processLayer(annotationLayer);
|
|
174
|
+
this.currentAnnotationLayer = annotationLayer;
|
|
175
|
+
this.currentAnnotationType = annotationType;
|
|
176
|
+
this.map.addLayer(this.currentAnnotationLayer);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* 获取当前注记类型
|
|
180
|
+
* @returns 当前注记类型
|
|
181
|
+
*/
|
|
182
|
+
getCurrentAnnotationType() {
|
|
183
|
+
return this.currentAnnotationType;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* 显示/隐藏注记图层
|
|
187
|
+
* @param visible 是否可见
|
|
188
|
+
*/
|
|
189
|
+
setAnnotationVisible(visible) {
|
|
190
|
+
if (this.currentAnnotationLayer) {
|
|
191
|
+
this.currentAnnotationLayer.setVisible(visible);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* 检查注记图层是否可见
|
|
196
|
+
* @returns 是否可见
|
|
197
|
+
*/
|
|
198
|
+
isAnnotationVisible() {
|
|
199
|
+
return this.currentAnnotationLayer ? this.currentAnnotationLayer.getVisible() : false;
|
|
144
200
|
}
|
|
145
201
|
/**
|
|
146
202
|
* 切换底图图层
|
|
@@ -167,6 +223,12 @@ export default class MapBaseLayers {
|
|
|
167
223
|
layer.setVisible(true);
|
|
168
224
|
});
|
|
169
225
|
this.currentBaseLayerType = type;
|
|
226
|
+
// 如果存在注记图层,更新其层级确保在新的基本图层之上
|
|
227
|
+
if (this.currentAnnotationLayer && this.currentAnnotationType) {
|
|
228
|
+
const baseZIndex = this.options.zIndex ?? TIANDITU_CONFIG.DEFAULT_ZINDEX;
|
|
229
|
+
const annotationZIndex = baseZIndex + TIANDITU_CONFIG.ANNOTATION_ZINDEX_OFFSET;
|
|
230
|
+
this.currentAnnotationLayer.setZIndex(annotationZIndex);
|
|
231
|
+
}
|
|
170
232
|
}
|
|
171
233
|
catch (error) {
|
|
172
234
|
this.errorHandler.createAndHandleError(`Failed to switch base layer to '${type}': ${error}`, ErrorType.LAYER_ERROR, { type, error });
|
|
@@ -462,6 +524,12 @@ export default class MapBaseLayers {
|
|
|
462
524
|
this.map.removeLayer(layer);
|
|
463
525
|
});
|
|
464
526
|
}
|
|
527
|
+
// 清除注记图层
|
|
528
|
+
if (this.currentAnnotationLayer) {
|
|
529
|
+
this.map.removeLayer(this.currentAnnotationLayer);
|
|
530
|
+
this.currentAnnotationLayer = null;
|
|
531
|
+
this.currentAnnotationType = null;
|
|
532
|
+
}
|
|
465
533
|
this.layers = {};
|
|
466
534
|
this.currentBaseLayerType = null;
|
|
467
535
|
}
|
package/core/MapTools.d.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import Map from "ol/Map";
|
|
2
|
-
import {
|
|
2
|
+
import { MapJSONData } from "../types";
|
|
3
3
|
import VectorLayer from "ol/layer/Vector";
|
|
4
4
|
import VectorSource from "ol/source/Vector";
|
|
5
5
|
import BaseLayer from "ol/layer/Base";
|
|
6
6
|
import ImageLayer from "ol/layer/Image";
|
|
7
7
|
import ImageSource from "ol/source/Image";
|
|
8
|
-
import { EventManager, MapEventData } from "./EventManager";
|
|
9
8
|
/**
|
|
10
9
|
* 地图工具类
|
|
11
10
|
* 提供地图的基础操作功能
|
|
12
11
|
*/
|
|
13
12
|
export default class MapTools {
|
|
14
13
|
private readonly map;
|
|
15
|
-
private eventManager;
|
|
16
14
|
private errorHandler;
|
|
17
15
|
constructor(map: Map);
|
|
18
16
|
/**
|
|
@@ -62,55 +60,6 @@ export default class MapTools {
|
|
|
62
60
|
* @throws 当参数无效时抛出错误
|
|
63
61
|
*/
|
|
64
62
|
static setLayerVisible: (map: Map, layerName: string, visible: boolean) => void;
|
|
65
|
-
/**
|
|
66
|
-
* 地图监听事件
|
|
67
|
-
* @param eventType 事件类型
|
|
68
|
-
* @param callback 回调函数
|
|
69
|
-
* @param options 事件选项
|
|
70
|
-
* @returns 事件监听器ID
|
|
71
|
-
* @throws 当参数无效时抛出错误
|
|
72
|
-
*/
|
|
73
|
-
mapOnEvent(eventType: EventType, callback: (feature?: any, e?: any) => void, options?: {
|
|
74
|
-
clickType?: 'point' | 'line' | 'polygon';
|
|
75
|
-
once?: boolean;
|
|
76
|
-
filter?: (event: MapEventData) => boolean;
|
|
77
|
-
}): string;
|
|
78
|
-
/**
|
|
79
|
-
* 地图监听事件(静态方法,兼容性保留)
|
|
80
|
-
* @param map 地图实例
|
|
81
|
-
* @param eventType 事件类型
|
|
82
|
-
* @param callback 回调函数
|
|
83
|
-
* @param clickType 点击类型
|
|
84
|
-
* @throws 当参数无效时抛出错误
|
|
85
|
-
* @deprecated 推荐使用实例方法 mapOnEvent
|
|
86
|
-
*/
|
|
87
|
-
static mapOnEvent(map: Map, eventType: EventType, callback: (feature?: any, e?: any) => void, clickType?: 'point' | 'line' | 'polygon'): void;
|
|
88
|
-
/**
|
|
89
|
-
* 兼容性方法:使用传统方式注册事件
|
|
90
|
-
* @private
|
|
91
|
-
*/
|
|
92
|
-
private registerEventWithManager;
|
|
93
|
-
/**
|
|
94
|
-
* 转换事件类型
|
|
95
|
-
* @private
|
|
96
|
-
*/
|
|
97
|
-
private convertToMapEventType;
|
|
98
|
-
/**
|
|
99
|
-
* 移除事件监听器
|
|
100
|
-
* @param listenerId 监听器ID
|
|
101
|
-
* @returns 是否成功移除
|
|
102
|
-
*/
|
|
103
|
-
removeEventListener(listenerId: string): boolean;
|
|
104
|
-
/**
|
|
105
|
-
* 移除指定类型的所有事件监听器
|
|
106
|
-
* @param eventType 事件类型
|
|
107
|
-
*/
|
|
108
|
-
removeAllEventListeners(eventType?: EventType): void;
|
|
109
|
-
/**
|
|
110
|
-
* 获取 EventManager 实例
|
|
111
|
-
* @returns EventManager 实例
|
|
112
|
-
*/
|
|
113
|
-
getEventManager(): EventManager;
|
|
114
63
|
/**
|
|
115
64
|
* 获取地图实例
|
|
116
65
|
* @returns 地图实例
|
package/core/MapTools.js
CHANGED
|
@@ -4,7 +4,6 @@ import VectorSource from "ol/source/Vector";
|
|
|
4
4
|
import GeoJSON from "ol/format/GeoJSON";
|
|
5
5
|
import { Fill, Style } from "ol/style";
|
|
6
6
|
import { getVectorContext } from "ol/render";
|
|
7
|
-
import { EventManager } from "./EventManager";
|
|
8
7
|
import { ErrorHandler, ErrorType } from "../utils/ErrorHandler";
|
|
9
8
|
import { ValidationUtils } from "../utils/ValidationUtils";
|
|
10
9
|
/**
|
|
@@ -17,10 +16,9 @@ class MapTools {
|
|
|
17
16
|
try {
|
|
18
17
|
ValidationUtils.validateMap(map);
|
|
19
18
|
this.map = map;
|
|
20
|
-
this.eventManager = new EventManager(map);
|
|
21
19
|
}
|
|
22
20
|
catch (error) {
|
|
23
|
-
this.errorHandler.createAndHandleError(`
|
|
21
|
+
this.errorHandler.createAndHandleError(`MapTools initialization failed: ${error}`, ErrorType.COMPONENT_ERROR, { map, error });
|
|
24
22
|
throw error;
|
|
25
23
|
}
|
|
26
24
|
}
|
|
@@ -165,156 +163,6 @@ class MapTools {
|
|
|
165
163
|
throw new Error('Failed to set layer visibility');
|
|
166
164
|
}
|
|
167
165
|
}
|
|
168
|
-
/**
|
|
169
|
-
* 地图监听事件
|
|
170
|
-
* @param eventType 事件类型
|
|
171
|
-
* @param callback 回调函数
|
|
172
|
-
* @param options 事件选项
|
|
173
|
-
* @returns 事件监听器ID
|
|
174
|
-
* @throws 当参数无效时抛出错误
|
|
175
|
-
*/
|
|
176
|
-
mapOnEvent(eventType, callback, options) {
|
|
177
|
-
try {
|
|
178
|
-
ErrorHandler.validateMap(this.map);
|
|
179
|
-
if (!eventType) {
|
|
180
|
-
throw new Error('Event type is required');
|
|
181
|
-
}
|
|
182
|
-
if (typeof callback !== 'function') {
|
|
183
|
-
throw new Error('Callback must be a function');
|
|
184
|
-
}
|
|
185
|
-
return this.registerEventWithManager(eventType, callback, options);
|
|
186
|
-
}
|
|
187
|
-
catch (error) {
|
|
188
|
-
this.errorHandler.createAndHandleError(`Failed to register map event: ${error}`, ErrorType.COMPONENT_ERROR, { eventType, callback, options, error });
|
|
189
|
-
throw error;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* 地图监听事件(静态方法,兼容性保留)
|
|
194
|
-
* @param map 地图实例
|
|
195
|
-
* @param eventType 事件类型
|
|
196
|
-
* @param callback 回调函数
|
|
197
|
-
* @param clickType 点击类型
|
|
198
|
-
* @throws 当参数无效时抛出错误
|
|
199
|
-
* @deprecated 推荐使用实例方法 mapOnEvent
|
|
200
|
-
*/
|
|
201
|
-
static mapOnEvent(map, eventType, callback, clickType) {
|
|
202
|
-
const errorHandler = ErrorHandler.getInstance();
|
|
203
|
-
try {
|
|
204
|
-
ErrorHandler.validateMap(map);
|
|
205
|
-
if (!eventType) {
|
|
206
|
-
throw new Error('Event type is required');
|
|
207
|
-
}
|
|
208
|
-
if (typeof callback !== 'function') {
|
|
209
|
-
throw new Error('Callback must be a function');
|
|
210
|
-
}
|
|
211
|
-
const eventManager = new EventManager(map);
|
|
212
|
-
const mapTools = new MapTools(map);
|
|
213
|
-
mapTools.registerEventWithManager(eventType, callback, { clickType });
|
|
214
|
-
}
|
|
215
|
-
catch (error) {
|
|
216
|
-
errorHandler.createAndHandleError(`Failed to register static map event: ${error}`, ErrorType.COMPONENT_ERROR, { map, eventType, callback, clickType, error });
|
|
217
|
-
throw error;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* 兼容性方法:使用传统方式注册事件
|
|
222
|
-
* @private
|
|
223
|
-
*/
|
|
224
|
-
registerEventWithManager(eventType, callback, options) {
|
|
225
|
-
const mapEventType = this.convertToMapEventType(eventType);
|
|
226
|
-
const eventCallback = (event) => {
|
|
227
|
-
try {
|
|
228
|
-
if (eventType === 'click') {
|
|
229
|
-
const feature = event.feature;
|
|
230
|
-
const extraData = {
|
|
231
|
-
features: event.features || [],
|
|
232
|
-
pixel: event.pixel
|
|
233
|
-
};
|
|
234
|
-
// 应用点击类型过滤
|
|
235
|
-
if (options?.clickType && feature) {
|
|
236
|
-
const geometryType = feature.getGeometry()?.getType();
|
|
237
|
-
const clickTypeMap = {
|
|
238
|
-
point: ['Point', 'MultiPoint'],
|
|
239
|
-
line: ['LineString', 'MultiLineString'],
|
|
240
|
-
polygon: ['Polygon', 'MultiPolygon']
|
|
241
|
-
};
|
|
242
|
-
if (geometryType && !clickTypeMap[options.clickType].includes(geometryType)) {
|
|
243
|
-
return; // 不符合点击类型过滤条件
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
callback(feature, extraData);
|
|
247
|
-
}
|
|
248
|
-
else if (eventType === 'moveend') {
|
|
249
|
-
callback(event.zoom);
|
|
250
|
-
}
|
|
251
|
-
else if (eventType === 'hover') {
|
|
252
|
-
callback({
|
|
253
|
-
features: event.features || [],
|
|
254
|
-
pixel: event.pixel
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
catch (error) {
|
|
259
|
-
this.errorHandler.createAndHandleError(`Error in event callback: ${error}`, ErrorType.COMPONENT_ERROR, { eventType, event, error });
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
return this.eventManager.on(mapEventType, eventCallback, {
|
|
263
|
-
once: options?.once,
|
|
264
|
-
filter: options?.filter
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* 转换事件类型
|
|
269
|
-
* @private
|
|
270
|
-
*/
|
|
271
|
-
convertToMapEventType(eventType) {
|
|
272
|
-
const typeMap = {
|
|
273
|
-
'click': 'click',
|
|
274
|
-
'hover': 'hover',
|
|
275
|
-
'moveend': 'moveend'
|
|
276
|
-
};
|
|
277
|
-
return typeMap[eventType] || 'click';
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* 移除事件监听器
|
|
281
|
-
* @param listenerId 监听器ID
|
|
282
|
-
* @returns 是否成功移除
|
|
283
|
-
*/
|
|
284
|
-
removeEventListener(listenerId) {
|
|
285
|
-
try {
|
|
286
|
-
return this.eventManager.off(listenerId);
|
|
287
|
-
}
|
|
288
|
-
catch (error) {
|
|
289
|
-
this.errorHandler.createAndHandleError(`Failed to remove event listener: ${error}`, ErrorType.COMPONENT_ERROR, { listenerId, error });
|
|
290
|
-
return false;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* 移除指定类型的所有事件监听器
|
|
295
|
-
* @param eventType 事件类型
|
|
296
|
-
*/
|
|
297
|
-
removeAllEventListeners(eventType) {
|
|
298
|
-
try {
|
|
299
|
-
if (eventType) {
|
|
300
|
-
const mapEventType = this.convertToMapEventType(eventType);
|
|
301
|
-
this.eventManager.offAll(mapEventType);
|
|
302
|
-
}
|
|
303
|
-
else {
|
|
304
|
-
this.eventManager.clear();
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
catch (error) {
|
|
308
|
-
this.errorHandler.createAndHandleError(`Failed to remove event listeners: ${error}`, ErrorType.COMPONENT_ERROR, { eventType, error });
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* 获取 EventManager 实例
|
|
313
|
-
* @returns EventManager 实例
|
|
314
|
-
*/
|
|
315
|
-
getEventManager() {
|
|
316
|
-
return this.eventManager;
|
|
317
|
-
}
|
|
318
166
|
/**
|
|
319
167
|
* 获取地图实例
|
|
320
168
|
* @returns 地图实例
|
package/core/Point.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Map from "ol/Map";
|
|
2
2
|
import VectorLayer from "ol/layer/Vector";
|
|
3
3
|
import VectorSource from "ol/source/Vector";
|
|
4
|
-
import { MapJSONData, PointOptions, ClusterOptions, PointData } from '../types';
|
|
4
|
+
import { MapJSONData, PointOptions, ClusterOptions, PointData, VueTemplatePointInstance } from '../types';
|
|
5
5
|
export default class Point {
|
|
6
6
|
private map;
|
|
7
7
|
constructor(map: Map);
|
|
@@ -50,20 +50,19 @@ export default class Point {
|
|
|
50
50
|
* @param options {
|
|
51
51
|
* nameKey: String 数据中的名称的key
|
|
52
52
|
* img: String 图标
|
|
53
|
-
* hasImg: Boolean 是否显示图标
|
|
54
53
|
* }
|
|
55
54
|
*/
|
|
56
55
|
addPoint(pointData: PointData[], options: PointOptions): VectorLayer<VectorSource> | null;
|
|
57
56
|
addClusterPoint(pointData: PointData[], options: ClusterOptions): VectorLayer<VectorSource> | null;
|
|
58
|
-
|
|
57
|
+
addTwinkleLayerFromPolygon(twinkleList: any[], className: string, key: string, json: MapJSONData): void;
|
|
59
58
|
/**
|
|
60
|
-
*
|
|
61
|
-
* @param twinkleList 闪烁点数据 - 二维数组 [[]
|
|
59
|
+
* 添加闪烁点
|
|
60
|
+
* @param twinkleList 闪烁点数据 - 二维数组 [[],[]]
|
|
62
61
|
* @param className 闪烁点样式,需要和id保持一致
|
|
63
62
|
* @param key 闪烁点索引
|
|
64
63
|
* @param callback
|
|
65
64
|
*/
|
|
66
|
-
|
|
65
|
+
addTwinkleLayer(twinkleList: any[], className: string | undefined, key: string, callback?: Function): void;
|
|
67
66
|
/**
|
|
68
67
|
* 地图定位
|
|
69
68
|
* @param lgtd 经度
|
|
@@ -75,17 +74,21 @@ export default class Point {
|
|
|
75
74
|
/**
|
|
76
75
|
* 设置dom元素为点位
|
|
77
76
|
*/
|
|
78
|
-
|
|
77
|
+
addDomPoint(id: string, lgtd: number, lttd: number): boolean;
|
|
79
78
|
/**
|
|
80
|
-
*
|
|
81
|
-
* @param
|
|
79
|
+
* 添加vue组件为点位
|
|
80
|
+
* @param pointDataList 点位信息列表
|
|
82
81
|
* @param template vue组件模板
|
|
83
82
|
* @param Vue Vue实例
|
|
84
83
|
* @returns 返回控制对象,包含显示、隐藏、移除方法
|
|
85
84
|
* @throws 当参数无效时抛出错误
|
|
86
85
|
*/
|
|
87
|
-
|
|
86
|
+
addVueTemplatePoint(pointDataList: PointData[], template: any, options?: {
|
|
87
|
+
positioning?: 'bottom-left' | 'bottom-center' | 'bottom-right' | 'center-left' | 'center-center' | 'center-right' | 'top-left' | 'top-center' | 'top-right';
|
|
88
|
+
stopEvent?: boolean;
|
|
89
|
+
}): {
|
|
88
90
|
setVisible: (visible: boolean) => void;
|
|
89
91
|
remove: () => void;
|
|
92
|
+
getPoints: () => VueTemplatePointInstance[];
|
|
90
93
|
};
|
|
91
94
|
}
|
package/core/Point.js
CHANGED
|
@@ -8,7 +8,7 @@ import VectorSource from "ol/source/Vector";
|
|
|
8
8
|
import { Cluster } from 'ol/source';
|
|
9
9
|
import * as turf from '@turf/turf';
|
|
10
10
|
import GeoJSON from "ol/format/GeoJSON";
|
|
11
|
-
import
|
|
11
|
+
import VueTemplatePoint from './VueTemplatePoint';
|
|
12
12
|
import MapTools from "./MapTools";
|
|
13
13
|
import { ValidationUtils } from '../utils/ValidationUtils';
|
|
14
14
|
export default class Point {
|
|
@@ -64,7 +64,7 @@ export default class Point {
|
|
|
64
64
|
if (options.nameKey && item) {
|
|
65
65
|
style.text = this.createTextStyle(options, item[options.nameKey]);
|
|
66
66
|
}
|
|
67
|
-
if (options.
|
|
67
|
+
if (options.img) {
|
|
68
68
|
style.image = this.createIconStyle(options);
|
|
69
69
|
}
|
|
70
70
|
return new Style(style);
|
|
@@ -81,7 +81,7 @@ export default class Point {
|
|
|
81
81
|
if (options.nameKey) {
|
|
82
82
|
style.text = this.createTextStyle(options, name);
|
|
83
83
|
}
|
|
84
|
-
if (options.
|
|
84
|
+
if (options.img) {
|
|
85
85
|
style.image = this.createIconStyle(options);
|
|
86
86
|
}
|
|
87
87
|
return new Style(style);
|
|
@@ -103,7 +103,6 @@ export default class Point {
|
|
|
103
103
|
* @param options {
|
|
104
104
|
* nameKey: String 数据中的名称的key
|
|
105
105
|
* img: String 图标
|
|
106
|
-
* hasImg: Boolean 是否显示图标
|
|
107
106
|
* }
|
|
108
107
|
*/
|
|
109
108
|
addPoint(pointData, options) {
|
|
@@ -169,7 +168,7 @@ export default class Point {
|
|
|
169
168
|
return clusterLayer;
|
|
170
169
|
}
|
|
171
170
|
// 在流域中心添加闪烁点位
|
|
172
|
-
|
|
171
|
+
addTwinkleLayerFromPolygon(twinkleList, className, key, json) {
|
|
173
172
|
new MapTools(this.map).removeLayer('twinklePoint');
|
|
174
173
|
// 计算多边形的中心点坐标
|
|
175
174
|
const calculatePolygonCenter = (polygonCoordinates) => {
|
|
@@ -221,17 +220,17 @@ export default class Point {
|
|
|
221
220
|
zIndex: 21
|
|
222
221
|
});
|
|
223
222
|
this.map.addLayer(basinLayer);
|
|
224
|
-
this.
|
|
223
|
+
this.addTwinkleLayer(twinkleList, className, key, (twinkleItem) => {
|
|
225
224
|
});
|
|
226
225
|
}
|
|
227
226
|
/**
|
|
228
|
-
*
|
|
229
|
-
* @param twinkleList 闪烁点数据 - 二维数组 [[]
|
|
227
|
+
* 添加闪烁点
|
|
228
|
+
* @param twinkleList 闪烁点数据 - 二维数组 [[],[]]
|
|
230
229
|
* @param className 闪烁点样式,需要和id保持一致
|
|
231
230
|
* @param key 闪烁点索引
|
|
232
231
|
* @param callback
|
|
233
232
|
*/
|
|
234
|
-
|
|
233
|
+
addTwinkleLayer(twinkleList, className = 'marker_warning', key, callback) {
|
|
235
234
|
// 查找class是warn-points的dom,并删除
|
|
236
235
|
const arr = document.getElementsByClassName(className);
|
|
237
236
|
const l = arr.length;
|
|
@@ -289,7 +288,7 @@ export default class Point {
|
|
|
289
288
|
/**
|
|
290
289
|
* 设置dom元素为点位
|
|
291
290
|
*/
|
|
292
|
-
|
|
291
|
+
addDomPoint(id, lgtd, lttd) {
|
|
293
292
|
if (!id) {
|
|
294
293
|
console.error('Element ID is required');
|
|
295
294
|
return false;
|
|
@@ -319,56 +318,26 @@ export default class Point {
|
|
|
319
318
|
}
|
|
320
319
|
}
|
|
321
320
|
/**
|
|
322
|
-
*
|
|
323
|
-
* @param
|
|
321
|
+
* 添加vue组件为点位
|
|
322
|
+
* @param pointDataList 点位信息列表
|
|
324
323
|
* @param template vue组件模板
|
|
325
324
|
* @param Vue Vue实例
|
|
326
325
|
* @returns 返回控制对象,包含显示、隐藏、移除方法
|
|
327
326
|
* @throws 当参数无效时抛出错误
|
|
328
327
|
*/
|
|
329
|
-
|
|
330
|
-
if (!
|
|
328
|
+
addVueTemplatePoint(pointDataList, template, options) {
|
|
329
|
+
if (!pointDataList || !Array.isArray(pointDataList) || pointDataList.length === 0) {
|
|
331
330
|
throw new Error('Valid point info list is required');
|
|
332
331
|
}
|
|
333
332
|
if (!template) {
|
|
334
333
|
throw new Error('Vue template is required');
|
|
335
334
|
}
|
|
336
|
-
if (!Vue) {
|
|
337
|
-
throw new Error('Vue instance is required');
|
|
338
|
-
}
|
|
339
335
|
try {
|
|
340
|
-
const
|
|
341
|
-
|
|
342
|
-
throw new Error('Valid longitude and latitude are required for each point');
|
|
343
|
-
}
|
|
344
|
-
return new DomPoint(this.map, {
|
|
345
|
-
Vue,
|
|
346
|
-
Template: template,
|
|
347
|
-
lgtd: pointInfo.lgtd,
|
|
348
|
-
lttd: pointInfo.lttd,
|
|
349
|
-
props: {
|
|
350
|
-
stationInfo: {
|
|
351
|
-
type: Object,
|
|
352
|
-
default: pointInfo
|
|
353
|
-
}
|
|
354
|
-
},
|
|
355
|
-
});
|
|
356
|
-
});
|
|
357
|
-
return {
|
|
358
|
-
setVisible: (visible) => {
|
|
359
|
-
layer.forEach((item) => {
|
|
360
|
-
item.setVisible(visible);
|
|
361
|
-
});
|
|
362
|
-
},
|
|
363
|
-
remove: () => {
|
|
364
|
-
layer.forEach((item) => {
|
|
365
|
-
item.remove();
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
};
|
|
336
|
+
const vueTemplatePoint = new VueTemplatePoint(this.map);
|
|
337
|
+
return vueTemplatePoint.addVueTemplatePoint(pointDataList, template, options);
|
|
369
338
|
}
|
|
370
339
|
catch (error) {
|
|
371
|
-
throw new Error(`Failed to create
|
|
340
|
+
throw new Error(`Failed to create Vue template points: ${error}`);
|
|
372
341
|
}
|
|
373
342
|
}
|
|
374
343
|
}
|
package/core/Polygon.js
CHANGED
|
@@ -74,7 +74,7 @@ export default class Polygon {
|
|
|
74
74
|
visible: true,
|
|
75
75
|
strokeColor: '#EBEEF5',
|
|
76
76
|
strokeWidth: 2,
|
|
77
|
-
fillColor: 'rgba(255, 255, 255, 0
|
|
77
|
+
fillColor: 'rgba(255, 255, 255, 0)',
|
|
78
78
|
textFont: '14px Calibri,sans-serif',
|
|
79
79
|
textFillColor: '#FFF',
|
|
80
80
|
textStrokeColor: '#409EFF',
|