cd-mapgis 1.0.62 → 1.0.65
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 +61 -0
- package/src/index.js +3 -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,8 @@ 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';
|
|
17
|
+
import { WKT } from 'ol/format';
|
|
16
18
|
|
|
17
19
|
/**
|
|
18
20
|
* 图层工具
|
|
@@ -206,6 +208,21 @@ export default class LayerUtil {
|
|
|
206
208
|
});
|
|
207
209
|
return { layer: layer, geometry: geometry };
|
|
208
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* 将单个wkt数据包装为一个图层
|
|
213
|
+
* @param {*} json
|
|
214
|
+
*/
|
|
215
|
+
static getWktLayer(p) {
|
|
216
|
+
let wktFormat = new WKT();
|
|
217
|
+
let geometry = wktFormat.readGeometry(p.data);
|
|
218
|
+
let feature = new Feature({ geometry: geometry });
|
|
219
|
+
let vectorSource = new VectorSource({ features: [feature] });
|
|
220
|
+
let layer = new VectorLayer({
|
|
221
|
+
source: vectorSource,
|
|
222
|
+
style: p.style
|
|
223
|
+
});
|
|
224
|
+
return { layer: layer, geometry: geometry };
|
|
225
|
+
}
|
|
209
226
|
/**
|
|
210
227
|
* [[116.4074, 39.9042], [121.4737, 31.2304]]
|
|
211
228
|
* @param {*} p
|
|
@@ -269,4 +286,48 @@ export default class LayerUtil {
|
|
|
269
286
|
source: vectorSource
|
|
270
287
|
});
|
|
271
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
* p.data:[[[x,y],[x,y]],[]]
|
|
291
|
+
* p.style
|
|
292
|
+
* @param {*} p
|
|
293
|
+
*/
|
|
294
|
+
static getPolygonsLayer(p) {
|
|
295
|
+
let features = [];
|
|
296
|
+
for (let i = 0; i < p.data.length; i++) {
|
|
297
|
+
let polygon = new Polygon(p.data[i]);
|
|
298
|
+
let feature = new Feature({ geometry: polygon });
|
|
299
|
+
features.push(feature);
|
|
300
|
+
}
|
|
301
|
+
let vectorSource = new VectorSource({ features: features });
|
|
302
|
+
return new VectorLayer({
|
|
303
|
+
source: vectorSource,
|
|
304
|
+
style: StyleUtil.getPolygonStyle(p)
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* 获取将矩形范围图层
|
|
309
|
+
* p.data:[minX, minY, maxX, maxY]
|
|
310
|
+
* p.style
|
|
311
|
+
* @param {*} p
|
|
312
|
+
* @returns
|
|
313
|
+
*/
|
|
314
|
+
static getPolygonLayerByRect(p) {
|
|
315
|
+
let minX = p.data[0];
|
|
316
|
+
let minY = p.data[1];
|
|
317
|
+
let maxX = p.data[2];
|
|
318
|
+
let maxY = p.data[3];
|
|
319
|
+
let polygon = new Polygon([[
|
|
320
|
+
[minX, minY],
|
|
321
|
+
[maxX, minY],
|
|
322
|
+
[maxX, maxY],
|
|
323
|
+
[minX, maxY],
|
|
324
|
+
[minX, minY]
|
|
325
|
+
]]);
|
|
326
|
+
let feature = new Feature({ geometry: polygon });
|
|
327
|
+
let vectorSource = new VectorSource({ features: [feature] });
|
|
328
|
+
return new VectorLayer({
|
|
329
|
+
source: vectorSource,
|
|
330
|
+
style: StyleUtil.getPolygonStyle(p)
|
|
331
|
+
});
|
|
332
|
+
}
|
|
272
333
|
}
|
package/src/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import LayerUtil from './LayerUtil.js';
|
|
|
5
5
|
import Overlay from './Overlay.js';
|
|
6
6
|
import HttpUtil from './HttpUtil.js';
|
|
7
7
|
import InnerUtil from './InnerUtil.js';
|
|
8
|
+
import StyleUtil from './StyleUtil.js';
|
|
8
9
|
|
|
9
10
|
// 导出模块
|
|
10
11
|
export {
|
|
@@ -13,5 +14,6 @@ export {
|
|
|
13
14
|
LayerUtil,
|
|
14
15
|
Overlay,
|
|
15
16
|
HttpUtil,
|
|
16
|
-
InnerUtil
|
|
17
|
+
InnerUtil,
|
|
18
|
+
StyleUtil
|
|
17
19
|
};
|