Skip to content

Commit

Permalink
90 percent fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
bobular committed Nov 1, 2024
1 parent 0bd958f commit 48d15cf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 42 deletions.
47 changes: 11 additions & 36 deletions packages/libs/components/src/map/SemanticMarkers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function SemanticMarkers({
// 2023-11: it does seem to be needed for zoom-in animation to work.
const debouncedUpdateMarkerPositions = debounce(
updateMarkerPositions,
1000
animation ? animation.duration : 0
);
// call it at least once at the beginning of the life cycle
debouncedUpdateMarkerPositions();
Expand Down Expand Up @@ -126,27 +126,23 @@ export default function SemanticMarkers({
) {
// get the position-modified markers from `animationFunction`
// see geohash.tsx for example
const animationValues = animation.animationFunction({
prevMarkers: prevRecenteredMarkers,
markers: recenteredMarkers,
});
const { markers: oldAndNewRepositionedMarkers } =
animation.animationFunction({
prevMarkers: prevRecenteredMarkers,
markers: recenteredMarkers,
});
// set them as current
// any marker that already existed will move to the modified position
if (
!isEqual(
animationValues.markers.map(({ props }) => props),
oldAndNewRepositionedMarkers.map(({ props }) => props),
consolidatedMarkers.map(({ props }) => props)
)
)
setConsolidatedMarkers(animationValues.markers);
// then set a timer to remove the old markers when zooming out
// or if zooming in, switch to just the new markers straight away
// (their starting position was set by `animationFunction`)
// It's complicated but it works!
timeoutVariable = enqueueZoom(
animationValues.zoomType,
recenteredMarkers
);
setConsolidatedMarkers(oldAndNewRepositionedMarkers);

// we used to set a timer to remove the old markers when zooming out
// but now we just let the next render cycle do it.
} else {
/** First render of markers **/
if (
Expand All @@ -171,27 +167,6 @@ export default function SemanticMarkers({
)
setPrevRecenteredMarkers(recenteredMarkers);
}

function enqueueZoom(
zoomType: string | null,
nextMarkers: ReactElement<BoundsDriftMarkerProps>[]
) {
/** If we are zooming in then reset the marker elements. When initially rendered
* the new markers will start at the matching existing marker's location and here we will
* reset marker elements so they will animated to their final position
**/
if (zoomType === 'in') {
setConsolidatedMarkers(nextMarkers);
} else if (zoomType === 'out') {
/** If we are zooming out then remove the old markers after they finish animating. **/
return window.setTimeout(
() => {
setConsolidatedMarkers(nextMarkers);
},
animation ? animation.duration : 0
);
}
}
}, [
animation,
map,
Expand Down
11 changes: 5 additions & 6 deletions packages/libs/components/src/map/animation_functions/geohash.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export default function geohashAnimation({
if (prevGeoHash.length > currentGeohash.length) {
zoomType = 'out';
const hashDif = prevGeoHash.length - currentGeohash.length;
// Get a new array of existing markers with new position property
// Get array of old markers with new positions
const cloneArray = updateMarkers(prevMarkers, markers, hashDif);
// Combine the new and existing markers
// Combine the new and old markers
consolidatedMarkers = [...markers, ...cloneArray];
} else if (prevGeoHash.length < currentGeohash.length) {
/** Zoom In - New markers start at old position
Expand All @@ -33,10 +33,9 @@ export default function geohashAnimation({
**/
zoomType = 'in';
const hashDif = currentGeohash.length - prevGeoHash.length;
// Get a new array of new markers with existing position property
// Set final render markers to the cloneArray which holds the new markers with
// their new starting location
consolidatedMarkers = updateMarkers(markers, prevMarkers, hashDif);
// Get array of new markers with old positions
const cloneArray = updateMarkers(markers, prevMarkers, hashDif);
consolidatedMarkers = [...prevMarkers, ...cloneArray];
} else {
/** No difference in geohashes - Render markers as they are **/
zoomType = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export default function updateMarkers(
// Clone marker element with new position
markerCloneProps = {
position: matchingMarkers[0].props.position,
// ideally we would put the modified markers on top
// but this doesn't seem to work:
// zIndexOffset: -1000, // or +1000
};
}

Expand Down

0 comments on commit 48d15cf

Please sign in to comment.