cd-mapgis 1.0.6 → 1.0.7

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/package.json CHANGED
@@ -1,17 +1,17 @@
1
- {
2
- "name": "cd-mapgis",
3
- "version": "1.0.6",
4
- "main": "./src/index.js",
5
- "types": "./src/index.d.ts",
6
- "type": "module",
7
- "scripts": {
8
- "test": "echo \"Error: no test specified\" && exit 1"
9
- },
10
- "keywords": [],
11
- "author": "cdzd",
12
- "license": "ISC",
13
- "description": "",
14
- "dependencies": {
15
- "ol": "^8.1.0"
16
- }
17
- }
1
+ {
2
+ "name": "cd-mapgis",
3
+ "version": "1.0.7",
4
+ "main": "./src/index.js",
5
+ "types": "./src/index.d.ts",
6
+ "type": "module",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "keywords": [],
11
+ "author": "cdzd",
12
+ "license": "ISC",
13
+ "description": "",
14
+ "dependencies": {
15
+ "ol": "^8.1.0"
16
+ }
17
+ }
package/src/OM.js CHANGED
@@ -8,6 +8,7 @@ import Fill from 'ol/style/Fill.js';
8
8
  import VectorLayer from 'ol/layer/Vector.js';
9
9
  import View from 'ol/View.js';
10
10
  import Map from 'ol/Map.js';
11
+ import Overlay from './Overlay.js';
11
12
 
12
13
  /**
13
14
  * OM
@@ -104,6 +105,14 @@ class OM {
104
105
  var newMaxY = centerY + newHeight / 2;
105
106
  return [newMinX, newMinY, newMaxX, newMaxY];
106
107
  }
108
+ /**
109
+ * 向地图添加一个覆盖物
110
+ * 删除所有的覆盖物:OM.map.getOverlays().clear();
111
+ * @param {*} p
112
+ */
113
+ static addOverlay(p) {
114
+ new Overlay(p).addToMap(OM.map);
115
+ }
107
116
  }
108
117
 
109
118
  // 导出模块
package/src/Overlay.js ADDED
@@ -0,0 +1,45 @@
1
+ import Overlay from 'ol/Overlay.js';
2
+
3
+ /**
4
+ * 覆盖层工具
5
+ */
6
+ export default class Overlay {
7
+ /**
8
+ * [{html:'<img src="11.png" style="width: 32px; height: 32px;">',point:[105.09188461513055, 29.60190582196913]}]
9
+ * @param {*} data
10
+ */
11
+ constructor(data) {
12
+ this.data = data.length ? data : [data];
13
+ this.items = [];//存放所有的覆盖层
14
+ for (let i = 0; i < data.length; i++) {
15
+ let d = data[i];
16
+ let imageElement = document.createElement('div');
17
+ imageElement.innerHTML = d.html;
18
+ let positioning = d.positioning ? d.positioning : 'center-center';
19
+ let imageOverlay = new Overlay({
20
+ position: d.point, // 指定经纬度坐标
21
+ element: imageElement,
22
+ positioning: positioning // 定位方式
23
+ });
24
+ this.items.push(imageOverlay);
25
+ }
26
+ }
27
+ /**
28
+ * 添加到地图
29
+ * @param {*} map
30
+ */
31
+ addToMap(map) {
32
+ for (let i = 0; i < this.items.length; i++) {
33
+ map.addOverlay(this.items[i]);
34
+ }
35
+ }
36
+ /**
37
+ * 从地图上删除
38
+ * @param {*} map
39
+ */
40
+ remove(map) {
41
+ for (let i = 0; i < this.items.length; i++) {
42
+ map.removeOverlay(this.items[i]);
43
+ }
44
+ }
45
+ }
package/src/index.js CHANGED
@@ -1,9 +1,11 @@
1
- // 使用 ES 模块系统
2
- import OM from './OM.js';
3
- import LayerUtil from './LayerUtil.js';
4
-
5
- // 导出模块
6
- export {
7
- OM,
8
- LayerUtil
1
+ // 使用 ES 模块系统
2
+ import OM from './OM.js';
3
+ import LayerUtil from './LayerUtil.js';
4
+ import Overlay from './Overlay.js';
5
+
6
+ // 导出模块
7
+ export {
8
+ OM,
9
+ LayerUtil,
10
+ Overlay
9
11
  };
package/test-om.js CHANGED
@@ -8,4 +8,4 @@ console.log('OM 类定义:', OM);
8
8
  // 测试调用静态方法(不执行实际初始化,只检查方法是否存在)
9
9
  console.log('OM.initMap 存在:', typeof OM.initMap === 'function');
10
10
 
11
- console.log('测试完成,请检查输出结果。');
11
+ console.log('测试完成,请检查输出结果。');