cd-mapgis 1.0.62 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cd-mapgis",
3
- "version": "1.0.62",
3
+ "version": "1.0.64",
4
4
  "main": "./src/index.js",
5
5
  "types": "./src/index.d.ts",
6
6
  "type": "module",
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
  * 图层工具
@@ -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
  }