my-openlayer 0.1.18 → 1.0.0
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 +1114 -213
- package/dist/MyOl.d.ts +99 -31
- package/dist/MyOl.js +338 -106
- package/dist/core/ConfigManager.d.ts +113 -0
- package/dist/core/ConfigManager.js +164 -0
- package/dist/core/DomPoint.d.ts +163 -14
- package/dist/core/DomPoint.js +401 -26
- package/dist/core/EventManager.d.ts +131 -0
- package/dist/core/EventManager.js +257 -0
- package/dist/core/Line.d.ts +20 -4
- package/dist/core/Line.js +36 -1
- package/dist/core/MapBaseLayers.d.ts +187 -19
- package/dist/core/MapBaseLayers.js +460 -122
- package/dist/core/MapTools.d.ts +77 -7
- package/dist/core/MapTools.js +267 -65
- package/dist/core/MeasureHandler.d.ts +13 -6
- package/dist/core/MeasureHandler.js +46 -25
- package/dist/core/Point.d.ts +13 -5
- package/dist/core/Point.js +94 -39
- package/dist/core/Polygon.d.ts +74 -22
- package/dist/core/Polygon.js +306 -125
- package/dist/index.d.ts +17 -10
- package/dist/index.js +15 -10
- package/dist/types.d.ts +280 -96
- package/dist/types.js +11 -1
- package/dist/utils/ErrorHandler.d.ts +102 -0
- package/dist/utils/ErrorHandler.js +191 -0
- package/package.json +5 -6
package/dist/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,
|
|
4
|
+
import { MapJSONData, PointOptions, ClusterOptions, PointData } from '../types';
|
|
5
5
|
export default class Point {
|
|
6
6
|
private map;
|
|
7
7
|
constructor(map: Map);
|
|
@@ -15,8 +15,8 @@ export default class Point {
|
|
|
15
15
|
* hasImg: Boolean 是否显示图标
|
|
16
16
|
* }
|
|
17
17
|
*/
|
|
18
|
-
addPoint(pointData: PointData[], options:
|
|
19
|
-
addClusterPoint(pointData: PointData[], options:
|
|
18
|
+
addPoint(pointData: PointData[], options: PointOptions): VectorLayer<VectorSource> | null;
|
|
19
|
+
addClusterPoint(pointData: PointData[], options: ClusterOptions): VectorLayer<VectorSource> | null;
|
|
20
20
|
setTwinkleLayerFromPolygon(twinkleList: any[], className: string, key: string, json: MapJSONData): void;
|
|
21
21
|
/**
|
|
22
22
|
* 设置闪烁点
|
|
@@ -33,11 +33,19 @@ export default class Point {
|
|
|
33
33
|
* @param zoom 缩放级别
|
|
34
34
|
* @param duration 动画时长
|
|
35
35
|
*/
|
|
36
|
-
locationAction(lgtd: number, lttd: number, zoom?: number, duration?: number):
|
|
36
|
+
locationAction(lgtd: number, lttd: number, zoom?: number, duration?: number): boolean;
|
|
37
37
|
/**
|
|
38
38
|
* 设置dom元素为点位
|
|
39
39
|
*/
|
|
40
|
-
setDomPoint(id: string, lgtd: number, lttd: number):
|
|
40
|
+
setDomPoint(id: string, lgtd: number, lttd: number): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* 设置vue组件为点位
|
|
43
|
+
* @param pointInfoList 点位信息列表
|
|
44
|
+
* @param template vue组件模板
|
|
45
|
+
* @param Vue Vue实例
|
|
46
|
+
* @returns 返回控制对象,包含显示、隐藏、移除方法
|
|
47
|
+
* @throws 当参数无效时抛出错误
|
|
48
|
+
*/
|
|
41
49
|
setDomPointVue(pointInfoList: any[], template: any, Vue: any): {
|
|
42
50
|
setVisible: (visible: boolean) => void;
|
|
43
51
|
remove: () => void;
|
package/dist/core/Point.js
CHANGED
|
@@ -3,13 +3,12 @@ import Overlay from 'ol/Overlay';
|
|
|
3
3
|
import Feature from "ol/Feature";
|
|
4
4
|
import { Point as olPoint } from "ol/geom";
|
|
5
5
|
import { Text, Style, Fill, Stroke, Icon } from "ol/style";
|
|
6
|
-
// import {Style, Icon, Text} from "ol/style";
|
|
7
6
|
import VectorLayer from "ol/layer/Vector";
|
|
8
7
|
import VectorSource from "ol/source/Vector";
|
|
9
8
|
import { Cluster } from 'ol/source';
|
|
10
|
-
import * as turf from 'turf';
|
|
9
|
+
import * as turf from '@turf/turf';
|
|
11
10
|
import GeoJSON from "ol/format/GeoJSON";
|
|
12
|
-
import DomPoint from
|
|
11
|
+
import DomPoint from './DomPoint';
|
|
13
12
|
import MapTools from "./MapTools";
|
|
14
13
|
export default class Point {
|
|
15
14
|
constructor(map) {
|
|
@@ -26,12 +25,18 @@ export default class Point {
|
|
|
26
25
|
* }
|
|
27
26
|
*/
|
|
28
27
|
addPoint(pointData, options) {
|
|
28
|
+
if (!pointData || pointData.length === 0) {
|
|
29
|
+
console.warn('Point data is empty or undefined');
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
29
32
|
const pointFeatureList = [];
|
|
30
33
|
pointData.forEach((item) => {
|
|
34
|
+
if (!item.lgtd || !item.lttd) {
|
|
35
|
+
console.warn('Invalid coordinates for point:', item);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
31
38
|
const pointFeature = new Feature({
|
|
32
|
-
|
|
33
|
-
// all: JSON.stringify(item),
|
|
34
|
-
rawData: item, //保存原始数据
|
|
39
|
+
rawData: item,
|
|
35
40
|
type: options.layerName,
|
|
36
41
|
geometry: new olPoint([item.lgtd, item.lttd])
|
|
37
42
|
});
|
|
@@ -75,8 +80,16 @@ export default class Point {
|
|
|
75
80
|
return PointVectorLayer;
|
|
76
81
|
}
|
|
77
82
|
addClusterPoint(pointData, options) {
|
|
83
|
+
if (!pointData || pointData.length === 0) {
|
|
84
|
+
console.warn('Point data is empty or undefined');
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
78
87
|
const pointFeatureList = [];
|
|
79
88
|
pointData.forEach(item => {
|
|
89
|
+
if (!item.lgtd || !item.lttd) {
|
|
90
|
+
console.warn('Invalid coordinates for cluster point:', item);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
80
93
|
const pointFeature = new Feature({
|
|
81
94
|
geometry: new olPoint([item.lgtd, item.lttd]),
|
|
82
95
|
name: options.nameKey ? item[options.nameKey] : '',
|
|
@@ -126,6 +139,7 @@ export default class Point {
|
|
|
126
139
|
});
|
|
127
140
|
clusterLayer.setVisible(options.visible === undefined ? true : options.visible);
|
|
128
141
|
this.map.addLayer(clusterLayer);
|
|
142
|
+
return clusterLayer;
|
|
129
143
|
}
|
|
130
144
|
// 在流域中心添加闪烁点位
|
|
131
145
|
setTwinkleLayerFromPolygon(twinkleList, className, key, json) {
|
|
@@ -233,58 +247,99 @@ export default class Point {
|
|
|
233
247
|
* @param duration 动画时长
|
|
234
248
|
*/
|
|
235
249
|
locationAction(lgtd, lttd, zoom = 20, duration = 3000) {
|
|
236
|
-
if (!(lgtd
|
|
237
|
-
console.error('[地图定位]', '
|
|
250
|
+
if (!lgtd || !lttd || isNaN(lgtd) || isNaN(lttd)) {
|
|
251
|
+
console.error('[地图定位]', '经纬度不能为空或无效');
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
try {
|
|
255
|
+
this.map.getView().animate({ center: [lgtd, lttd], zoom, duration });
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
console.error('[地图定位]', '定位失败:', error);
|
|
238
260
|
return false;
|
|
239
261
|
}
|
|
240
|
-
this.map.getView().animate({ center: [lgtd, lttd], zoom, duration });
|
|
241
262
|
}
|
|
242
263
|
/**
|
|
243
264
|
* 设置dom元素为点位
|
|
244
265
|
*/
|
|
245
266
|
setDomPoint(id, lgtd, lttd) {
|
|
267
|
+
if (!id || !lgtd || !lttd || isNaN(lgtd) || isNaN(lttd)) {
|
|
268
|
+
console.error('Invalid parameters for setDomPoint');
|
|
269
|
+
return false;
|
|
270
|
+
}
|
|
246
271
|
const el = document.getElementById(id);
|
|
247
|
-
if (el) {
|
|
272
|
+
if (!el) {
|
|
273
|
+
console.error(`Element with id '${id}' not found`);
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
try {
|
|
248
277
|
const anchor = new Overlay({
|
|
249
278
|
id: id,
|
|
250
279
|
element: el,
|
|
251
280
|
positioning: 'center-center',
|
|
252
281
|
stopEvent: false
|
|
253
|
-
// autoPan: true,
|
|
254
|
-
// autoPanAnimation: {
|
|
255
|
-
// duration: 250
|
|
256
|
-
// },
|
|
257
282
|
});
|
|
258
283
|
anchor.setPosition([lgtd, lttd]);
|
|
259
284
|
this.map.addOverlay(anchor);
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
console.error('Failed to set DOM point:', error);
|
|
289
|
+
return false;
|
|
260
290
|
}
|
|
261
291
|
}
|
|
292
|
+
/**
|
|
293
|
+
* 设置vue组件为点位
|
|
294
|
+
* @param pointInfoList 点位信息列表
|
|
295
|
+
* @param template vue组件模板
|
|
296
|
+
* @param Vue Vue实例
|
|
297
|
+
* @returns 返回控制对象,包含显示、隐藏、移除方法
|
|
298
|
+
* @throws 当参数无效时抛出错误
|
|
299
|
+
*/
|
|
262
300
|
setDomPointVue(pointInfoList, template, Vue) {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
301
|
+
if (!pointInfoList || !Array.isArray(pointInfoList) || pointInfoList.length === 0) {
|
|
302
|
+
throw new Error('Valid point info list is required');
|
|
303
|
+
}
|
|
304
|
+
if (!template) {
|
|
305
|
+
throw new Error('Vue template is required');
|
|
306
|
+
}
|
|
307
|
+
if (!Vue) {
|
|
308
|
+
throw new Error('Vue instance is required');
|
|
309
|
+
}
|
|
310
|
+
try {
|
|
311
|
+
const layer = pointInfoList.map((pointInfo) => {
|
|
312
|
+
if (!pointInfo.lgtd || !pointInfo.lttd || isNaN(pointInfo.lgtd) || isNaN(pointInfo.lttd)) {
|
|
313
|
+
throw new Error('Valid longitude and latitude are required for each point');
|
|
314
|
+
}
|
|
315
|
+
return new DomPoint(this.map, {
|
|
316
|
+
Vue,
|
|
317
|
+
Template: template,
|
|
318
|
+
lgtd: pointInfo.lgtd,
|
|
319
|
+
lttd: pointInfo.lttd,
|
|
320
|
+
props: {
|
|
321
|
+
stationInfo: {
|
|
322
|
+
type: Object,
|
|
323
|
+
default: pointInfo
|
|
324
|
+
}
|
|
325
|
+
},
|
|
286
326
|
});
|
|
287
|
-
}
|
|
288
|
-
|
|
327
|
+
});
|
|
328
|
+
return {
|
|
329
|
+
setVisible: (visible) => {
|
|
330
|
+
layer.forEach((item) => {
|
|
331
|
+
item.setVisible(visible);
|
|
332
|
+
});
|
|
333
|
+
},
|
|
334
|
+
remove: () => {
|
|
335
|
+
layer.forEach((item) => {
|
|
336
|
+
item.remove();
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
catch (error) {
|
|
342
|
+
throw new Error(`Failed to create DOM points: ${error}`);
|
|
343
|
+
}
|
|
289
344
|
}
|
|
290
345
|
}
|
package/dist/core/Polygon.d.ts
CHANGED
|
@@ -1,39 +1,78 @@
|
|
|
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 { Image as ImageLayer } from "ol/layer";
|
|
5
|
-
import {
|
|
6
|
-
|
|
4
|
+
import { Image as ImageLayer, Heatmap } from "ol/layer";
|
|
5
|
+
import { PolygonOptions, MapJSONData, PointData, HeatMapOptions, ImageLayerData, MaskLayerOptions, FeatureColorUpdateOptions } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Polygon 类用于处理地图上的面要素操作
|
|
8
|
+
* 包括添加多边形、边框、图片图层、热力图等功能
|
|
9
|
+
*/
|
|
7
10
|
export default class Polygon {
|
|
8
|
-
map
|
|
11
|
+
private map;
|
|
9
12
|
private colorMap;
|
|
10
13
|
[key: string]: any;
|
|
14
|
+
/**
|
|
15
|
+
* 构造函数
|
|
16
|
+
* @param map OpenLayers 地图实例
|
|
17
|
+
*/
|
|
11
18
|
constructor(map: Map);
|
|
12
19
|
/**
|
|
13
20
|
* 获取等级颜色
|
|
14
|
-
* @param lev
|
|
21
|
+
* @param lev 等级值,支持字符串或数字
|
|
22
|
+
* @returns 对应等级的颜色值,如果等级不存在则返回默认颜色
|
|
15
23
|
*/
|
|
16
24
|
getLevColor(lev: string | number): string;
|
|
17
25
|
/**
|
|
18
|
-
*
|
|
19
|
-
* @param data
|
|
20
|
-
* @param options
|
|
26
|
+
* 添加地图边框图层
|
|
27
|
+
* @param data 图层数据,必须是有效的 GeoJSON 格式
|
|
28
|
+
* @param options 图层配置选项
|
|
29
|
+
* @returns 创建的图层实例
|
|
30
|
+
* @throws 当数据格式无效时抛出错误
|
|
31
|
+
*/
|
|
32
|
+
addBorderPolygon(data: MapJSONData, options?: PolygonOptions): VectorLayer<VectorSource>;
|
|
33
|
+
/**
|
|
34
|
+
* 添加多边形图层
|
|
35
|
+
* @param dataJSON GeoJSON 数据
|
|
36
|
+
* @param options 图层配置选项
|
|
37
|
+
* @returns 创建的矢量图层
|
|
38
|
+
* @throws 当数据格式无效时抛出错误
|
|
39
|
+
*/
|
|
40
|
+
addPolygon(dataJSON: MapJSONData, options?: PolygonOptions): VectorLayer<VectorSource>;
|
|
41
|
+
/**
|
|
42
|
+
* 设置要素样式
|
|
43
|
+
* @param features 要素数组
|
|
44
|
+
* @param options 样式配置选项
|
|
45
|
+
*/
|
|
46
|
+
private setFeatureStyles;
|
|
47
|
+
/**
|
|
48
|
+
* 获取要素文本
|
|
49
|
+
* @param feature 要素对象
|
|
50
|
+
* @param options 配置选项
|
|
51
|
+
* @returns 文本内容
|
|
52
|
+
*/
|
|
53
|
+
private getFeatureText;
|
|
54
|
+
/**
|
|
55
|
+
* 适应图层视图
|
|
56
|
+
* @param layer 图层对象
|
|
21
57
|
*/
|
|
22
|
-
|
|
23
|
-
addPolygon(dataJSON: MapJSONData, options?: OptionsType): VectorLayer<VectorSource<Geometry>>;
|
|
58
|
+
private fitViewToLayer;
|
|
24
59
|
/**
|
|
25
60
|
* 根据数据数组更新某个面颜色
|
|
26
61
|
* @param layerName 图层名称
|
|
27
|
-
* @param colorObj
|
|
28
|
-
* colorObj:{
|
|
29
|
-
* 对应geojson文件中的索引字段[propName]: 'rgba(255, 0, 0, 0.6)', // 颜色
|
|
30
|
-
* ...
|
|
31
|
-
* }
|
|
62
|
+
* @param colorObj 颜色映射对象,键为要素属性值,值为颜色字符串
|
|
32
63
|
* @param options 配置项
|
|
64
|
+
* @throws 当图层不存在时抛出错误
|
|
33
65
|
*/
|
|
34
66
|
updateFeatureColor(layerName: string, colorObj?: {
|
|
35
67
|
[propName: string]: string;
|
|
36
|
-
}, options?:
|
|
68
|
+
}, options?: FeatureColorUpdateOptions): void;
|
|
69
|
+
/**
|
|
70
|
+
* 更新单个要素的颜色
|
|
71
|
+
* @param feature 要素对象
|
|
72
|
+
* @param colorObj 颜色映射对象
|
|
73
|
+
* @param options 配置选项
|
|
74
|
+
*/
|
|
75
|
+
private updateSingleFeatureColor;
|
|
37
76
|
/**
|
|
38
77
|
* 设置外围蒙版图层
|
|
39
78
|
*
|
|
@@ -51,12 +90,25 @@ export default class Polygon {
|
|
|
51
90
|
}): void;
|
|
52
91
|
/**
|
|
53
92
|
* 添加图片图层
|
|
54
|
-
* @param
|
|
55
|
-
* @param
|
|
56
|
-
* @
|
|
57
|
-
* @
|
|
93
|
+
* @param imageData 图片数据,包含url和extent
|
|
94
|
+
* @param options 配置项
|
|
95
|
+
* @returns 创建的图片图层
|
|
96
|
+
* @throws 当数据格式无效时抛出错误
|
|
97
|
+
*/
|
|
98
|
+
addImageLayer(imageData: ImageLayerData, options?: PolygonOptions): ImageLayer<any>;
|
|
99
|
+
/**
|
|
100
|
+
* 添加热力图图层
|
|
101
|
+
* @param pointData 点数据数组
|
|
102
|
+
* @param options 热力图配置
|
|
103
|
+
*/
|
|
104
|
+
addHeatmap(pointData: PointData[], options?: HeatMapOptions): Heatmap;
|
|
105
|
+
/**
|
|
106
|
+
* 添加遮罩图层
|
|
107
|
+
* @param data GeoJSON格式的遮罩数据
|
|
108
|
+
* @param options 配置项
|
|
109
|
+
* @returns 创建的遮罩图层
|
|
110
|
+
* @throws 当数据格式无效时抛出错误
|
|
58
111
|
*/
|
|
59
|
-
|
|
60
|
-
addHeatmap(layerName: string, pointData: PointData[], options: HeatMapOptions): void;
|
|
112
|
+
addMaskLayer(data: any, options?: MaskLayerOptions): VectorLayer<VectorSource>;
|
|
61
113
|
removePolygonLayer(layerName: string): void;
|
|
62
114
|
}
|