my-openlayer 1.0.1 → 1.0.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/{dist/core → core}/Polygon.d.ts +25 -0
- package/{dist/core → core}/Polygon.js +89 -17
- package/package.json +9 -6
- package/{dist/utils → utils}/ValidationUtils.d.ts +2 -1
- package/{dist/utils → utils}/ValidationUtils.js +8 -4
- /package/{dist/MyOl.d.ts → MyOl.d.ts} +0 -0
- /package/{dist/MyOl.js → MyOl.js} +0 -0
- /package/{dist/core → core}/ConfigManager.d.ts +0 -0
- /package/{dist/core → core}/ConfigManager.js +0 -0
- /package/{dist/core → core}/DomPoint.d.ts +0 -0
- /package/{dist/core → core}/DomPoint.js +0 -0
- /package/{dist/core → core}/EventManager.d.ts +0 -0
- /package/{dist/core → core}/EventManager.js +0 -0
- /package/{dist/core → core}/Line.d.ts +0 -0
- /package/{dist/core → core}/Line.js +0 -0
- /package/{dist/core → core}/MapBaseLayers.d.ts +0 -0
- /package/{dist/core → core}/MapBaseLayers.js +0 -0
- /package/{dist/core → core}/MapTools.d.ts +0 -0
- /package/{dist/core → core}/MapTools.js +0 -0
- /package/{dist/core → core}/MeasureHandler.d.ts +0 -0
- /package/{dist/core → core}/MeasureHandler.js +0 -0
- /package/{dist/core → core}/Point.d.ts +0 -0
- /package/{dist/core → core}/Point.js +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/index.js → index.js} +0 -0
- /package/{dist/types.d.ts → types.d.ts} +0 -0
- /package/{dist/types.js → types.js} +0 -0
- /package/{dist/utils → utils}/ErrorHandler.d.ts +0 -0
- /package/{dist/utils → utils}/ErrorHandler.js +0 -0
|
@@ -96,6 +96,31 @@ export default class Polygon {
|
|
|
96
96
|
* @throws 当数据格式无效时抛出错误
|
|
97
97
|
*/
|
|
98
98
|
addImageLayer(imageData: ImageLayerData, options?: PolygonOptions): ImageLayer<any>;
|
|
99
|
+
/**
|
|
100
|
+
* 尝试更新现有图层
|
|
101
|
+
* @private
|
|
102
|
+
*/
|
|
103
|
+
private tryUpdateExistingImageLayer;
|
|
104
|
+
/**
|
|
105
|
+
* 创建新的图像图层
|
|
106
|
+
* @private
|
|
107
|
+
*/
|
|
108
|
+
private createNewImageLayer;
|
|
109
|
+
/**
|
|
110
|
+
* 更新图层属性
|
|
111
|
+
* @private
|
|
112
|
+
*/
|
|
113
|
+
private updateImageLayerProperties;
|
|
114
|
+
/**
|
|
115
|
+
* 配置图层基本属性
|
|
116
|
+
* @private
|
|
117
|
+
*/
|
|
118
|
+
private configureImageLayer;
|
|
119
|
+
/**
|
|
120
|
+
* 添加图层到地图并应用裁剪
|
|
121
|
+
* @private
|
|
122
|
+
*/
|
|
123
|
+
private addImageLayerToMap;
|
|
99
124
|
/**
|
|
100
125
|
* 添加热力图图层
|
|
101
126
|
* @param pointData 点数据数组
|
|
@@ -341,7 +341,9 @@ export default class Polygon {
|
|
|
341
341
|
* @throws 当数据格式无效时抛出错误
|
|
342
342
|
*/
|
|
343
343
|
addImageLayer(imageData, options) {
|
|
344
|
-
|
|
344
|
+
// 检查是否允许空img(当存在layerName且存在同名图层时)
|
|
345
|
+
const allowEmptyImg = !imageData.img && !!options?.layerName;
|
|
346
|
+
ValidationUtils.validateImageData(imageData, allowEmptyImg);
|
|
345
347
|
const mergedOptions = {
|
|
346
348
|
opacity: 1,
|
|
347
349
|
visible: true,
|
|
@@ -349,30 +351,100 @@ export default class Polygon {
|
|
|
349
351
|
layerName: 'imageLayer',
|
|
350
352
|
...options
|
|
351
353
|
};
|
|
352
|
-
//
|
|
354
|
+
// 尝试更新现有图层
|
|
353
355
|
if (mergedOptions.layerName) {
|
|
354
|
-
|
|
356
|
+
const existingLayer = this.tryUpdateExistingImageLayer(imageData, mergedOptions);
|
|
357
|
+
if (existingLayer) {
|
|
358
|
+
return existingLayer;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
// 创建新图层
|
|
362
|
+
return this.createNewImageLayer(imageData, mergedOptions);
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* 尝试更新现有图层
|
|
366
|
+
* @private
|
|
367
|
+
*/
|
|
368
|
+
tryUpdateExistingImageLayer(imageData, options) {
|
|
369
|
+
const existingLayers = MapTools.getLayerByLayerName(this.map, options.layerName);
|
|
370
|
+
if (existingLayers.length === 0) {
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
const existingLayer = existingLayers[0];
|
|
374
|
+
// 如果没有extent,直接设置source为undefined
|
|
375
|
+
if (!imageData.extent) {
|
|
376
|
+
existingLayer.setSource(undefined);
|
|
377
|
+
}
|
|
378
|
+
else {
|
|
379
|
+
// 创建新的source
|
|
380
|
+
const url = imageData.img || existingLayer.getSource()?.getUrl() || '';
|
|
381
|
+
const newSource = new ImageStatic({
|
|
382
|
+
url,
|
|
383
|
+
imageExtent: imageData.extent
|
|
384
|
+
});
|
|
385
|
+
existingLayer.setSource(newSource);
|
|
386
|
+
}
|
|
387
|
+
// 更新图层属性
|
|
388
|
+
this.updateImageLayerProperties(existingLayer, options);
|
|
389
|
+
return existingLayer;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* 创建新的图像图层
|
|
393
|
+
* @private
|
|
394
|
+
*/
|
|
395
|
+
createNewImageLayer(imageData, options) {
|
|
396
|
+
let source = undefined;
|
|
397
|
+
// 只有当extent存在时才创建ImageStatic source
|
|
398
|
+
if (imageData.extent) {
|
|
399
|
+
source = new ImageStatic({
|
|
400
|
+
url: imageData.img || '',
|
|
401
|
+
imageExtent: imageData.extent
|
|
402
|
+
});
|
|
355
403
|
}
|
|
356
|
-
const source = new ImageStatic({
|
|
357
|
-
url: imageData.img,
|
|
358
|
-
imageExtent: imageData.extent
|
|
359
|
-
});
|
|
360
404
|
const imageLayer = new ImageLayer({
|
|
361
405
|
source,
|
|
362
|
-
opacity:
|
|
363
|
-
visible:
|
|
406
|
+
opacity: options.opacity,
|
|
407
|
+
visible: options.visible
|
|
364
408
|
});
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
409
|
+
this.configureImageLayer(imageLayer, options);
|
|
410
|
+
return this.addImageLayerToMap(imageLayer, options);
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* 更新图层属性
|
|
414
|
+
* @private
|
|
415
|
+
*/
|
|
416
|
+
updateImageLayerProperties(layer, options) {
|
|
417
|
+
if (options.opacity !== undefined) {
|
|
418
|
+
layer.setOpacity(options.opacity);
|
|
419
|
+
}
|
|
420
|
+
if (options.visible !== undefined) {
|
|
421
|
+
layer.setVisible(options.visible);
|
|
422
|
+
}
|
|
423
|
+
if (options.zIndex !== undefined) {
|
|
424
|
+
layer.setZIndex(options.zIndex);
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* 配置图层基本属性
|
|
429
|
+
* @private
|
|
430
|
+
*/
|
|
431
|
+
configureImageLayer(layer, options) {
|
|
432
|
+
layer.set('name', options.layerName);
|
|
433
|
+
layer.set('layerName', options.layerName);
|
|
434
|
+
layer.setZIndex(options.zIndex);
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* 添加图层到地图并应用裁剪
|
|
438
|
+
* @private
|
|
439
|
+
*/
|
|
440
|
+
addImageLayerToMap(layer, options) {
|
|
441
|
+
if (options.mapClip && options.mapClipData) {
|
|
442
|
+
const clippedLayer = MapTools.setMapClip(layer, options.mapClipData);
|
|
371
443
|
this.map.addLayer(clippedLayer);
|
|
372
444
|
return clippedLayer;
|
|
373
445
|
}
|
|
374
|
-
this.map.addLayer(
|
|
375
|
-
return
|
|
446
|
+
this.map.addLayer(layer);
|
|
447
|
+
return layer;
|
|
376
448
|
}
|
|
377
449
|
/**
|
|
378
450
|
* 添加热力图图层
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "my-openlayer",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.3",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -13,14 +13,17 @@
|
|
|
13
13
|
"vue"
|
|
14
14
|
],
|
|
15
15
|
"files": [
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
16
|
+
"**/*",
|
|
17
|
+
"!scripts",
|
|
18
|
+
"!temp-publish"
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
21
|
"dev": "vite",
|
|
22
22
|
"build": "tsc",
|
|
23
|
-
"preview": "vite preview"
|
|
23
|
+
"preview": "vite preview",
|
|
24
|
+
"prepare-publish": "node scripts/prepare-publish.cjs",
|
|
25
|
+
"publish-flat": "npm run build && npm run prepare-publish && cd temp-publish && npm publish",
|
|
26
|
+
"publish-flat-dry": "npm run build && npm run prepare-publish && cd temp-publish && npm publish --dry-run"
|
|
24
27
|
},
|
|
25
28
|
"dependencies": {
|
|
26
29
|
"@turf/turf": "^7.2.0",
|
|
@@ -39,4 +42,4 @@
|
|
|
39
42
|
"peerDependencies": {
|
|
40
43
|
"ol": "^6.15.1"
|
|
41
44
|
}
|
|
42
|
-
}
|
|
45
|
+
}
|
|
@@ -90,9 +90,10 @@ export declare class ValidationUtils {
|
|
|
90
90
|
/**
|
|
91
91
|
* 验证图像数据
|
|
92
92
|
* @param imageData 图像数据
|
|
93
|
+
* @param allowEmptyImg 是否允许img为空
|
|
93
94
|
* @throws 如果图像数据无效则抛出异常
|
|
94
95
|
*/
|
|
95
|
-
static validateImageData(imageData: any): void;
|
|
96
|
+
static validateImageData(imageData: any, allowEmptyImg?: boolean): void;
|
|
96
97
|
/**
|
|
97
98
|
* 验证遮罩数据
|
|
98
99
|
* @param data 遮罩数据
|
|
@@ -180,13 +180,17 @@ export class ValidationUtils {
|
|
|
180
180
|
/**
|
|
181
181
|
* 验证图像数据
|
|
182
182
|
* @param imageData 图像数据
|
|
183
|
+
* @param allowEmptyImg 是否允许img为空
|
|
183
184
|
* @throws 如果图像数据无效则抛出异常
|
|
184
185
|
*/
|
|
185
|
-
static validateImageData(imageData) {
|
|
186
|
-
if (!imageData
|
|
187
|
-
throw new Error('Invalid image data:
|
|
186
|
+
static validateImageData(imageData, allowEmptyImg = false) {
|
|
187
|
+
if (!imageData) {
|
|
188
|
+
throw new Error('Invalid image data: imageData is required');
|
|
188
189
|
}
|
|
189
|
-
if (!
|
|
190
|
+
if (!allowEmptyImg && !imageData.img) {
|
|
191
|
+
throw new Error('Invalid image data: img is required');
|
|
192
|
+
}
|
|
193
|
+
if (imageData.extent && (!Array.isArray(imageData.extent) || imageData.extent.length !== 4)) {
|
|
190
194
|
throw new Error('Invalid extent: must be an array of 4 numbers [minX, minY, maxX, maxY]');
|
|
191
195
|
}
|
|
192
196
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|