cd-mapgis 1.0.65 → 1.0.67

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,6 +1,6 @@
1
1
  {
2
2
  "name": "cd-mapgis",
3
- "version": "1.0.65",
3
+ "version": "1.0.67",
4
4
  "main": "./src/index.js",
5
5
  "types": "./src/index.d.ts",
6
6
  "type": "module",
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
  }
@@ -0,0 +1,49 @@
1
+ import VectorSource from 'ol/source/Vector.js';
2
+ import VectorLayer from 'ol/layer/Vector.js';
3
+ import Feature from 'ol/Feature.js';
4
+ import MapView from './MapView.js';
5
+ import Point from 'ol/geom/Point.js';
6
+ import Style from 'ol/style/Style.js';
7
+ import Icon from 'ol/style/Icon.js';
8
+
9
+ export default class Location {
10
+ constructor(p) {
11
+ this.param = p;
12
+ this.img = p.img;
13
+ this.vectorSource = null;
14
+ this.vectorLayer = null;
15
+ this.map = p.map ? p.map : MapView.Instance.map;
16
+ }
17
+
18
+ /**
19
+ * [lon,lat]
20
+ * @param {*} point
21
+ */
22
+ mark(point) {
23
+ if (!this.vectorLayer) {
24
+ let vectorSource = new VectorSource();
25
+ let vectorLayer = new VectorLayer({
26
+ source: vectorSource
27
+ });
28
+ this.map.addLayer(vectorLayer);
29
+ this.vectorSource = vectorSource;
30
+ this.vectorLayer = vectorLayer;
31
+ }
32
+ this.vectorSource.clear();
33
+ // 使用外部圆点图标
34
+ let dotFeature = new Feature({
35
+ geometry: new Point(point)
36
+ });
37
+ dotFeature.setStyle(new Style({
38
+ image: new Icon({
39
+ src: this.img, // 外部图标路径
40
+ scale: 1, // 缩放比例
41
+ anchor: [0.5, 0.5], // 锚点为中心
42
+ anchorOrigin: 'center',
43
+ anchorXUnits: 'fraction',
44
+ anchorYUnits: 'fraction'
45
+ })
46
+ }));
47
+ this.vectorSource.addFeature(dotFeature);
48
+ }
49
+ }
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
- this.view = new View({
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
@@ -6,6 +6,7 @@ import Overlay from './Overlay.js';
6
6
  import HttpUtil from './HttpUtil.js';
7
7
  import InnerUtil from './InnerUtil.js';
8
8
  import StyleUtil from './StyleUtil.js';
9
+ import Location from './Location.js';
9
10
 
10
11
  // 导出模块
11
12
  export {
@@ -15,5 +16,6 @@ export {
15
16
  Overlay,
16
17
  HttpUtil,
17
18
  InnerUtil,
18
- StyleUtil
19
+ StyleUtil,
20
+ Location
19
21
  };