cd-mapgis 1.0.69 → 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 +1 -1
- package/src/InnerUtil.js +12 -1
- package/src/LayerUtil.js +14 -0
- package/src/MapView.js +53 -0
package/package.json
CHANGED
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,7 +71,7 @@ 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
|
// 将弧度转换为角度,并更新指北针旋转
|
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
|
@@ -273,4 +273,57 @@ export default class MapView {
|
|
|
273
273
|
this.map.getView().fit(this._reset_bounds, this.map.getSize());
|
|
274
274
|
}
|
|
275
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
|
+
}
|
|
276
329
|
}
|