cd-mapgis 1.0.69 → 1.0.71
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 +19 -2
- 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
|
@@ -202,6 +202,7 @@ export default class LayerUtil {
|
|
|
202
202
|
let geometry = geoJSON.readGeometry(p.data);
|
|
203
203
|
let feature = new Feature({ geometry: geometry });
|
|
204
204
|
let vectorSource = new VectorSource({ features: [feature] });
|
|
205
|
+
p.style = p.style ? p.style : StyleUtil.getViewOnTemplayerStyle();
|
|
205
206
|
let layer = new VectorLayer({
|
|
206
207
|
source: vectorSource,
|
|
207
208
|
style: p.style
|
|
@@ -217,6 +218,7 @@ export default class LayerUtil {
|
|
|
217
218
|
let geometry = wktFormat.readGeometry(p.data);
|
|
218
219
|
let feature = new Feature({ geometry: geometry });
|
|
219
220
|
let vectorSource = new VectorSource({ features: [feature] });
|
|
221
|
+
p.style = p.style ? p.style : StyleUtil.getViewOnTemplayerStyle();
|
|
220
222
|
let layer = new VectorLayer({
|
|
221
223
|
source: vectorSource,
|
|
222
224
|
style: p.style
|
|
@@ -232,9 +234,10 @@ export default class LayerUtil {
|
|
|
232
234
|
let geometry = new LineString(coordinates);
|
|
233
235
|
let feature = new Feature({ geometry: geometry });
|
|
234
236
|
let vectorSource = new VectorSource({ features: [feature] });
|
|
237
|
+
p.style = p.style ? p.style : StyleUtil.getPointStyle(p);
|
|
235
238
|
let layer = new VectorLayer({
|
|
236
239
|
source: vectorSource,
|
|
237
|
-
style:
|
|
240
|
+
style: p.style
|
|
238
241
|
});
|
|
239
242
|
return { layer: layer, geometry: geometry };
|
|
240
243
|
}
|
|
@@ -242,7 +245,7 @@ export default class LayerUtil {
|
|
|
242
245
|
* 将geoJson的点集合数据包装为一个图层
|
|
243
246
|
* @param {*} p {geoList:[],img:{url,anchor},text:{str,font,color,offsetY}}
|
|
244
247
|
*/
|
|
245
|
-
static getJsonPointsLayer(p) {
|
|
248
|
+
static getJsonPointsLayer(p) {
|
|
246
249
|
let geoJSON = new GeoJSON();
|
|
247
250
|
let features = [];
|
|
248
251
|
for (let i = 0; i < p.geoList.length; i++) {
|
|
@@ -330,4 +333,18 @@ export default class LayerUtil {
|
|
|
330
333
|
style: StyleUtil.getPolygonStyle(p)
|
|
331
334
|
});
|
|
332
335
|
}
|
|
336
|
+
/**
|
|
337
|
+
* [[long,lat],[long,lat]]
|
|
338
|
+
* @param {*} p
|
|
339
|
+
* @returns
|
|
340
|
+
*/
|
|
341
|
+
static getPolygonLayerByPoints(p) {
|
|
342
|
+
let polygon = new Polygon([p.data]);
|
|
343
|
+
let feature = new Feature({ geometry: polygon });
|
|
344
|
+
let vectorSource = new VectorSource({ features: [feature] });
|
|
345
|
+
return new VectorLayer({
|
|
346
|
+
source: vectorSource,
|
|
347
|
+
style: StyleUtil.getPolygonStyle(p)
|
|
348
|
+
});
|
|
349
|
+
}
|
|
333
350
|
}
|
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
|
}
|