cd-mapgis 1.0.64 → 1.0.66
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 +1 -1
- package/src/InnerUtil.js +39 -0
- package/src/LayerUtil.js +16 -0
- package/src/MapView.js +19 -4
- package/src/index.js +3 -1
package/package.json
CHANGED
package/src/InnerUtil.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Polygon from 'ol/geom/Polygon.js';
|
|
2
2
|
import { WKT } from 'ol/format';
|
|
3
|
+
import MapView from './MapView.js';
|
|
3
4
|
|
|
4
5
|
export default class InnerUtil {
|
|
5
6
|
/**
|
|
@@ -35,4 +36,42 @@ export default class InnerUtil {
|
|
|
35
36
|
const wktFormat = new WKT();
|
|
36
37
|
return wktFormat.writeGeometry(polygon);
|
|
37
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* 注册指北针
|
|
41
|
+
* .compass-icon {
|
|
42
|
+
width: 100%;
|
|
43
|
+
height: 100%;
|
|
44
|
+
transition: transform 0.3s ease-out;
|
|
45
|
+
background-image: url('compass.png');
|
|
46
|
+
background-size: contain;
|
|
47
|
+
background-repeat: no-repeat;
|
|
48
|
+
background-position: center;
|
|
49
|
+
}
|
|
50
|
+
* @param {*} p
|
|
51
|
+
*/
|
|
52
|
+
static registCompass(p) {
|
|
53
|
+
let map = p.map ? p.map : MapView.Instance.map;
|
|
54
|
+
// 获取指北针元素
|
|
55
|
+
const compassElement = document.getElementById(p.compassId);
|
|
56
|
+
const compassIcon = compassElement.querySelector(p.compassIconStyle);
|
|
57
|
+
// 监听地图视图的旋转变化
|
|
58
|
+
map.getView().on('change:rotation', function () {
|
|
59
|
+
const rotation = map.getView().getRotation();
|
|
60
|
+
// 将弧度转换为角度,并更新指北针旋转
|
|
61
|
+
// 注意:PNG图片需要旋转相反方向,因为地图旋转时指北针应保持指向北方
|
|
62
|
+
const rotationDeg = -rotation * (180 / Math.PI);
|
|
63
|
+
compassIcon.style.transform = `rotate(${rotationDeg}deg)`;
|
|
64
|
+
});
|
|
65
|
+
// 点击指北针重置地图方向
|
|
66
|
+
compassElement.addEventListener('click', function () {
|
|
67
|
+
// 平滑动画重置旋转角度
|
|
68
|
+
const view = map.getView();
|
|
69
|
+
if (view.getRotation() !== 0) {
|
|
70
|
+
view.animate({
|
|
71
|
+
rotation: 0,
|
|
72
|
+
duration: 500
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
38
77
|
}
|
package/src/LayerUtil.js
CHANGED
|
@@ -14,6 +14,7 @@ import VectorLayer from 'ol/layer/Vector.js';
|
|
|
14
14
|
import StyleUtil from './StyleUtil.js';
|
|
15
15
|
import LineString from 'ol/geom/LineString.js';
|
|
16
16
|
import Polygon from 'ol/geom/Polygon.js';
|
|
17
|
+
import { WKT } from 'ol/format';
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* 图层工具
|
|
@@ -207,6 +208,21 @@ export default class LayerUtil {
|
|
|
207
208
|
});
|
|
208
209
|
return { layer: layer, geometry: geometry };
|
|
209
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* 将单个wkt数据包装为一个图层
|
|
213
|
+
* @param {*} json
|
|
214
|
+
*/
|
|
215
|
+
static getWktLayer(p) {
|
|
216
|
+
let wktFormat = new WKT();
|
|
217
|
+
let geometry = wktFormat.readGeometry(p.data);
|
|
218
|
+
let feature = new Feature({ geometry: geometry });
|
|
219
|
+
let vectorSource = new VectorSource({ features: [feature] });
|
|
220
|
+
let layer = new VectorLayer({
|
|
221
|
+
source: vectorSource,
|
|
222
|
+
style: p.style
|
|
223
|
+
});
|
|
224
|
+
return { layer: layer, geometry: geometry };
|
|
225
|
+
}
|
|
210
226
|
/**
|
|
211
227
|
* [[116.4074, 39.9042], [121.4737, 31.2304]]
|
|
212
228
|
* @param {*} p
|
package/src/MapView.js
CHANGED
|
@@ -5,6 +5,7 @@ import StyleUtil from './StyleUtil.js';
|
|
|
5
5
|
import MapDrawUtil from './MapDrawUtil.js';
|
|
6
6
|
import SwipeUtil from './SwipeUtil.js';
|
|
7
7
|
import DragPan from 'ol/interaction/DragPan.js';
|
|
8
|
+
import * as OlInteraction from 'ol/interaction';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* ol地图显示
|
|
@@ -34,17 +35,31 @@ export default class MapView {
|
|
|
34
35
|
}
|
|
35
36
|
//初始化地图及其他参数
|
|
36
37
|
_init(p) {
|
|
38
|
+
// 创建地图交互
|
|
39
|
+
let interactions = null;
|
|
40
|
+
if (p.mobileRotate) {
|
|
41
|
+
interactions = OlInteraction.defaults({
|
|
42
|
+
altShiftDragRotate: false, // 禁用Alt+Shift+拖拽旋转
|
|
43
|
+
pinchRotate: true, // 启用双指旋转
|
|
44
|
+
pinchZoom: true, // 启用双指缩放
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
37
48
|
if (p.view) {
|
|
38
49
|
this.view = p.view;
|
|
39
50
|
} else {
|
|
40
51
|
let center = p.center ? p.center : [104.0633664, 30.6598344];//地图初始中心点(默认天府广场)
|
|
41
52
|
let zoom = p.zoom ? p.zoom : 16; //地图初始显示级数
|
|
42
53
|
let projection = p.projection ? p.projection : 'EPSG:4326';
|
|
43
|
-
|
|
54
|
+
let viewP = {
|
|
44
55
|
center: center,
|
|
45
56
|
zoom: zoom,
|
|
46
57
|
projection: projection
|
|
47
|
-
}
|
|
58
|
+
};
|
|
59
|
+
if (interactions) {
|
|
60
|
+
viewP.interactions = interactions;
|
|
61
|
+
}
|
|
62
|
+
this.view = new View(viewP);
|
|
48
63
|
}
|
|
49
64
|
this.target = p.target ? p.target : 'map';//地图div的id
|
|
50
65
|
let layers = p.layers ? p.layers : [];
|
|
@@ -83,9 +98,9 @@ export default class MapView {
|
|
|
83
98
|
let res;
|
|
84
99
|
if (p.type == 'jsonPoints') {
|
|
85
100
|
res = LayerUtil.getJsonPointsLayer(p);
|
|
86
|
-
} else if(p.type == 'tracePoints'){
|
|
101
|
+
} else if (p.type == 'tracePoints') {
|
|
87
102
|
res = LayerUtil.getTracePointsLayer(p);
|
|
88
|
-
}else {
|
|
103
|
+
} else {
|
|
89
104
|
res = LayerUtil.getJsonLayer(p);
|
|
90
105
|
}
|
|
91
106
|
this._view_templayer = res.layer;
|
package/src/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import LayerUtil from './LayerUtil.js';
|
|
|
5
5
|
import Overlay from './Overlay.js';
|
|
6
6
|
import HttpUtil from './HttpUtil.js';
|
|
7
7
|
import InnerUtil from './InnerUtil.js';
|
|
8
|
+
import StyleUtil from './StyleUtil.js';
|
|
8
9
|
|
|
9
10
|
// 导出模块
|
|
10
11
|
export {
|
|
@@ -13,5 +14,6 @@ export {
|
|
|
13
14
|
LayerUtil,
|
|
14
15
|
Overlay,
|
|
15
16
|
HttpUtil,
|
|
16
|
-
InnerUtil
|
|
17
|
+
InnerUtil,
|
|
18
|
+
StyleUtil
|
|
17
19
|
};
|