cd-mapgis 1.0.58 → 1.0.60
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 +22 -6
- package/src/MapView.js +17 -5
package/package.json
CHANGED
package/src/LayerUtil.js
CHANGED
|
@@ -12,6 +12,7 @@ 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
14
|
import StyleUtil from './StyleUtil.js';
|
|
15
|
+
import LineString from 'ol/geom/LineString.js';
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* 图层工具
|
|
@@ -205,15 +206,30 @@ export default class LayerUtil {
|
|
|
205
206
|
});
|
|
206
207
|
return { layer: layer, geometry: geometry };
|
|
207
208
|
}
|
|
209
|
+
/**
|
|
210
|
+
* [[116.4074, 39.9042], [121.4737, 31.2304]]
|
|
211
|
+
* @param {*} p
|
|
212
|
+
*/
|
|
213
|
+
static getJsonPointsLayer(p) {
|
|
214
|
+
let coordinates = JSON.parse(p.data);
|
|
215
|
+
let geometry = new LineString(coordinates);
|
|
216
|
+
let feature = new Feature({ geometry: geometry });
|
|
217
|
+
let vectorSource = new VectorSource({ features: [feature] });
|
|
218
|
+
let layer = new VectorLayer({
|
|
219
|
+
source: vectorSource,
|
|
220
|
+
style: p.style
|
|
221
|
+
});
|
|
222
|
+
return { layer: layer, geometry: geometry };
|
|
223
|
+
}
|
|
208
224
|
/**
|
|
209
225
|
* 将geoJson的点集合数据包装为一个图层
|
|
210
226
|
* @param {*} p {geoList:[],img:{url,anchor},text:{str,font,color,offsetY}}
|
|
211
227
|
*/
|
|
212
|
-
static getJsonPointsLayer(p) {
|
|
228
|
+
static getJsonPointsLayer(p) {
|
|
213
229
|
let geoJSON = new GeoJSON();
|
|
214
230
|
let features = [];
|
|
215
231
|
for (let i = 0; i < p.geoList.length; i++) {
|
|
216
|
-
let geo = p.geoList[i];
|
|
232
|
+
let geo = p.geoList[i];
|
|
217
233
|
var f = new Feature({
|
|
218
234
|
geometry: geoJSON.readGeometry(geo.json)
|
|
219
235
|
});
|
|
@@ -223,7 +239,7 @@ export default class LayerUtil {
|
|
|
223
239
|
}
|
|
224
240
|
f.setStyle(StyleUtil.getPointStyle(p));
|
|
225
241
|
features.push(f);
|
|
226
|
-
}
|
|
242
|
+
}
|
|
227
243
|
let vectorSource = new VectorSource({ features: features });
|
|
228
244
|
return new VectorLayer({
|
|
229
245
|
source: vectorSource
|
|
@@ -233,11 +249,11 @@ export default class LayerUtil {
|
|
|
233
249
|
* 将geoJson的多边形集合数据包装为一个图层
|
|
234
250
|
* @param {*} p {geoList:[],style:{fillColor,lineColor,lineWidth},text:{str,font,color}}
|
|
235
251
|
*/
|
|
236
|
-
static getJsonPolygonsLayer(p) {
|
|
252
|
+
static getJsonPolygonsLayer(p) {
|
|
237
253
|
let geoJSON = new GeoJSON();
|
|
238
254
|
let features = [];
|
|
239
255
|
for (let i = 0; i < p.geoList.length; i++) {
|
|
240
|
-
let geo = p.geoList[i];
|
|
256
|
+
let geo = p.geoList[i];
|
|
241
257
|
var f = new Feature({
|
|
242
258
|
geometry: geoJSON.readGeometry(geo.json)
|
|
243
259
|
});
|
|
@@ -247,7 +263,7 @@ export default class LayerUtil {
|
|
|
247
263
|
}
|
|
248
264
|
f.setStyle(StyleUtil.getPolygonStyle(p));
|
|
249
265
|
features.push(f);
|
|
250
|
-
}
|
|
266
|
+
}
|
|
251
267
|
let vectorSource = new VectorSource({ features: features });
|
|
252
268
|
return new VectorLayer({
|
|
253
269
|
source: vectorSource
|
package/src/MapView.js
CHANGED
|
@@ -80,15 +80,27 @@ export default class MapView {
|
|
|
80
80
|
this.clearTemplayer(); //移除之前的显示
|
|
81
81
|
p.style = StyleUtil.getViewOnTemplayerStyle();
|
|
82
82
|
//重建图层,避免在其他地方全部移除图层后,templayer不为空,但是已经不在地图中的情况
|
|
83
|
-
let res
|
|
83
|
+
let res;
|
|
84
|
+
if (p.type == 'jsonPoints') {
|
|
85
|
+
res = LayerUtil.getJsonPointsLayer(p);
|
|
86
|
+
} else {
|
|
87
|
+
res = LayerUtil.getJsonLayer(p);
|
|
88
|
+
}
|
|
84
89
|
this._view_templayer = res.layer;
|
|
85
90
|
this.map.addLayer(this._view_templayer);// 添加到地图
|
|
86
91
|
// fit方法 - 自动适应范围
|
|
87
92
|
let extent = res.geometry.getExtent();
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
93
|
+
//非点
|
|
94
|
+
if (extent[0] != extent[2]) {
|
|
95
|
+
//缩放到指定的范围
|
|
96
|
+
let extent2 = this.expandExtent(extent);
|
|
97
|
+
this.map.getView().fit(extent2, {
|
|
98
|
+
size: this.map.getSize()
|
|
99
|
+
});
|
|
100
|
+
} else {
|
|
101
|
+
//平移到指定的点
|
|
102
|
+
this.map.getView().setCenter([extent[0], extent[1]]); // [经度, 纬度]
|
|
103
|
+
}
|
|
92
104
|
}
|
|
93
105
|
/**
|
|
94
106
|
* 清除显示在临时图层上的数据
|