cd-mapgis 1.1.5 → 1.1.7
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/LineLayer.js +3 -16
- package/src/PointLayer.js +24 -21
package/package.json
CHANGED
package/src/LineLayer.js
CHANGED
|
@@ -15,7 +15,6 @@ export default class LineLayer {
|
|
|
15
15
|
this.vectorLayer = new VectorLayer({
|
|
16
16
|
source: this.vectorSource
|
|
17
17
|
});
|
|
18
|
-
this.features = [];
|
|
19
18
|
this.mapView = p.mapView ? p.mapView : MapView.Instance;
|
|
20
19
|
this.map = this.mapView.map;
|
|
21
20
|
this.map.addLayer(this.vectorLayer);
|
|
@@ -49,7 +48,6 @@ export default class LineLayer {
|
|
|
49
48
|
})
|
|
50
49
|
}));
|
|
51
50
|
feature.set('attr', p.attr);
|
|
52
|
-
this.features.push(feature);
|
|
53
51
|
return feature;
|
|
54
52
|
}
|
|
55
53
|
/**
|
|
@@ -84,21 +82,10 @@ export default class LineLayer {
|
|
|
84
82
|
* 缩放到本图层显示范围
|
|
85
83
|
*/
|
|
86
84
|
fitToLayer(){
|
|
87
|
-
const map = this.map;
|
|
88
|
-
|
|
89
|
-
this.features.forEach(f => {
|
|
90
|
-
const coord = f.getGeometry().getCoordinates();
|
|
91
|
-
minX = Math.min(minX, coord[0]);
|
|
92
|
-
minY = Math.min(minY, coord[1]);
|
|
93
|
-
maxX = Math.max(maxX, coord[0]);
|
|
94
|
-
maxY = Math.max(maxY, coord[1]);
|
|
95
|
-
});
|
|
96
|
-
const manualExtent = [minX, minY, maxX, maxY];
|
|
97
|
-
console.log('手动计算 extent:', manualExtent);
|
|
98
|
-
map.getView().fit(manualExtent, {
|
|
85
|
+
const map = this.map;
|
|
86
|
+
map.getView().fit(this.vectorSource.getExtent(), {
|
|
99
87
|
size: map.getSize(),
|
|
100
|
-
maxZoom:
|
|
101
|
-
duration: 1000
|
|
88
|
+
maxZoom: 18
|
|
102
89
|
})
|
|
103
90
|
}
|
|
104
91
|
}
|
package/src/PointLayer.js
CHANGED
|
@@ -15,7 +15,6 @@ export default class PointLayer {
|
|
|
15
15
|
this.vectorLayer = new VectorLayer({
|
|
16
16
|
source: this.vectorSource
|
|
17
17
|
});
|
|
18
|
-
this.features = [];
|
|
19
18
|
this.mapView = p.mapView ? p.mapView : MapView.Instance;
|
|
20
19
|
this.map = this.mapView.map;
|
|
21
20
|
this.map.addLayer(this.vectorLayer);
|
|
@@ -42,18 +41,34 @@ export default class PointLayer {
|
|
|
42
41
|
let feature = new Feature({
|
|
43
42
|
geometry: new Point(p.point)
|
|
44
43
|
});
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
let p = {};
|
|
45
|
+
if (p.img) {
|
|
46
|
+
p.image = new Icon({
|
|
47
47
|
src: p.img, // 外部图标路径
|
|
48
48
|
scale: 1, // 缩放比例
|
|
49
49
|
anchor: [0.5, 0.5], // 锚点为中心
|
|
50
50
|
anchorOrigin: 'center',
|
|
51
51
|
anchorXUnits: 'fraction',
|
|
52
52
|
anchorYUnits: 'fraction'
|
|
53
|
-
})
|
|
54
|
-
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (p.text) {
|
|
56
|
+
let font = p.font ? p.font : 'bold 20px 宋体';
|
|
57
|
+
let corlor = p.corlor ? p.corlor : '#0619e9';
|
|
58
|
+
let offsetY = p.offsetY ? p.offsetY : -10;
|
|
59
|
+
p.text = new Text({
|
|
60
|
+
text: p.text, // 从要素属性获取文字
|
|
61
|
+
font: font,
|
|
62
|
+
overflow: true, // 关键设置:允许文字溢出
|
|
63
|
+
fill: new Fill({
|
|
64
|
+
color: corlor
|
|
65
|
+
}),
|
|
66
|
+
offsetX: 0,
|
|
67
|
+
offsetY: offsetY // 文字显示在图标上方
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
feature.setStyle(new Style(p));
|
|
55
71
|
feature.set('attr', p.attr);
|
|
56
|
-
this.features.push(feature);
|
|
57
72
|
return feature;
|
|
58
73
|
}
|
|
59
74
|
/**
|
|
@@ -88,22 +103,10 @@ export default class PointLayer {
|
|
|
88
103
|
* 缩放到本图层显示范围
|
|
89
104
|
*/
|
|
90
105
|
fitToLayer() {
|
|
91
|
-
const map = this.map;
|
|
92
|
-
|
|
93
|
-
this.features.forEach(f => {
|
|
94
|
-
const coord = f.getGeometry().getCoordinates();
|
|
95
|
-
minX = Math.min(minX, coord[0]);
|
|
96
|
-
minY = Math.min(minY, coord[1]);
|
|
97
|
-
maxX = Math.max(maxX, coord[0]);
|
|
98
|
-
maxY = Math.max(maxY, coord[1]);
|
|
99
|
-
});
|
|
100
|
-
const manualExtent = [minX, minY, maxX, maxY];
|
|
101
|
-
console.log('features:', this.features);
|
|
102
|
-
console.log('手动计算 extent:', manualExtent);
|
|
103
|
-
map.getView().fit(manualExtent, {
|
|
106
|
+
const map = this.map;
|
|
107
|
+
map.getView().fit(this.vectorSource.getExtent(), {
|
|
104
108
|
size: map.getSize(),
|
|
105
|
-
maxZoom:
|
|
106
|
-
duration: 1000
|
|
109
|
+
maxZoom: 18
|
|
107
110
|
})
|
|
108
111
|
}
|
|
109
112
|
}
|