cd-mapgis 1.0.68 → 1.0.70

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.68",
3
+ "version": "1.0.70",
4
4
  "main": "./src/index.js",
5
5
  "types": "./src/index.d.ts",
6
6
  "type": "module",
package/src/InnerUtil.js CHANGED
@@ -36,6 +36,17 @@ export default class InnerUtil {
36
36
  const wktFormat = new WKT();
37
37
  return wktFormat.writeGeometry(polygon);
38
38
  }
39
+ /**
40
+ * 获取点集合的wkt [[long,lat],[long,lat]]
41
+ * @param {*} p
42
+ */
43
+ static getWktByPoints(data) {
44
+ // 创建多边形几何对象
45
+ let polygon = new Polygon([data]);
46
+ // 转换为WKT格式
47
+ const wktFormat = new WKT();
48
+ return wktFormat.writeGeometry(polygon);
49
+ }
39
50
  /**
40
51
  * 注册指北针
41
52
  * .compass-icon {
@@ -60,12 +71,12 @@ export default class InnerUtil {
60
71
  map.getView().on('change:rotation', function () {
61
72
  let compassIcon = document.getElementById(p.compassIconId);
62
73
  if (!compassIcon) {
63
- console.error("未获取到dom元素:" + p.compassIconId);
74
+ console.error("未获取到dom元素:" + p.compassIconId);
64
75
  }
65
76
  let rotation = map.getView().getRotation();
66
77
  // 将弧度转换为角度,并更新指北针旋转
67
- // 注意:PNG图片需要旋转相反方向,因为地图旋转时指北针应保持指向北方
68
- const rotationDeg = -rotation * (180 / Math.PI);
78
+ // 注意:PNG图片需要旋转方向,因为地图旋转时指北针应保持指向北方
79
+ const rotationDeg = rotation * (180 / Math.PI);
69
80
  compassIcon.style.transform = `rotate(${rotationDeg}deg)`;
70
81
  });
71
82
  // 点击指北针重置地图方向
package/src/LayerUtil.js CHANGED
@@ -330,4 +330,18 @@ export default class LayerUtil {
330
330
  style: StyleUtil.getPolygonStyle(p)
331
331
  });
332
332
  }
333
+ /**
334
+ * [[long,lat],[long,lat]]
335
+ * @param {*} p
336
+ * @returns
337
+ */
338
+ static getPolygonLayerByPoints(p) {
339
+ let polygon = new Polygon([p.data]);
340
+ let feature = new Feature({ geometry: polygon });
341
+ let vectorSource = new VectorSource({ features: [feature] });
342
+ return new VectorLayer({
343
+ source: vectorSource,
344
+ style: StyleUtil.getPolygonStyle(p)
345
+ });
346
+ }
333
347
  }
package/src/MapView.js CHANGED
@@ -12,6 +12,7 @@ import * as OlInteraction from 'ol/interaction';
12
12
  */
13
13
  export default class MapView {
14
14
  static Instance = null;//主地图,一般用于只操作一个地图的情况
15
+ static CHINA_EXTENT = [73.66, 3.86, 135.05, 53.55];//中国范围
15
16
  constructor(p) {
16
17
  this.params = p;
17
18
  this.view = null;
@@ -59,6 +60,11 @@ export default class MapView {
59
60
  if (interactions) {
60
61
  viewP.interactions = interactions;
61
62
  }
63
+ if (p.chinaExtent) {
64
+ viewP.extent = MapView.CHINA_EXTENT;
65
+ viewP.constrainOnlyCenter = true;// 限制整个视图范围,而不仅仅是中心点
66
+ viewP.smoothExtentConstraint = interactions;// 平滑约束
67
+ }
62
68
  this.view = new View(viewP);
63
69
  }
64
70
  this.target = p.target ? p.target : 'map';//地图div的id
@@ -267,4 +273,57 @@ export default class MapView {
267
273
  this.map.getView().fit(this._reset_bounds, this.map.getSize());
268
274
  }
269
275
  }
276
+ //获取可视范围的矩形多边形
277
+ getVisiblePolygon() {
278
+ const view = this.map.getView();
279
+ const size = this.map.getSize();
280
+ const center = view.getCenter();
281
+ const resolution = view.getResolution();
282
+ const rotation = view.getRotation();
283
+ // 如果没有旋转,直接使用内置方法
284
+ if (rotation === 0 || Math.abs(rotation) < 1e-10) {
285
+ let d = view.calculateExtent(size);
286
+ let minX = d[0];
287
+ let minY = d[1];
288
+ let maxX = d[2];
289
+ let maxY = d[3];
290
+ return [
291
+ [minX, minY],
292
+ [maxX, minY],
293
+ [maxX, maxY],
294
+ [minX, maxY],
295
+ [minX, minY]
296
+ ];
297
+ }
298
+ // 计算四个角点在地图坐标系中的位置
299
+ const halfWidth = (size[0] * resolution) / 2;
300
+ const halfHeight = (size[1] * resolution) / 2;
301
+ // 原始四个角点(相对于中心点)
302
+ const unrotatedCorners = [
303
+ [-halfWidth, -halfHeight], // 左下
304
+ [halfWidth, -halfHeight], // 右下
305
+ [halfWidth, halfHeight], // 右上
306
+ [-halfWidth, halfHeight] // 左上
307
+ ];
308
+ const cos = Math.cos(rotation);
309
+ const sin = Math.sin(rotation);
310
+ const centerX = center[0];
311
+ const centerY = center[1];
312
+ // 旋转并转换到地图坐标系
313
+ let rotatedCorners = unrotatedCorners.map(corner => {
314
+ const x = corner[0];
315
+ const y = corner[1];
316
+ // 旋转变换
317
+ const rotatedX = x * cos - y * sin;
318
+ const rotatedY = x * sin + y * cos;
319
+ // 转换为地图坐标
320
+ return [
321
+ centerX + rotatedX,
322
+ centerY + rotatedY
323
+ ];
324
+ });
325
+ // 返回四个角点坐标(旋转后的实际矩形)
326
+ rotatedCorners.push(rotatedCorners[0]);//封闭
327
+ return rotatedCorners;
328
+ }
270
329
  }