cd-mapgis 1.0.38 → 1.0.39

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.38",
3
+ "version": "1.0.39",
4
4
  "main": "./src/index.js",
5
5
  "types": "./src/index.d.ts",
6
6
  "type": "module",
package/src/LayerUtil.js CHANGED
@@ -207,39 +207,48 @@ export default class LayerUtil {
207
207
  }
208
208
  /**
209
209
  * 将geoJson的点集合数据包装为一个图层
210
- * @param {*} p {geoJsons:[],img:{url,anchor},text:{str,font,color,offsetY}}
210
+ * @param {*} p {geoList:[],img:{url,anchor},text:{str,font,color,offsetY}}
211
211
  */
212
212
  static getJsonPointsLayer(p) {
213
213
  let geoJSON = new GeoJSON();
214
214
  let vectorSource = new VectorSource({ features: [] });
215
215
  let layer = new VectorLayer({
216
- source: vectorSource,
217
- style: StyleUtil.getPointStyle(p)
216
+ source: vectorSource
218
217
  });
219
- for (let i = 0; i < p.geoJsons; i++) {
220
- let json = p.geoJsons[i];
218
+ for (let i = 0; i < p.geoList; i++) {
219
+ let geo = p.geoList[i];
221
220
  var f = new ol.Feature({
222
- geometry: geoJSON.readGeometry(json)
221
+ geometry: geoJSON.readGeometry(geo.json)
223
222
  });
223
+ if (geo.text) {
224
+ if (!p.text) p.text = {};
225
+ p.text.str = geo.text;
226
+ }
227
+ f.setStyle(StyleUtil.getPointStyle(p));
224
228
  vectorSource.addFeature(f);
225
229
  }
226
230
  return layer;
227
231
  }
228
232
  /**
229
233
  * 将geoJson的多边形集合数据包装为一个图层
230
- * @param {*} p
234
+ * @param {*} p {geoList:[],style:{fillColor,lineColor,lineWidth},text:{str,font,color}}
231
235
  */
232
236
  static getJsonPolygonsLayer(p) {
237
+ let geoJSON = new GeoJSON();
233
238
  let vectorSource = new VectorSource({ features: [] });
234
239
  let layer = new VectorLayer({
235
- source: vectorSource,
236
- style: StyleUtil.getPolygonStyle(p)
240
+ source: vectorSource
237
241
  });
238
- for (let i = 0; i < p.geoJsons; i++) {
239
- let json = p.geoJsons[i];
242
+ for (let i = 0; i < p.geoList; i++) {
243
+ let geo = p.geoList[i];
240
244
  var f = new ol.Feature({
241
- geometry: geoJSON.readGeometry(json)
245
+ geometry: geoJSON.readGeometry(geo.json)
242
246
  });
247
+ if (geo.text) {
248
+ if (!p.text) p.text = {};
249
+ p.text.str = geo.text;
250
+ }
251
+ f.setStyle(StyleUtil.getPolygonStyle(p));
243
252
  vectorSource.addFeature(f);
244
253
  }
245
254
  return layer;
package/src/StyleUtil.js CHANGED
@@ -135,17 +135,25 @@ export default class StyleUtil {
135
135
  * @returns
136
136
  */
137
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
- })
138
+ let styleParam = {};
139
+ let fill = 'rgba(255, 255, 255, 0.2)';
140
+ let lineColor = 'rgba(0, 0, 255, 1)';
141
+ let lineWidth = 2;
142
+ if (p.style) {
143
+ if (p.style.fillColor) fill = p.style.fillColor;
144
+ if (p.style.lineColor) lineColor = p.style.lineColor;
145
+ if (p.style.lineWidth) lineWidth = p.style.lineWidth;
146
+ }
147
+ styleParam.fill = new Fill({
148
+ color: fill
149
+ });
150
+ styleParam.stroke = new Stroke({
151
+ color: lineColor,
152
+ width: lineWidth
149
153
  });
154
+ if (p.text) {
155
+ styleParam.text = StyleUtil.getText(p.text);
156
+ }
157
+ return new Style(styleParam);
150
158
  }
151
159
  }