Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use recenteredMarkers #574

Merged
merged 6 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions packages/libs/components/src/map/SemanticMarkers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,39 +109,40 @@ export default function SemanticMarkers({
// but don't animate if we moved markers by 360 deg. longitude
// because the DriftMarker or Leaflet.Marker.SlideTo code seems to
// send everything back to the 'main' world.
if (
recenteredMarkers.length > 0 &&
prevMarkers.length > 0 &&
animation &&
!didRecenterMarkers
) {
if (recenteredMarkers.length > 0 && prevMarkers.length > 0 && animation) {
const animationValues = animation.animationFunction({
prevMarkers,
markers: recenteredMarkers,
});
setConsolidatedMarkers(animationValues.markers);
timeoutVariable = enqueueZoom(animationValues.zoomType);
timeoutVariable = enqueueZoom(
animationValues.zoomType,
recenteredMarkers
);
} else {
/** First render of markers **/
setConsolidatedMarkers(markers);
setConsolidatedMarkers(recenteredMarkers);
}

// Update previous markers with the original markers array
setPrevMarkers(markers);
// Update previous markers
setPrevMarkers(recenteredMarkers);
}

function enqueueZoom(zoomType: string | null) {
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(markers);
setConsolidatedMarkers(nextMarkers);
} else if (zoomType === 'out') {
/** If we are zooming out then remove the old markers after they finish animating. **/
return window.setTimeout(
() => {
setConsolidatedMarkers(markers);
setConsolidatedMarkers(nextMarkers);
},
animation ? animation.duration : 0
);
Expand All @@ -157,7 +158,8 @@ export default function SemanticMarkers({
[consolidatedMarkers]
);

useFlyToMarkers({ markers: refinedMarkers, flyToMarkers, flyToMarkersDelay });
// this should use the unadulterated markers (which are always in the "main world")
useFlyToMarkers({ markers, flyToMarkers, flyToMarkersDelay });

return <>{refinedMarkers}</>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ function MapLayerComponent(props: MapTypeMapLayerProps) {
!markerData.isFetching &&
isApproxSameViewport(props.appState.viewport, defaultViewport)
}
flyToMarkersDelay={500}
flyToMarkersDelay={2000}
/>
)}
</>
Expand Down Expand Up @@ -597,6 +597,7 @@ function useMarkerData(props: MarkerDataProps) {
data: markerData,
error,
isFetching,
isPreviousData,
} = useDistributionMarkerData(props);
if (markerData == null) return { error, isFetching };

Expand Down Expand Up @@ -648,7 +649,7 @@ function useMarkerData(props: MarkerDataProps) {

return {
error,
isFetching,
isFetching: isFetching || isPreviousData,
markerProps,
totalVisibleWithOverlayEntityCount,
totalVisibleEntityCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,10 @@ function BubbleMapLayer(props: MapTypeMapLayerProps) {
markers={markers}
animation={defaultAnimation}
flyToMarkers={
!markersData.isFetching &&
!(markersData.isFetching || markersData.isPreviousData) &&
isApproxSameViewport(props.appState.viewport, defaultViewport)
}
flyToMarkersDelay={500}
flyToMarkersDelay={2000}
/>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ function MapLayerComponent(props: MapTypeMapLayerProps) {
!markerDataResponse.isFetching &&
isApproxSameViewport(props.appState.viewport, defaultViewport)
}
flyToMarkersDelay={500}
flyToMarkersDelay={2000}
/>
)}
</>
Expand Down Expand Up @@ -438,6 +438,7 @@ function useMarkerData(props: DistributionMarkerDataProps) {
data: markerData,
error,
isFetching,
isPreviousData,
} = useDistributionMarkerData(props);

if (markerData == null) return { error, isFetching };
Expand Down Expand Up @@ -472,7 +473,7 @@ function useMarkerData(props: DistributionMarkerDataProps) {

return {
error,
isFetching,
isFetching: isFetching || isPreviousData,
markerProps,
totalVisibleWithOverlayEntityCount,
totalVisibleEntityCount,
Expand Down
Loading