Skip to content

Commit

Permalink
Fixed issues of map not refreshing on change by triggering useEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoleiftekhar committed Aug 15, 2024
1 parent 202aa28 commit 3f1a52a
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/pages/conversion/places-preview-map/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,22 +269,33 @@ const PlacesPreviewMap = ({ style, unitsChanged, levelsChanged, footprintChanged
dmLayers.polygonLayer.setOptions({ visible: false });
dmLayers.polygonOutlineLayer.setOptions({ visible: false });
layersAdded = [unitLayer, unitLines, polygonHoverLayer, polygonClickLayer, unitSymbols];

console.log('hi');

map.events.add('drawingmodechanged', drawingManager, (e) => {
let dmLayers = drawingManager.getLayers();
layersAdded = [unitLayer, unitLines, polygonHoverLayer, polygonClickLayer, unitSymbols];

if (e === 'idle') {
console.log('hey');
setDrawNotif(false);
let updatedFeatures = drawingManager.getSource().shapes;

deleteUnitPrevEdits(units, selectedLevel);
updatedFeatures.forEach((feature, index) => {
if(isNaN(feature.data.properties.ordinal)) {
setFields(feature, selectedLevel);
units.features.push(feature.data);

const newFeatures = updatedFeatures.reduce((acc, feature) => {
if (isNaN(feature.data.properties.ordinal)) {
setFields(feature, selectedLevel);
acc.push(feature.data);
}
});
return acc;
}, []);

setUnits(prevUnits => ({
...prevUnits,
features: [...prevUnits.features, ...newFeatures],
}));


// Update the units state with the edited features (for updating zip)
unitsChanged(units);
Expand Down

0 comments on commit 3f1a52a

Please sign in to comment.