cd-mapgis 1.0.36 → 1.0.37

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.36",
3
+ "version": "1.0.37",
4
4
  "main": "./src/index.js",
5
5
  "types": "./src/index.d.ts",
6
6
  "type": "module",
package/src/LayerUtil.js CHANGED
@@ -11,6 +11,7 @@ import GeoJSON from 'ol/format/GeoJSON.js';
11
11
  import Feature from 'ol/Feature.js';
12
12
  import VectorSource from 'ol/source/Vector.js';
13
13
  import VectorLayer from 'ol/layer/Vector.js';
14
+ import StyleUtil from './StyleUtil.js';
14
15
 
15
16
  /**
16
17
  * 图层工具
@@ -190,11 +191,12 @@ export default class LayerUtil {
190
191
  return null;
191
192
  }
192
193
  /**
193
- * geoJson数据包装为一个图层
194
+ * 将单个geoJson数据包装为一个图层
194
195
  * @param {*} json
195
196
  */
196
197
  static getJsonLayer(p) {
197
- let geometry = new GeoJSON().readGeometry(p.data);
198
+ let geoJSON = new GeoJSON();
199
+ let geometry = geoJSON.readGeometry(p.data);
198
200
  let feature = new Feature({ geometry: geometry });
199
201
  let vectorSource = new VectorSource({ features: [feature] });
200
202
  let layer = new VectorLayer({
@@ -203,4 +205,43 @@ export default class LayerUtil {
203
205
  });
204
206
  return { layer: layer, geometry: geometry };
205
207
  }
208
+ /**
209
+ * 将geoJson的点集合数据包装为一个图层
210
+ * @param {*} p {geoJsons:[],img:{url,anchor},text:{str,font,color,offsetY}}
211
+ */
212
+ static getJsonPointsLayer(p) {
213
+ let geoJSON = new GeoJSON();
214
+ let vectorSource = new VectorSource({ features: [] });
215
+ let layer = new VectorLayer({
216
+ source: vectorSource,
217
+ style: StyleUtil.getPointStyle(p)
218
+ });
219
+ for (let i = 0; i < p.geoJsons; i++) {
220
+ let json = p.geoJsons[i];
221
+ var f = new ol.Feature({
222
+ geometry: geoJSON.readGeometry(json)
223
+ });
224
+ vectorSource.addFeature(f);
225
+ }
226
+ return layer;
227
+ }
228
+ /**
229
+ * 将geoJson的多边形集合数据包装为一个图层
230
+ * @param {*} p
231
+ */
232
+ static getJsonPolygonsLayer(p) {
233
+ let vectorSource = new VectorSource({ features: [] });
234
+ let layer = new VectorLayer({
235
+ source: vectorSource,
236
+ style: StyleUtil.getPolygonStyle(p)
237
+ });
238
+ for (let i = 0; i < p.geoJsons; i++) {
239
+ let json = p.geoJsons[i];
240
+ var f = new ol.Feature({
241
+ geometry: geoJSON.readGeometry(json)
242
+ });
243
+ vectorSource.addFeature(f);
244
+ }
245
+ return layer;
246
+ }
206
247
  }
package/src/StyleUtil.js CHANGED
@@ -2,6 +2,8 @@ import Style from 'ol/style/Style.js';
2
2
  import Stroke from 'ol/style/Stroke.js';
3
3
  import Fill from 'ol/style/Fill.js';
4
4
  import Circle from 'ol/style/Circle.js';
5
+ import Icon from 'ol/style/Icon.js';
6
+ import Text from 'ol/style/Text.js';
5
7
 
6
8
  /**
7
9
  * 样式工具类
@@ -57,7 +59,7 @@ export default class StyleUtil {
57
59
  }),
58
60
  stroke: new Stroke({
59
61
  color: 'rgba(0, 0, 255, 1)',
60
- lineDash: [10, 10],
62
+ lineDash: [10, 10], //虚线
61
63
  width: 2
62
64
  }),
63
65
  image: new Circle({
@@ -71,4 +73,79 @@ export default class StyleUtil {
71
73
  })
72
74
  });
73
75
  }
76
+ /**
77
+ * 获取图片样式
78
+ * @param {*} p
79
+ * @returns
80
+ */
81
+ static getIcon(p) {
82
+ let anchor = p.anchor ? p.anchor : [0.5, 0.5];//锚点,0.5,0.5 图片水平偏移一半,垂直偏移一半(变成居中)
83
+ return new Icon({
84
+ anchor: anchor,
85
+ anchorOrigin: 'top-right',
86
+ anchorXUnits: 'fraction',
87
+ anchorYUnits: 'pixels',
88
+ offsetOrigin: 'top-right',
89
+ // offset:[0,10],
90
+ //图标缩放比例
91
+ //scale:0.5,
92
+ //透明度
93
+ //opacity: 0.75,
94
+ //图标的url
95
+ src: p.url
96
+ });
97
+ }
98
+ /**
99
+ * 获取文字样式
100
+ * @param {*} p
101
+ * @returns
102
+ */
103
+ static getText(p) {
104
+ let font = p.font ? p.font : 'bold 20px 宋体';
105
+ let corlor = p.corlor ? p.corlor : '#0619e9';
106
+ let offsetY = p.offsetY ? p.offsetY : -10;
107
+ return new Text({
108
+ text: p.str, // 从要素属性获取文字
109
+ font: font,
110
+ fill: new Fill({
111
+ color: corlor
112
+ }),
113
+ offsetX: 0,
114
+ offsetY: offsetY // 文字显示在图标上方
115
+ });
116
+ }
117
+ /**
118
+ * 获取点的样式
119
+ * @param {*} p
120
+ * @returns
121
+ */
122
+ static getPointStyle(p) {
123
+ let styleParam = {};
124
+ if (p.img) {
125
+ styleParam.image = StyleUtil.getIcon(p.img);
126
+ }
127
+ if (p.text) {
128
+ styleParam.text = StyleUtil.getText(p.text);
129
+ }
130
+ return new Style(styleParam);
131
+ }
132
+ /**
133
+ * 获取多边形的样式
134
+ * @param {*} p
135
+ * @returns
136
+ */
137
+ static getPolygonStyle(p) {
138
+ let fill = p.fill ? p.fill : 'rgba(255, 255, 255, 0.2)';
139
+ let lineColor = p.lineColor ? p.lineColor : 'rgba(0, 0, 255, 1)';
140
+ let lineWidth = p.lineWidth ? p.lineWidth : 2;
141
+ return new Style({
142
+ fill: new Fill({
143
+ color: fill
144
+ }),
145
+ stroke: new Stroke({
146
+ color: lineColor,
147
+ width: lineWidth
148
+ })
149
+ });
150
+ }
74
151
  }
package/src/index.d.ts CHANGED
@@ -22,7 +22,7 @@ declare module 'cd-mapgis' {
22
22
  data: string;
23
23
  }): void;
24
24
  static expandExtent(extent: number[]): number[];
25
- static addOverlay(p:{html:string,point:number[],positioning?:string}): void;
25
+ static addOverlay(p: { html: string, point: number[], positioning?: string }): void;
26
26
  static initParam(params: any): void;
27
27
  static post(url: string, data: any): Promise<any>;
28
28
  static getDic(key: string): Promise<any>;
@@ -33,6 +33,8 @@ declare module 'cd-mapgis' {
33
33
  static buffer(p: any): Promise<any>;
34
34
  static getBound(p: any): Promise<any>;
35
35
  static checkPushLayers(p: any): Promise<any>;
36
+ static getLayerAttr(p: any): Promise<any>;
37
+ static getAddressByPoint(p: any): Promise<any>;
36
38
  static viewLayers(p: any): Promise<any>;
37
39
  static fitToLayers(p: any): void;
38
40
  }
@@ -67,6 +69,9 @@ declare module 'cd-mapgis' {
67
69
  static getWmtsLayer(p: {
68
70
  url: string;
69
71
  }): Promise<any>;
72
+ static getJsonLayer(p: any): any;
73
+ static getJsonPointsLayer(p: any): any;
74
+ static getJsonPolygonsLayer(p: any): any;
70
75
  }
71
76
  export class Overlay {
72
77
  constructor(data: any);