Skip to content

Commit

Permalink
Update variables and types
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfdsilva committed Aug 2, 2023
1 parent 58f232b commit f654526
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/scripts/components/common/mapbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ function MapboxMapComponent(
id={`base-${baseLayerResolvedData.id}`}
stacCol={baseLayerResolvedData.stacCol}
mapInstance={mapRef.current}
urlPosition={initialPosition}
isPositionSet={!!initialPosition}
date={date}
sourceParams={baseLayerResolvedData.sourceParams}
zoomExtent={baseLayerResolvedData.zoomExtent}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export interface MapLayerRasterTimeseriesProps {
onStatusChange?: (result: { status: ActionStatus; id: string }) => void;
isHidden?: boolean;
idSuffix?: string;
isPositionSet?: boolean;
}

export interface StacFeature {
Expand Down Expand Up @@ -76,7 +77,7 @@ export function MapLayerRasterTimeseries(props: MapLayerRasterTimeseriesProps) {
onStatusChange,
isHidden,
idSuffix = '',
urlPosition
isPositionSet
} = props;

const theme = useTheme();
Expand Down Expand Up @@ -472,7 +473,7 @@ export function MapLayerRasterTimeseries(props: MapLayerRasterTimeseriesProps) {
() => (stacCollection.length ? getMergedBBox(stacCollection) : undefined),
[stacCollection]
);
useFitBbox(mapInstance, urlPosition, bounds, layerBounds);
useFitBbox(mapInstance, !!isPositionSet, bounds, layerBounds);

return null;
}
12 changes: 7 additions & 5 deletions app/scripts/components/common/mapbox/layers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,21 +435,23 @@ export function useLayerInteraction({
type OptionalBbox = number[] | undefined | null;

/**
* Centers on the given bounds if the current position is not within the bounds.
* Gives preference to the layer defined bounds over the STAC collection bounds.
* Centers on the given bounds if the current position is not within the bounds,
* and there's no user defined position (via user initiated map movement). Gives
* preference to the layer defined bounds over the STAC collection bounds.
*
* @param mapInstance Mapbox instance
* @param isUserPositionSet Whether the user has set a position
* @param initialBbox Bounding box from the layer
* @param stacBbox Bounds from the STAC collection
*/
export function useFitBbox(
mapInstance: MapboxMap,
urlPosition: any,
isUserPositionSet: boolean,
initialBbox: OptionalBbox,
stacBbox: OptionalBbox
) {
useEffect(() => {
if (urlPosition) return;
if (isUserPositionSet) return;

// Prefer layer defined bounds to STAC collection bounds.
const bounds = (initialBbox ?? stacBbox) as
Expand All @@ -459,5 +461,5 @@ export function useFitBbox(
if (bounds?.length && checkFitBoundsFromLayer(bounds, mapInstance)) {
mapInstance.fitBounds(bounds, { padding: FIT_BOUNDS_PADDING });
}
}, [mapInstance, urlPosition, initialBbox, stacBbox]);
}, [mapInstance, isUserPositionSet, initialBbox, stacBbox]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface MapLayerVectorTimeseriesProps {
onStatusChange?: (result: { status: ActionStatus; id: string }) => void;
isHidden?: boolean;
idSuffix?: string;
isPositionSet?: boolean;
}

export function MapLayerVectorTimeseries(props: MapLayerVectorTimeseriesProps) {
Expand All @@ -44,7 +45,7 @@ export function MapLayerVectorTimeseries(props: MapLayerVectorTimeseriesProps) {
onStatusChange,
isHidden,
idSuffix = '',
urlPosition
isPositionSet
} = props;

const theme = useTheme();
Expand Down Expand Up @@ -285,7 +286,7 @@ export function MapLayerVectorTimeseries(props: MapLayerVectorTimeseriesProps) {
//
// FitBounds when needed
//
useFitBbox(mapInstance, urlPosition, bounds, featuresBbox);
useFitBbox(mapInstance, !!isPositionSet, bounds, featuresBbox);

return null;
}
2 changes: 2 additions & 0 deletions app/scripts/components/datasets/s-explore/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,8 @@ function DatasetsExplore() {
isComparing={isComparing}
initialPosition={mapPosition ?? undefined}
onPositionChange={(v) => {
// Only store the map position if the change was initiated by
// the user.
if (v.userInitiated) {
setMapPosition(v);
}
Expand Down

0 comments on commit f654526

Please sign in to comment.