cd-mapgis 1.0.38 → 1.0.40
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/LayerUtil.js +23 -14
- package/src/StyleUtil.js +19 -11
package/package.json
CHANGED
package/src/LayerUtil.js
CHANGED
|
@@ -207,39 +207,48 @@ export default class LayerUtil {
|
|
|
207
207
|
}
|
|
208
208
|
/**
|
|
209
209
|
* 将geoJson的点集合数据包装为一个图层
|
|
210
|
-
* @param {*} p {
|
|
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.
|
|
220
|
-
let
|
|
221
|
-
var f = new
|
|
222
|
-
geometry: geoJSON.readGeometry(json)
|
|
218
|
+
for (let i = 0; i < p.geoList; i++) {
|
|
219
|
+
let geo = p.geoList[i];
|
|
220
|
+
var f = new Feature({
|
|
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.
|
|
239
|
-
let
|
|
240
|
-
var f = new
|
|
241
|
-
geometry: geoJSON.readGeometry(json)
|
|
242
|
+
for (let i = 0; i < p.geoList; i++) {
|
|
243
|
+
let geo = p.geoList[i];
|
|
244
|
+
var f = new Feature({
|
|
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
|
|
139
|
-
let
|
|
140
|
-
let
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
}
|