-
Notifications
You must be signed in to change notification settings - Fork 6
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
Display selected datasets on the map #668
Changes from all commits
9949537
ac17b50
3be9f44
9a1c07c
8fb81af
0cc3745
c055024
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { useMemo } from 'react'; | ||
import { BaseGeneratorParams } from '../types'; | ||
|
||
export default function useGeneratorParams(props: BaseGeneratorParams) { | ||
return useMemo(() => { | ||
return props; | ||
// Memoize only required abse params | ||
}, [props.generatorOrder, props.hidden, props.opacity]); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
import axios, { Method } from 'axios'; | ||
import { Map as MapboxMap } from 'mapbox-gl'; | ||
import { MapRef } from 'react-map-gl'; | ||
import { endOfDay, startOfDay } from "date-fns"; | ||
import { StacFeature } from "./types"; | ||
import { userTzDate2utcString } from "$utils/date"; | ||
import { validateRangeNum } from "$utils/utils"; | ||
import { endOfDay, startOfDay } from 'date-fns'; | ||
import { | ||
DatasetDatumFn, | ||
DatasetDatumFnResolverBag, | ||
DatasetDatumReturnType | ||
} from 'veda'; | ||
|
||
import { StacFeature } from './types'; | ||
|
||
import { userTzDate2utcString } from '$utils/date'; | ||
import { validateRangeNum } from '$utils/utils'; | ||
|
||
export const FIT_BOUNDS_PADDING = 32; | ||
|
||
export const validateLon = validateRangeNum(-180, 180); | ||
export const validateLat = validateRangeNum(-90, 90); | ||
|
||
|
||
|
||
export function getMergedBBox(features: StacFeature[]) { | ||
const mergedBBox = [ | ||
Number.POSITIVE_INFINITY, | ||
|
@@ -32,8 +36,6 @@ export function getMergedBBox(features: StacFeature[]) { | |
) as [number, number, number, number]; | ||
} | ||
|
||
|
||
|
||
export function checkFitBoundsFromLayer( | ||
layerBounds?: [number, number, number, number], | ||
mapInstance?: MapboxMap | MapRef | ||
|
@@ -58,8 +60,6 @@ export function checkFitBoundsFromLayer( | |
return layerExtentSmaller || isOutside; | ||
} | ||
|
||
|
||
|
||
/** | ||
* Creates the appropriate filter object to send to STAC. | ||
* | ||
|
@@ -87,7 +87,6 @@ export function getFilterPayload(date: Date, collection: string) { | |
}; | ||
} | ||
|
||
|
||
// There are cases when the data can't be displayed properly on low zoom levels. | ||
// In these cases instead of displaying the raster tiles, we display markers to | ||
// indicate whether or not there is data in a given location. When the user | ||
|
@@ -123,3 +122,61 @@ export async function requestQuickCache({ | |
return quickCache.get(key); | ||
} | ||
|
||
type Fn = (...args: any[]) => any; | ||
|
||
type ObjResMap<T> = { | ||
[K in keyof T]: Res<T[K]>; | ||
}; | ||
|
||
type Res<T> = T extends Fn | ||
? T extends DatasetDatumFn<DatasetDatumReturnType> | ||
? DatasetDatumReturnType | ||
: never | ||
: T extends any[] | ||
? Res<T[number]>[] | ||
: T extends object | ||
? ObjResMap<T> | ||
: T; | ||
|
||
export function resolveConfigFunctions<T>( | ||
datum: T, | ||
bag: DatasetDatumFnResolverBag | ||
): Res<T>; | ||
export function resolveConfigFunctions<T extends any[]>( | ||
datum: T, | ||
bag: DatasetDatumFnResolverBag | ||
): Res<T[number]>[]; | ||
export function resolveConfigFunctions( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TBH I'm struggling to understand what this does. Sorry, might just be a case of Friday afternoon. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This basically resolves the functions in the dataset config and is needed to support this behavior. This was used in the past for the customization of the compare map message. Although it is a neat little power user functionality, not sure it is used (known/needed) a lot. |
||
datum: any, | ||
bag: DatasetDatumFnResolverBag | ||
): any { | ||
if (Array.isArray(datum)) { | ||
return datum.map((v) => resolveConfigFunctions(v, bag)); | ||
} | ||
|
||
if (datum != null && typeof datum === 'object') { | ||
// Use for loop instead of reduce as it faster. | ||
const ready = {}; | ||
for (const [k, v] of Object.entries(datum as object)) { | ||
ready[k] = resolveConfigFunctions(v, bag); | ||
} | ||
return ready; | ||
} | ||
|
||
if (typeof datum === 'function') { | ||
try { | ||
return datum(bag); | ||
} catch (error) { | ||
/* eslint-disable-next-line no-console */ | ||
console.error( | ||
'Failed to resolve function %s(%o) with error %s', | ||
datum.name, | ||
bag, | ||
error.message | ||
); | ||
return null; | ||
} | ||
} | ||
|
||
return datum; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to
types.d.ts
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These types are only ever used for the
resolveConfigFunctions
function declaration and are not needed elsewhere so I think they can live with the declaration. However feel free to move them if you like