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.
@@ -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
- }): string;
24
+ }): TileLayer<TileWMS>;
24
25
  static getTiandiTuLayer(options: {
25
26
  type: TiandituType;
26
27
  token: string;
@@ -124,7 +124,7 @@ export default class MapBaseLayers {
124
124
  visible: options.visible ?? true,
125
125
  });
126
126
  this.map.addLayer(wmsLayer);
127
- return layer;
127
+ return wmsLayer;
128
128
  }
129
129
  //img_c 影像底图 ter_c 地形底图
130
130
  static getTiandiTuLayer(options) {
@@ -31,7 +31,7 @@ export default class Polygon {
31
31
  * }
32
32
  * @param options 配置项
33
33
  */
34
- updateFeatureColors(layerName: string, colorObj?: {
34
+ updateFeatureColor(layerName: string, colorObj?: {
35
35
  [propName: string]: string;
36
36
  }, options?: OptionsType): void;
37
37
  /**
@@ -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
- feature.setStyle(new Style({
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
- text: new Text({
92
- text: options?.textVisible && options.nameKey ? feature.get(options.nameKey) : "",
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
- updateFeatureColors(layerName, colorObj, options) {
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.forEach((feature) => {
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
- // const oldStyle = feature.getStyle()
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
- text: new Text({
141
- text: options?.textVisible === false ? "" : name,
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
@@ -72,6 +72,7 @@ export interface OptionsType {
72
72
  lineDashOffset?: number;
73
73
  fillColor?: string;
74
74
  textVisible?: boolean;
75
+ textValue?: string;
75
76
  textFont?: string;
76
77
  textFillColor?: string;
77
78
  textStrokeColor?: string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "my-openlayer",
3
3
  "private": false,
4
- "version": "0.1.14",
4
+ "version": "0.1.16",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",