cd-mapgis 1.0.66 → 1.0.68

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.66",
3
+ "version": "1.0.68",
4
4
  "main": "./src/index.js",
5
5
  "types": "./src/index.d.ts",
6
6
  "type": "module",
package/src/InnerUtil.js CHANGED
@@ -53,10 +53,16 @@ export default class InnerUtil {
53
53
  let map = p.map ? p.map : MapView.Instance.map;
54
54
  // 获取指北针元素
55
55
  const compassElement = document.getElementById(p.compassId);
56
- const compassIcon = compassElement.querySelector(p.compassIconStyle);
56
+ if (!compassElement) {
57
+ console.error("未获取到dom元素:" + p.compassId);
58
+ }
57
59
  // 监听地图视图的旋转变化
58
60
  map.getView().on('change:rotation', function () {
59
- const rotation = map.getView().getRotation();
61
+ let compassIcon = document.getElementById(p.compassIconId);
62
+ if (!compassIcon) {
63
+ console.error("未获取到dom元素:" + p.compassIconId);
64
+ }
65
+ let rotation = map.getView().getRotation();
60
66
  // 将弧度转换为角度,并更新指北针旋转
61
67
  // 注意:PNG图片需要旋转相反方向,因为地图旋转时指北针应保持指向北方
62
68
  const rotationDeg = -rotation * (180 / Math.PI);
@@ -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/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
  };