Skip to content

Commit

Permalink
Center bounds only if no map position is set
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfdsilva committed Jul 31, 2023
1 parent 66a4977 commit d5cb803
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions app/scripts/components/common/mapbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ function MapboxMapComponent(
id={`base-${baseLayerResolvedData.id}`}
stacCol={baseLayerResolvedData.stacCol}
mapInstance={mapRef.current}
urlPosition={initialPosition}

Check failure on line 422 in app/scripts/components/common/mapbox/index.tsx

View workflow job for this annotation

GitHub Actions / ts-check

Type '{ id: string; stacCol: string; mapInstance: Map; urlPosition: Partial<MapPosition> | undefined; date: Date | undefined; sourceParams: ObjResMap<Record<string, any>> | undefined; zoomExtent: number[] | undefined; bounds: number[] | undefined; onStatusChange: ({ status }: { ...; }) => void; }' is not assignable to type 'IntrinsicAttributes & (MapLayerRasterTimeseriesProps | MapLayerVectorTimeseriesProps | MapLayerZarrTimeseriesProps)'.
date={date}
sourceParams={baseLayerResolvedData.sourceParams}
zoomExtent={baseLayerResolvedData.zoomExtent}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export function MapLayerRasterTimeseries(props: MapLayerRasterTimeseriesProps) {
bounds,
onStatusChange,
isHidden,
idSuffix = ''
idSuffix = '',
urlPosition

Check failure on line 79 in app/scripts/components/common/mapbox/layers/raster-timeseries.tsx

View workflow job for this annotation

GitHub Actions / lint

'urlPosition' is missing in props validation

Check failure on line 79 in app/scripts/components/common/mapbox/layers/raster-timeseries.tsx

View workflow job for this annotation

GitHub Actions / ts-check

Property 'urlPosition' does not exist on type 'MapLayerRasterTimeseriesProps'.
} = props;

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

return null;
}
8 changes: 5 additions & 3 deletions app/scripts/components/common/mapbox/layers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const getCompareLayerData = (
type: otherLayer.type,
name: otherLayer.name,
description: otherLayer.description,
legend: otherLayer.legend,
legend: otherLayer.legend,
stacCol: otherLayer.stacCol,
zoomExtent: zoomExtent ?? otherLayer.zoomExtent,
sourceParams: defaultsDeep({}, sourceParams, otherLayer.sourceParams),
Expand Down Expand Up @@ -432,7 +432,6 @@ export function useLayerInteraction({
}, [layerId, mapInstance, onClick]);
}


type OptionalBbox = number[] | undefined | null;

/**
Expand All @@ -445,10 +444,13 @@ type OptionalBbox = number[] | undefined | null;
*/
export function useFitBbox(
mapInstance: MapboxMap,
urlPosition: any,
initialBbox: OptionalBbox,
stacBbox: OptionalBbox
) {
useEffect(() => {
if (urlPosition) return;

// Prefer layer defined bounds to STAC collection bounds.
const bounds = (initialBbox ?? stacBbox) as
| [number, number, number, number]
Expand All @@ -457,5 +459,5 @@ export function useFitBbox(
if (bounds?.length && checkFitBoundsFromLayer(bounds, mapInstance)) {
mapInstance.fitBounds(bounds, { padding: FIT_BOUNDS_PADDING });
}
}, [mapInstance, initialBbox, stacBbox]);
}, [mapInstance, urlPosition, initialBbox, stacBbox]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ import { Feature } from 'geojson';
import { endOfDay, startOfDay } from 'date-fns';
import centroid from '@turf/centroid';

import {
requestQuickCache,
useFitBbox,
useLayerInteraction
} from './utils';
import { requestQuickCache, useFitBbox, useLayerInteraction } from './utils';
import { useMapStyle } from './styles';
import { useCustomMarker } from './custom-marker';

Expand Down Expand Up @@ -47,7 +43,8 @@ export function MapLayerVectorTimeseries(props: MapLayerVectorTimeseriesProps) {
bounds,
onStatusChange,
isHidden,
idSuffix = ''
idSuffix = '',
urlPosition

Check failure on line 47 in app/scripts/components/common/mapbox/layers/vector-timeseries.tsx

View workflow job for this annotation

GitHub Actions / lint

'urlPosition' is missing in props validation

Check failure on line 47 in app/scripts/components/common/mapbox/layers/vector-timeseries.tsx

View workflow job for this annotation

GitHub Actions / ts-check

Property 'urlPosition' does not exist on type 'MapLayerVectorTimeseriesProps'.
} = props;

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

return null;
}
6 changes: 5 additions & 1 deletion app/scripts/components/datasets/s-explore/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,11 @@ function DatasetsExplore() {
compareDate={selectedCompareDatetime ?? undefined}
isComparing={isComparing}
initialPosition={mapPosition ?? undefined}
onPositionChange={setMapPosition}
onPositionChange={(v) => {
if (v.userInitiated) {
setMapPosition(v);
}
}}
projection={mapProjection ?? projectionDefault}
onProjectionChange={setMapProjection}
/>
Expand Down

0 comments on commit d5cb803

Please sign in to comment.