cd-mapgis 1.0.61 → 1.0.64
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 +25 -0
- package/src/LayerUtil.js +46 -1
package/package.json
CHANGED
package/src/InnerUtil.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import Polygon from 'ol/geom/Polygon.js';
|
|
2
|
+
import { WKT } from 'ol/format';
|
|
3
|
+
|
|
1
4
|
export default class InnerUtil {
|
|
2
5
|
/**
|
|
3
6
|
* 替换geoServer地址的前缀
|
|
@@ -10,4 +13,26 @@ export default class InnerUtil {
|
|
|
10
13
|
let index = url.indexOf('/geoserver');
|
|
11
14
|
return host + url.substr(index);
|
|
12
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* 将矩形范围转换为wkt
|
|
18
|
+
* [minX, minY, maxX, maxY]
|
|
19
|
+
* @param {*} rect
|
|
20
|
+
*/
|
|
21
|
+
static getWktByRect(rect) {
|
|
22
|
+
let minX = rect[0];
|
|
23
|
+
let minY = rect[1];
|
|
24
|
+
let maxX = rect[2];
|
|
25
|
+
let maxY = rect[3];
|
|
26
|
+
// 创建多边形几何对象
|
|
27
|
+
let polygon = new Polygon([[
|
|
28
|
+
[minX, minY],
|
|
29
|
+
[maxX, minY],
|
|
30
|
+
[maxX, maxY],
|
|
31
|
+
[minX, maxY],
|
|
32
|
+
[minX, minY]
|
|
33
|
+
]]);
|
|
34
|
+
// 转换为WKT格式
|
|
35
|
+
const wktFormat = new WKT();
|
|
36
|
+
return wktFormat.writeGeometry(polygon);
|
|
37
|
+
}
|
|
13
38
|
}
|
package/src/LayerUtil.js
CHANGED
|
@@ -13,6 +13,7 @@ import VectorSource from 'ol/source/Vector.js';
|
|
|
13
13
|
import VectorLayer from 'ol/layer/Vector.js';
|
|
14
14
|
import StyleUtil from './StyleUtil.js';
|
|
15
15
|
import LineString from 'ol/geom/LineString.js';
|
|
16
|
+
import Polygon from 'ol/geom/Polygon.js';
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* 图层工具
|
|
@@ -217,7 +218,7 @@ export default class LayerUtil {
|
|
|
217
218
|
let vectorSource = new VectorSource({ features: [feature] });
|
|
218
219
|
let layer = new VectorLayer({
|
|
219
220
|
source: vectorSource,
|
|
220
|
-
style: p
|
|
221
|
+
style: StyleUtil.getPointStyle(p)
|
|
221
222
|
});
|
|
222
223
|
return { layer: layer, geometry: geometry };
|
|
223
224
|
}
|
|
@@ -269,4 +270,48 @@ export default class LayerUtil {
|
|
|
269
270
|
source: vectorSource
|
|
270
271
|
});
|
|
271
272
|
}
|
|
273
|
+
/**
|
|
274
|
+
* p.data:[[[x,y],[x,y]],[]]
|
|
275
|
+
* p.style
|
|
276
|
+
* @param {*} p
|
|
277
|
+
*/
|
|
278
|
+
static getPolygonsLayer(p) {
|
|
279
|
+
let features = [];
|
|
280
|
+
for (let i = 0; i < p.data.length; i++) {
|
|
281
|
+
let polygon = new Polygon(p.data[i]);
|
|
282
|
+
let feature = new Feature({ geometry: polygon });
|
|
283
|
+
features.push(feature);
|
|
284
|
+
}
|
|
285
|
+
let vectorSource = new VectorSource({ features: features });
|
|
286
|
+
return new VectorLayer({
|
|
287
|
+
source: vectorSource,
|
|
288
|
+
style: StyleUtil.getPolygonStyle(p)
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* 获取将矩形范围图层
|
|
293
|
+
* p.data:[minX, minY, maxX, maxY]
|
|
294
|
+
* p.style
|
|
295
|
+
* @param {*} p
|
|
296
|
+
* @returns
|
|
297
|
+
*/
|
|
298
|
+
static getPolygonLayerByRect(p) {
|
|
299
|
+
let minX = p.data[0];
|
|
300
|
+
let minY = p.data[1];
|
|
301
|
+
let maxX = p.data[2];
|
|
302
|
+
let maxY = p.data[3];
|
|
303
|
+
let polygon = new Polygon([[
|
|
304
|
+
[minX, minY],
|
|
305
|
+
[maxX, minY],
|
|
306
|
+
[maxX, maxY],
|
|
307
|
+
[minX, maxY],
|
|
308
|
+
[minX, minY]
|
|
309
|
+
]]);
|
|
310
|
+
let feature = new Feature({ geometry: polygon });
|
|
311
|
+
let vectorSource = new VectorSource({ features: [feature] });
|
|
312
|
+
return new VectorLayer({
|
|
313
|
+
source: vectorSource,
|
|
314
|
+
style: StyleUtil.getPolygonStyle(p)
|
|
315
|
+
});
|
|
316
|
+
}
|
|
272
317
|
}
|