cd-mapgis 1.0.5 → 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 +17 -17
- package/src/OM.js +11 -2
- package/src/Overlay.js +45 -0
- package/src/index.js +10 -8
- package/test-om.js +1 -1
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "cd-mapgis",
|
|
3
|
-
"version": "1.0.
|
|
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
|
|
@@ -24,7 +25,7 @@ class OM {
|
|
|
24
25
|
let zoom = p.zoom ? p.zoom : 16; //地图初始显示级数
|
|
25
26
|
let projection = p.projection ? p.projection : 'EPSG:4326';
|
|
26
27
|
let layers = p.layers ? p.layers : [];
|
|
27
|
-
|
|
28
|
+
OM.view = new View({
|
|
28
29
|
center: center,
|
|
29
30
|
zoom: zoom,
|
|
30
31
|
projection: projection
|
|
@@ -33,7 +34,7 @@ class OM {
|
|
|
33
34
|
target: target,
|
|
34
35
|
controls: [],
|
|
35
36
|
layers: layers,
|
|
36
|
-
view: view,
|
|
37
|
+
view: OM.view,
|
|
37
38
|
});
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
@@ -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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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