my-openlayer 0.1.14 → 0.1.16
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/dist/core/MapBaseLayers.d.ts +2 -1
- package/dist/core/MapBaseLayers.js +1 -1
- package/dist/core/Polygon.d.ts +1 -1
- package/dist/core/Polygon.js +20 -38
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import Map from "ol/Map";
|
|
5
5
|
import { Tile as TileLayer } from "ol/layer";
|
|
6
|
+
import { TileWMS } from "ol/source";
|
|
6
7
|
import WMTSTileGrid from "ol/tilegrid/WMTS";
|
|
7
8
|
import XYZ from "ol/source/XYZ";
|
|
8
9
|
import { MapLayersOptions, TiandituType, AnnotationLayerOptions } from "../types";
|
|
@@ -20,7 +21,7 @@ export default class MapBaseLayers {
|
|
|
20
21
|
addGeoServerLayer(url: string, layer: string, options: {
|
|
21
22
|
zIndex?: number;
|
|
22
23
|
visible?: boolean;
|
|
23
|
-
}):
|
|
24
|
+
}): TileLayer<TileWMS>;
|
|
24
25
|
static getTiandiTuLayer(options: {
|
|
25
26
|
type: TiandituType;
|
|
26
27
|
token: string;
|
package/dist/core/Polygon.d.ts
CHANGED
package/dist/core/Polygon.js
CHANGED
|
@@ -52,35 +52,13 @@ export default class Polygon {
|
|
|
52
52
|
source: new VectorSource({
|
|
53
53
|
features: (new GeoJSON()).readFeatures(dataJSON, options.projectionOptOptions ?? {})
|
|
54
54
|
}),
|
|
55
|
-
// style: function (feature: any) {
|
|
56
|
-
// feature.set('type', options?.type)
|
|
57
|
-
// feature.set('layerName', options?.type)
|
|
58
|
-
// return new Style({
|
|
59
|
-
// stroke: new Stroke({
|
|
60
|
-
// color: options?.strokeColor ?? '#EBEEF5',
|
|
61
|
-
// width: options?.strokeWidth ?? 2,
|
|
62
|
-
// lineDash: options?.lineDash,
|
|
63
|
-
// lineDashOffset: options?.lineDashOffset
|
|
64
|
-
// }),
|
|
65
|
-
// fill: new Fill({ color: options?.fillColor || 'rgba(255, 255, 255, 0.3)' }),
|
|
66
|
-
// text: new Text({
|
|
67
|
-
// text: options?.textVisible && options.nameKey ? feature.values_[options.nameKey] : "",
|
|
68
|
-
// font: options?.textFont ?? '14px Calibri,sans-serif',
|
|
69
|
-
// fill: new Fill({ color: options?.textFillColor ?? '#FFF' }),
|
|
70
|
-
// stroke: new Stroke({
|
|
71
|
-
// color: options?.textStrokeColor ?? '#409EFF',
|
|
72
|
-
// width: options?.textStrokeWidth ?? 2
|
|
73
|
-
// })
|
|
74
|
-
// })
|
|
75
|
-
// })
|
|
76
|
-
// },
|
|
77
55
|
zIndex: options.zIndex ?? 11
|
|
78
56
|
});
|
|
79
57
|
const features = layer.getSource()?.getFeatures();
|
|
80
58
|
features?.forEach(feature => {
|
|
81
59
|
feature.set('type', options?.type);
|
|
82
60
|
feature.set('layerName', options?.type);
|
|
83
|
-
|
|
61
|
+
const featureStyle = new Style({
|
|
84
62
|
stroke: new Stroke({
|
|
85
63
|
color: options?.strokeColor ?? '#EBEEF5',
|
|
86
64
|
width: options?.strokeWidth ?? 2,
|
|
@@ -88,16 +66,20 @@ export default class Polygon {
|
|
|
88
66
|
lineDashOffset: options?.lineDashOffset
|
|
89
67
|
}),
|
|
90
68
|
fill: new Fill({ color: options?.fillColor || 'rgba(255, 255, 255, 0.3)' }),
|
|
91
|
-
|
|
92
|
-
|
|
69
|
+
});
|
|
70
|
+
if (options?.textVisible) {
|
|
71
|
+
const text = options?.textValue || (options.nameKey ? feature.get(options.nameKey) : "");
|
|
72
|
+
featureStyle.setText(new Text({
|
|
73
|
+
text: text,
|
|
93
74
|
font: options?.textFont ?? '14px Calibri,sans-serif',
|
|
94
75
|
fill: new Fill({ color: options?.textFillColor ?? '#FFF' }),
|
|
95
76
|
stroke: new Stroke({
|
|
96
77
|
color: options?.textStrokeColor ?? '#409EFF',
|
|
97
78
|
width: options?.textStrokeWidth ?? 2
|
|
98
79
|
})
|
|
99
|
-
})
|
|
100
|
-
}
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
feature.setStyle(featureStyle);
|
|
101
83
|
});
|
|
102
84
|
layer.setVisible(options.visible === undefined ? true : options.visible);
|
|
103
85
|
this.map.addLayer(layer);
|
|
@@ -120,34 +102,34 @@ export default class Polygon {
|
|
|
120
102
|
* }
|
|
121
103
|
* @param options 配置项
|
|
122
104
|
*/
|
|
123
|
-
|
|
105
|
+
updateFeatureColor(layerName, colorObj, options) {
|
|
124
106
|
const layer = MapTools.getLayerByLayerName(this.map, layerName)[0];
|
|
125
107
|
if (layer instanceof VectorLayer) {
|
|
126
108
|
const features = layer.getSource()?.getFeatures();
|
|
127
|
-
features
|
|
109
|
+
features?.forEach((feature) => {
|
|
128
110
|
if (options?.nameKey || (!colorObj || Object.keys(colorObj).length === 0)) {
|
|
129
111
|
const name = options?.nameKey ? feature.get(options.nameKey) : '';
|
|
130
112
|
const newColor = colorObj?.[name];
|
|
131
|
-
|
|
132
|
-
// console.log(oldStyle)
|
|
133
|
-
// if (newColor) {
|
|
134
|
-
feature.setStyle(new Style({
|
|
113
|
+
const featureStyle = new Style({
|
|
135
114
|
stroke: new Stroke({
|
|
136
115
|
color: options?.strokeColor ?? '#EBEEF5',
|
|
137
116
|
width: options?.strokeWidth ?? 2
|
|
138
117
|
}),
|
|
139
118
|
fill: new Fill({ color: newColor || options?.fillColor || 'rgba(255, 255, 255, 0.3)' }),
|
|
140
|
-
|
|
141
|
-
|
|
119
|
+
});
|
|
120
|
+
if (options?.textVisible) {
|
|
121
|
+
const text = options?.textValue || (options.nameKey ? feature.get(options.nameKey) : "");
|
|
122
|
+
featureStyle.setText(new Text({
|
|
123
|
+
text,
|
|
142
124
|
font: options?.textFont ?? '14px Calibri,sans-serif',
|
|
143
125
|
fill: new Fill({ color: options?.textFillColor || '#FFF' }),
|
|
144
126
|
stroke: new Stroke({
|
|
145
127
|
color: options?.textStrokeColor ?? '#409EFF',
|
|
146
128
|
width: options?.textStrokeWidth ?? 2
|
|
147
129
|
})
|
|
148
|
-
})
|
|
149
|
-
}
|
|
150
|
-
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
feature.setStyle(featureStyle);
|
|
151
133
|
}
|
|
152
134
|
});
|
|
153
135
|
}
|
package/dist/types.d.ts
CHANGED