Skip to content

Commit a3f5e22

Browse files
committed
DBC22-5106: fixed featureContext events desync
1 parent d11411d commit a3f5e22

2 files changed

Lines changed: 32 additions & 5 deletions

File tree

src/frontend/src/Components/map/Map.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,8 +780,10 @@ export default function DriveBCMap(props) {
780780
// Count filtered events to store in routeDetails
781781
if (filteredEvents) {
782782
// Toggle features visibility
783-
const featuresDict = updateEventsLayers(mapContext, filteredEvents, mapLayers, setLoadingLayers, referenceData, mapView);
784-
setFeatureContext({...featureContext, events: featuresDict});
783+
updateEventsLayers(
784+
mapContext, filteredEvents, mapLayers, setLoadingLayers, referenceData, mapView,
785+
featureContext, setFeatureContext // DBC22-5106
786+
);
785787

786788
const eventCounts = {
787789
closures: 0,

src/frontend/src/Components/map/layers/eventsLayer.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ const addFeature = (feature, display_category, vsMap, lineVsMap, setNewFeatureSt
2828
}
2929

3030
// Helper function that creates a feature and updates its properties for each event
31-
const processEvent = (mapContext, event, currentProjection, vsMap, lineVsMap, referenceData, updateReferenceFeature, setNewFeatureStyle=false) => {
31+
const processEvent = (
32+
mapContext, event, currentProjection, vsMap, lineVsMap,
33+
referenceData, updateReferenceFeature, // Reference feature handling
34+
setNewFeatureStyle=false,
35+
eventFeaturesInContextDict=null
36+
) => {
3237
let eventFound = false;
3338

3439
// all events have a point coordinate for an icon; for line or zone
@@ -42,6 +47,11 @@ const processEvent = (mapContext, event, currentProjection, vsMap, lineVsMap, re
4247
pointFeature.getGeometry().transform('EPSG:4326', currentProjection);
4348
addFeature(pointFeature, event.display_category, vsMap, lineVsMap, setNewFeatureStyle);
4449

50+
// Save feature to featuresDict for route details panel
51+
if (eventFeaturesInContextDict && !(event.id in eventFeaturesInContextDict)) {
52+
eventFeaturesInContextDict[event.id] = pointFeature;
53+
}
54+
4555
if (event.location.type === 'Point') {
4656
savePointFeature(mapContext, event, pointFeature);
4757
}
@@ -190,8 +200,12 @@ export function loadEventsLayers(eventsData, mapContext, mapLayers, mapRef, refe
190200
return eventFound;
191201
}
192202

193-
export function updateEventsLayers(mapContext, events, mapLayers, setLoadingLayers, referenceData, mapView) {
203+
export function updateEventsLayers(
204+
mapContext, events, mapLayers, setLoadingLayers, referenceData, mapView,
205+
featureContext, setFeatureContext // Feature context for route details panel
206+
) {
194207
const featuresDict = {};
208+
const contextFeaturesDict = featureContext.events || {};
195209

196210
const eventsDict = events.reduce((dict, obj) => {
197211
dict[obj.id] = obj;
@@ -220,6 +234,11 @@ export function updateEventsLayers(mapContext, events, mapLayers, setLoadingLaye
220234
} else {
221235
feature.setStyle(new Style(null));
222236
}
237+
238+
// Store point features in dict for context
239+
if (!(layer.name.endsWith('Lines')) && !(feature.featureId in contextFeaturesDict)) {
240+
contextFeaturesDict[featureId] = feature;
241+
}
223242
}
224243
});
225244

@@ -236,9 +255,15 @@ export function updateEventsLayers(mapContext, events, mapLayers, setLoadingLaye
236255
Object.values(eventsDict).forEach((event) => {
237256
if (processedEvents.has(event.id)) { return; }
238257

239-
processEvent(mapContext, event, 'EPSG:3857', vsMap, lineVsMap, null, null, true);
258+
processEvent(mapContext, event, 'EPSG:3857', vsMap, lineVsMap, null, null, true, contextFeaturesDict);
240259
});
241260

261+
// Update feature context with new features
262+
setFeatureContext(prevState => ({
263+
...prevState,
264+
events: contextFeaturesDict
265+
}));
266+
242267
setLoadingLayers(prevState => ({
243268
...prevState,
244269
events: false

0 commit comments

Comments
 (0)