Skip to content

Commit

Permalink
Merge pull request #2577 from GlobalFishingWatch:deck-migration/fourw…
Browse files Browse the repository at this point in the history
…ings-static

deck heatmap static layer
  • Loading branch information
j8seangel authored Mar 25, 2024
2 parents 04403f0 + 2dfee2a commit f057cc4
Show file tree
Hide file tree
Showing 17 changed files with 371 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export const selectActiveActivityDataviews = createSelector(
export const selectActivityMergedDataviewId = createSelector(
[selectActiveActivityDataviews],
(dataviews): string => {
return getMergedDataviewId(dataviews)
return dataviews?.length ? getMergedDataviewId(dataviews) : ''
}
)

Expand All @@ -219,7 +219,7 @@ export const selectActiveDetectionsDataviews = createSelector(
export const selectDetectionsMergedDataviewId = createSelector(
[selectActiveDetectionsDataviews],
(dataviews): string => {
return getMergedDataviewId(dataviews)
return dataviews?.length ? getMergedDataviewId(dataviews) : ''
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const useHeatmapActivityGraph = () => {
const start = getUTCDate(timerange.start).getTime()
const end = getUTCDate(timerange.end).getTime()
const chunk = getChunk(start, end)
const id = getMergedDataviewId(dataviews)
const id = dataviews?.length ? getMergedDataviewId(dataviews) : ''
const fourwingsActivityLayer = useGetDeckLayer<FourwingsLayer>(id)
const { loaded, instance } = fourwingsActivityLayer || {}
const heatmapActivity = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { GeoJSONFeature } from '@globalfishingwatch/maplibre-gl'
import type { FourWingsFeature } from '@globalfishingwatch/deck-loaders'
import type { FourWingsFeature, FourWingsStaticFeature } from '@globalfishingwatch/deck-loaders'

export interface Bounds {
north: number
Expand All @@ -9,7 +9,7 @@ export interface Bounds {
}

export const filterFeaturesByBounds = (
features: GeoJSONFeature[] | FourWingsFeature[],
features: GeoJSONFeature[] | FourWingsFeature[] | FourWingsStaticFeature[],
bounds: Bounds
) => {
if (!bounds) {
Expand Down
23 changes: 15 additions & 8 deletions libs/deck-layer-composer/src/resolvers/dataviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ function isEnvironmentalDataview(dataview: UrlDataviewInstance) {
)
}

function isHeatmapStaticDataview(dataview: UrlDataviewInstance) {
return dataview.config?.type === DataviewType.HeatmapStatic
}

function isTrackDataview(dataview: UrlDataviewInstance) {
return (
dataview.category === DataviewCategory.Vessels && dataview.config?.type === DataviewType.Track
Expand Down Expand Up @@ -136,6 +140,8 @@ export function getFourwingsDataviewsResolved(
config: {
type: fourwingsDataviews[0]?.config?.type,
sublayers: fourwingsDataviews.flatMap(getFourwingsDataviewSublayers),
minVisibleValue: fourwingsDataviews[0].config?.minVisibleValue,
maxVisibleValue: fourwingsDataviews[0].config?.maxVisibleValue,
colorRampWhiteEnd,
visualizationMode,
comparisonMode,
Expand Down Expand Up @@ -224,7 +230,7 @@ export function getDataviewsResolved(
const {
activityDataviews,
detectionDataviews,
environmentalDataviews,
fourwingsDataviews,
trackDataviews,
otherDataviews,
} = dataviews.reduce(
Expand All @@ -233,8 +239,8 @@ export function getDataviewsResolved(
acc.activityDataviews.push(dataview)
} else if (isDetectionsDataview(dataview)) {
acc.detectionDataviews.push(dataview)
} else if (isEnvironmentalDataview(dataview)) {
acc.environmentalDataviews.push(dataview)
} else if (isEnvironmentalDataview(dataview) || isHeatmapStaticDataview(dataview)) {
acc.fourwingsDataviews.push(dataview)
} else if (isTrackDataview(dataview)) {
acc.trackDataviews.push(dataview)
} else {
Expand All @@ -245,14 +251,14 @@ export function getDataviewsResolved(
{
activityDataviews: [] as UrlDataviewInstance[],
detectionDataviews: [] as UrlDataviewInstance[],
environmentalDataviews: [] as UrlDataviewInstance[],
fourwingsDataviews: [] as UrlDataviewInstance[],
trackDataviews: [] as UrlDataviewInstance[],
otherDataviews: [] as UrlDataviewInstance[],
}
)

const singleHeatmapDataview =
[...activityDataviews, ...detectionDataviews, ...environmentalDataviews].length === 1
[...activityDataviews, ...detectionDataviews, ...fourwingsDataviews].length === 1
const activityComparisonMode = activityDataviews.every((dataview) =>
params.bivariateDataviews?.includes(dataview.id)
)
Expand Down Expand Up @@ -280,17 +286,18 @@ export function getDataviewsResolved(
colorRampWhiteEnd: singleHeatmapDataview,
})
: []
const environmentalDataviewsParsed = environmentalDataviews.flatMap(
const fourwingsDataviewsParsed = fourwingsDataviews.flatMap(
(d) =>
getFourwingsDataviewsResolved(d, {
colorRampWhiteEnd: singleHeatmapDataview,
colorRampWhiteEnd:
d.config?.type === DataviewType.HeatmapStatic ? false : singleHeatmapDataview,
}) || []
)
const dataviewsMerged = [
...otherDataviews,
...mergedActivityDataview,
...mergedDetectionsDataview,
...environmentalDataviewsParsed,
...fourwingsDataviewsParsed,
...trackDataviews,
]
return dataviewsMerged
Expand Down
10 changes: 9 additions & 1 deletion libs/deck-layer-composer/src/resolvers/fourwings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import {
TIME_COMPARISON_NOT_SUPPORTED_INTERVALS,
getUTCDateTime,
} from '@globalfishingwatch/deck-layers'
import { DatasetTypes, DataviewCategory, EndpointId } from '@globalfishingwatch/api-types'
import {
DatasetTypes,
DataviewCategory,
DataviewType,
EndpointId,
} from '@globalfishingwatch/api-types'
import { ColorRampId } from '@globalfishingwatch/deck-layers'
import { resolveEndpoint } from '@globalfishingwatch/datasets-client'
import { getDataviewAvailableIntervals } from './dataviews'
Expand Down Expand Up @@ -90,13 +95,16 @@ export const resolveDeckFourwingsLayerProps = (
id: dataview.id,
minFrame: startTime,
maxFrame: endTime,
static: dataview.config?.type === DataviewType.HeatmapStatic,
resolution,
sublayers,
comparisonMode,
visualizationMode,
aggregationOperation,
availableIntervals,
hoveredFeatures: interactions,
minVisibleValue: dataview.config?.minVisibleValue,
maxVisibleValue: dataview.config?.maxVisibleValue,
debug: dataview.config?.debug ?? false,
visible: dataview.config?.visible ?? true,
colorRampWhiteEnd: dataview.config?.colorRampWhiteEnd ?? false,
Expand Down
5 changes: 4 additions & 1 deletion libs/deck-layer-composer/src/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ export const dataviewToDeckLayer = (
const deckLayerProps = resolveDeckBasemapLayerProps(dataview)
return new BaseMapLayer(deckLayerProps)
}
if (dataview.config?.type === DataviewType.HeatmapAnimated) {
if (
dataview.config?.type === DataviewType.HeatmapAnimated ||
dataview.config?.type === DataviewType.HeatmapStatic
) {
const deckLayerProps = resolveDeckFourwingsLayerProps(dataview, globalConfig, interactions)
const layer = new FourwingsLayer(deckLayerProps)
return layer
Expand Down
4 changes: 2 additions & 2 deletions libs/deck-layers/src/layers/context/ContextLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
LayerGroup,
getLayerGroupOffset,
getPickedFeatureToHighlight,
GFWContextLoader,
GFWMVTLoader,
getMVTSublayerProps,
} from '../../utils'
import { API_PATH } from './context.config'
Expand Down Expand Up @@ -57,7 +57,7 @@ export class ContextLayer<PropsT = {}> extends CompositeLayer<
new TileLayer<TileLayerProps>({
id: `${this.id}-base-layer`,
data: `${API_PATH}/${this.props.datasetId}/context-layers/{z}/{x}/{y}`,
loaders: [GFWContextLoader],
loaders: [GFWMVTLoader],
maxRequests: 100,
debounceTime: 500,
renderSubLayers: (props: any) => {
Expand Down
6 changes: 3 additions & 3 deletions libs/deck-layers/src/layers/context/EEZLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
hexToDeckColor,
LayerGroup,
getLayerGroupOffset,
GFWContextLoader,
GFWMVTLoader,
getMVTSublayerProps,
} from '../../utils'
import { ContextLayer } from './ContextLayer'
Expand Down Expand Up @@ -51,7 +51,7 @@ export class EEZLayer extends ContextLayer<EEZLayerProps> {
new TileLayer<TileLayerProps>({
id: `${this.id}-boundaries-layer`,
data: `${API_PATH}/${this.props.boundariesDatasetId}/context-layers/{z}/{x}/{y}`,
loaders: [GFWContextLoader],
loaders: [GFWMVTLoader],
maxRequests: 100,
debounceTime: 500,
renderSubLayers: (props: any) => {
Expand All @@ -77,7 +77,7 @@ export class EEZLayer extends ContextLayer<EEZLayerProps> {
new TileLayer<TileLayerProps>({
id: `${this.id}-base-layer`,
data: `${API_PATH}/${this.props.areasDatasetId}/context-layers/{z}/{x}/{y}`,
loaders: [GFWContextLoader],
loaders: [GFWMVTLoader],
maxRequests: 100,
debounceTime: 500,
renderSubLayers: (props: any) => {
Expand Down
Loading

0 comments on commit f057cc4

Please sign in to comment.