my-openlayer 3.1.3 → 3.1.4

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.
@@ -81,7 +81,15 @@ export default class PointPulseLayer {
81
81
  const source = new VectorSource({
82
82
  features: PointPulseLayer.createFeatures(pointData, options)
83
83
  });
84
- const createStyles = (feature) => {
84
+ const baseZIndex = options.zIndex || ConfigManager.DEFAULT_POINT_OPTIONS.zIndex;
85
+ const iconImg = options.icon?.img ?? options.icon?.src;
86
+ /**
87
+ * 仅负责绘制脉冲动画,避免动画覆盖图标。
88
+ */
89
+ const createPulseStyle = (feature) => {
90
+ if (!pulseOptions.enabled) {
91
+ return undefined;
92
+ }
85
93
  const rawData = feature.get('rawData');
86
94
  const level = String(rawData?.[levelKey] ?? 'default');
87
95
  const progress = frameIndex / Math.max(1, pulseOptions.frameCount - 1);
@@ -90,28 +98,28 @@ export default class PointPulseLayer {
90
98
  const opacity = 1 - progress;
91
99
  const fillColor = pulseOptions.colorMap[level] ?? pulseOptions.colorMap.default ?? 'rgba(6, 183, 253, 0.32)';
92
100
  const strokeColor = pulseOptions.strokeColorMap?.[level] ?? pulseOptions.strokeColorMap?.default;
93
- const styles = [];
94
- if (pulseOptions.enabled) {
95
- const pulseCacheKey = `${level}_${frameIndex}`;
96
- let pulseStyle = pulseStyleCache.get(pulseCacheKey);
97
- if (!pulseStyle) {
98
- pulseStyle = new Style({
99
- zIndex: 0,
100
- image: new CircleStyle({
101
- radius,
102
- fill: new Fill({ color: PointPulseLayer.withOpacity(fillColor, opacity) }),
103
- stroke: strokeColor && pulseOptions.strokeWidth > 0
104
- ? new Stroke({ color: PointPulseLayer.withOpacity(strokeColor, opacity), width: pulseOptions.strokeWidth })
105
- : undefined
106
- })
107
- });
108
- pulseStyleCache.set(pulseCacheKey, pulseStyle);
109
- }
110
- styles.push(pulseStyle);
101
+ const pulseCacheKey = `${level}_${frameIndex}`;
102
+ let pulseStyle = pulseStyleCache.get(pulseCacheKey);
103
+ if (!pulseStyle) {
104
+ pulseStyle = new Style({
105
+ image: new CircleStyle({
106
+ radius,
107
+ fill: new Fill({ color: PointPulseLayer.withOpacity(fillColor, opacity) }),
108
+ stroke: strokeColor && pulseOptions.strokeWidth > 0
109
+ ? new Stroke({ color: PointPulseLayer.withOpacity(strokeColor, opacity), width: pulseOptions.strokeWidth })
110
+ : undefined
111
+ })
112
+ });
113
+ pulseStyleCache.set(pulseCacheKey, pulseStyle);
111
114
  }
115
+ return pulseStyle;
116
+ };
117
+ /**
118
+ * 仅负责绘制图标与文本,固定放在脉冲层之上。
119
+ */
120
+ const createStaticStyle = (feature) => {
121
+ const rawData = feature.get('rawData');
112
122
  const text = options.textVisible && options.textKey && rawData ? String(rawData[options.textKey] ?? '') : '';
113
- // P1-4: icon.img 是新名,icon.src 保留兼容(@deprecated)
114
- const iconImg = options.icon?.img ?? options.icon?.src;
115
123
  const staticCacheKey = [
116
124
  options.img ?? iconImg ?? '',
117
125
  options.scale ?? options.icon?.scale ?? ConfigManager.DEFAULT_POINT_ICON_SCALE,
@@ -120,8 +128,7 @@ export default class PointPulseLayer {
120
128
  ].join('|');
121
129
  let pointStyle = staticStyleCache.get(staticCacheKey);
122
130
  if (pointStyle) {
123
- styles.push(pointStyle);
124
- return styles;
131
+ return pointStyle;
125
132
  }
126
133
  const pointStyleOptions = {};
127
134
  const iconSrc = options.img ?? iconImg;
@@ -147,23 +154,34 @@ export default class PointPulseLayer {
147
154
  }
148
155
  if (pointStyleOptions.image || pointStyleOptions.text) {
149
156
  pointStyle = new Style(pointStyleOptions);
150
- pointStyle.setZIndex(1);
151
157
  staticStyleCache.set(staticCacheKey, pointStyle);
152
- styles.push(pointStyle);
158
+ return pointStyle;
153
159
  }
154
- return styles;
160
+ return undefined;
155
161
  };
156
- const layer = new VectorLayer({
162
+ const pulseLayer = new VectorLayer({
163
+ properties: {
164
+ name: options.layerName,
165
+ layerName: options.layerName
166
+ },
167
+ source,
168
+ style: createPulseStyle,
169
+ zIndex: baseZIndex,
170
+ });
171
+ const visible = options.visible === undefined ? true : options.visible;
172
+ pulseLayer.setVisible(visible);
173
+ map.addLayer(pulseLayer);
174
+ const staticLayer = new VectorLayer({
157
175
  properties: {
158
176
  name: options.layerName,
159
177
  layerName: options.layerName
160
178
  },
161
179
  source,
162
- style: createStyles,
163
- zIndex: options.zIndex || ConfigManager.DEFAULT_POINT_OPTIONS.zIndex,
180
+ style: createStaticStyle,
181
+ zIndex: baseZIndex + 1,
164
182
  });
165
- layer.setVisible(options.visible === undefined ? true : options.visible);
166
- map.addLayer(layer);
183
+ staticLayer.setVisible(visible);
184
+ map.addLayer(staticLayer);
167
185
  const tick = () => {
168
186
  if (!running)
169
187
  return;
@@ -173,7 +191,7 @@ export default class PointPulseLayer {
173
191
  if (nextFrameIndex !== renderedFrameIndex) {
174
192
  frameIndex = nextFrameIndex;
175
193
  renderedFrameIndex = nextFrameIndex;
176
- layer.changed();
194
+ pulseLayer.changed();
177
195
  }
178
196
  rafId = requestAnimationFrame(tick);
179
197
  };
@@ -192,11 +210,14 @@ export default class PointPulseLayer {
192
210
  };
193
211
  start();
194
212
  return {
195
- layer,
213
+ layer: pulseLayer,
196
214
  source,
197
215
  start,
198
216
  stop,
199
- setVisible: (visible) => layer.setVisible(visible),
217
+ setVisible: (visible) => {
218
+ pulseLayer.setVisible(visible);
219
+ staticLayer.setVisible(visible);
220
+ },
200
221
  updateData: (nextData) => {
201
222
  source.clear();
202
223
  source.addFeatures(PointPulseLayer.createFeatures(nextData, options));
@@ -204,7 +225,8 @@ export default class PointPulseLayer {
204
225
  remove: () => {
205
226
  stop();
206
227
  source.clear();
207
- map.removeLayer(layer);
228
+ map.removeLayer(pulseLayer);
229
+ map.removeLayer(staticLayer);
208
230
  }
209
231
  };
210
232
  }
@@ -103,9 +103,20 @@ export default class PolygonStyleFactory {
103
103
  const strokeWidth = withDefaultStroke ? options?.strokeWidth ?? previousStroke?.getWidth() : undefined;
104
104
  const lineDash = withDefaultStroke ? options?.lineDash ?? previousStroke?.getLineDash() ?? undefined : undefined;
105
105
  const lineDashOffset = withDefaultStroke ? options?.lineDashOffset ?? previousStroke?.getLineDashOffset() : undefined;
106
- const newColor = hasMappedColor
107
- ? colorObj[name]
108
- : options?.fillColor ?? (withDefaultFill ? previousFill?.getColor() : undefined);
106
+ /** *********************颜色回退策略*********************/
107
+ // 1) colorObj 命中映射:使用映射颜色
108
+ // 2) 未命中但 options.fillColor 传入:使用传入的 fillColor
109
+ // 3) 都未提供:使用透明填充,避免沿用上一次更新的颜色
110
+ let newColor;
111
+ if (hasMappedColor) {
112
+ newColor = colorObj[name];
113
+ }
114
+ else if (options?.fillColor !== undefined) {
115
+ newColor = options.fillColor;
116
+ }
117
+ else {
118
+ newColor = withDefaultFill ? 'rgba(0, 0, 0, 0)' : undefined;
119
+ }
109
120
  const featureStyle = new Style({
110
121
  stroke: strokeColor !== undefined || strokeWidth !== undefined || lineDash !== undefined || lineDashOffset !== undefined
111
122
  ? new Stroke({ color: strokeColor, width: strokeWidth, lineDash, lineDashOffset })
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "my-openlayer",
3
3
  "private": false,
4
- "version": "3.1.3",
4
+ "version": "3.1.4",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "main": "index.js",