This repository has been archived by the owner on Apr 25, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: main logic of the new layer system (#370)
* init * impl cesium * enable vitest on vscode * support photooverlay * define appearance types * add delegatedDataTypes * fix storybook * fix * chore: update codeowners [ci skip]
- Loading branch information
Showing
82 changed files
with
10,500 additions
and
14 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
* @KaWaite | ||
/e2e/ @rot1024 | ||
/src/core/ @rot1024 | ||
/.github/ @KaWaite @rot1024 | ||
/src/components/atoms/Plugin/ @KaWaite @rot1024 | ||
/src/components/molecules/Visualizer/ @KaWaite @rot1024 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type Props = {}; | ||
|
||
export default function Infobox(_props: Props): JSX.Element | null { | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type Props = {}; | ||
|
||
export default function Plugins(_props: Props): JSX.Element | null { | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type Props = {}; | ||
|
||
export default function Widgets(_props: Props): JSX.Element | null { | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export type Props = {}; | ||
|
||
export default function Crust(_props: Props): JSX.Element | null { | ||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { ComponentType, useMemo, useCallback, ReactNode } from "react"; | ||
|
||
import type { Layer, Atom, Typography, DataType } from "../../mantle"; | ||
import LayerComponent, { type CommonProps, type Props as LayerProps } from "../Layer"; | ||
|
||
export type Props = { | ||
layers?: Layer[]; | ||
atomMap?: Map<string, Atom>; | ||
overrides?: Record<string, Record<string, any>>; | ||
selectedLayerId?: string; | ||
isHidden?: (id: string) => boolean; | ||
clusters?: Cluster[]; | ||
delegatedDataTypes?: DataType[]; | ||
clusterComponent?: ClusterComponentType; | ||
Feature?: LayerProps["Feature"]; | ||
} & Omit<CommonProps, "isSelected" | "isHidden">; | ||
|
||
export type Cluster = { | ||
id: string; | ||
property?: ClusterProperty; | ||
layers?: string[]; | ||
}; | ||
|
||
export type ClusterComponentProps = { | ||
cluster: Cluster; | ||
property?: ClusterProperty; | ||
children?: ReactNode; | ||
}; | ||
|
||
export type ClusterProperty = { | ||
default?: { | ||
clusterPixelRange: number; | ||
clusterMinSize: number; | ||
clusterLabelTypography?: Typography; | ||
clusterImage?: string; | ||
clusterImageHeight?: number; | ||
clusterImageWidth?: number; | ||
}; | ||
layers?: { layer?: string }[]; | ||
}; | ||
|
||
export type ClusterComponentType = ComponentType<ClusterComponentProps>; | ||
|
||
export default function ClusteredLayers({ | ||
clusters, | ||
clusterComponent, | ||
layers, | ||
atomMap, | ||
selectedLayerId, | ||
overrides, | ||
delegatedDataTypes, | ||
isHidden, | ||
...props | ||
}: Props): JSX.Element | null { | ||
const Cluster = clusterComponent; | ||
const clusteredLayers = useMemo<Set<string>>( | ||
() => new Set(clusters?.flatMap(c => (c.layers ?? []).filter(Boolean))), | ||
[clusters], | ||
); | ||
|
||
const renderLayer = useCallback( | ||
(layer: Layer) => { | ||
const a = atomMap?.get(layer.id); | ||
return !layer.id || !a ? null : ( | ||
<LayerComponent | ||
key={layer.id} | ||
{...props} | ||
layer={layer} | ||
atom={a} | ||
overrides={overrides?.[layer.id]} | ||
isSelected={!!selectedLayerId && selectedLayerId == layer.id} | ||
isHidden={isHidden?.(layer.id)} | ||
delegatedDataTypes={delegatedDataTypes} | ||
/> | ||
); | ||
}, | ||
[atomMap, isHidden, overrides, props, selectedLayerId, delegatedDataTypes], | ||
); | ||
|
||
return ( | ||
<> | ||
{Cluster && | ||
clusters | ||
?.filter(cluster => !!cluster.id) | ||
.map(cluster => ( | ||
<Cluster key={cluster.id} cluster={cluster}> | ||
{layers?.filter(layer => cluster?.layers?.some(l => l === layer.id)).map(renderLayer)} | ||
</Cluster> | ||
))} | ||
{layers?.filter(layer => !clusteredLayers.has(layer.id)).map(renderLayer)} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { useAtom } from "jotai"; | ||
import { useCallback, useLayoutEffect, useMemo } from "react"; | ||
|
||
import { computeAtom, DataType, type Atom } from "../../mantle"; | ||
import type { DataRange, Feature, Layer } from "../../mantle"; | ||
|
||
export type { Atom as Atoms } from "../../mantle"; | ||
|
||
export const createAtom = computeAtom; | ||
|
||
export default function useHooks( | ||
layer: Layer | undefined, | ||
atom: Atom | undefined, | ||
overrides?: Record<string, any>, | ||
delegatedDataTypes?: DataType[], | ||
) { | ||
const [computedLayer, set] = useAtom(useMemo(() => atom ?? createAtom(), [atom])); | ||
const writeFeatures = useCallback( | ||
(features: Feature[]) => set({ type: "writeFeatures", features }), | ||
[set], | ||
); | ||
const requestFetch = useCallback( | ||
(range: DataRange) => set({ type: "requestFetch", range }), | ||
[set], | ||
); | ||
const deleteFeatures = useCallback( | ||
(features: string[]) => set({ type: "deleteFeatures", features }), | ||
[set], | ||
); | ||
|
||
useLayoutEffect(() => { | ||
set({ type: "updateDelegatedDataTypes", delegatedDataTypes: delegatedDataTypes ?? [] }); | ||
}, [delegatedDataTypes, set]); | ||
|
||
useLayoutEffect(() => { | ||
set({ | ||
type: "override", | ||
overrides, | ||
}); | ||
}, [set, overrides]); | ||
|
||
useLayoutEffect(() => { | ||
set({ | ||
type: "setLayer", | ||
layer: | ||
typeof layer?.visible === "undefined" || layer?.type === null || layer?.type | ||
? layer | ||
: undefined, | ||
}); | ||
}, [layer, set]); | ||
|
||
return { | ||
computedLayer, | ||
handleFeatureRequest: requestFetch, | ||
handleFeatureFetch: writeFeatures, | ||
handleFeatureDelete: deleteFeatures, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { ComponentType } from "react"; | ||
|
||
import type { DataRange, Feature, ComputedLayer, Layer, DataType } from "../../mantle"; | ||
|
||
import useHooks, { type Atoms } from "./hooks"; | ||
|
||
export type { Layer, LayerSimple } from "../../mantle"; | ||
|
||
export type FeatureComponentType = ComponentType<FeatureComponentProps>; | ||
|
||
export type CommonProps = { | ||
isBuilt?: boolean; | ||
isEditable?: boolean; | ||
isHidden?: boolean; | ||
isSelected?: boolean; | ||
sceneProperty?: any; | ||
}; | ||
|
||
export type FeatureComponentProps = { | ||
layer: ComputedLayer; | ||
onFeatureRequest?: (range: DataRange) => void; | ||
onFeatureFetch?: (features: Feature[]) => void; | ||
onFeatureDelete?: (features: string[]) => void; | ||
} & CommonProps; | ||
|
||
export type Props = { | ||
layer?: Layer; | ||
atom?: Atoms; | ||
overrides?: Record<string, any>; | ||
delegatedDataTypes?: DataType[]; | ||
/** Feature component should be injected by a map engine. */ | ||
Feature?: ComponentType<FeatureComponentProps>; | ||
} & CommonProps; | ||
|
||
export default function LayerComponent({ | ||
Feature, | ||
layer, | ||
atom: atoms, | ||
overrides, | ||
delegatedDataTypes, | ||
...props | ||
}: Props): JSX.Element | null { | ||
const { computedLayer, handleFeatureDelete, handleFeatureFetch, handleFeatureRequest } = useHooks( | ||
Feature ? layer : undefined, | ||
atoms, | ||
overrides, | ||
delegatedDataTypes, | ||
); | ||
|
||
return layer && computedLayer && Feature ? ( | ||
<Feature | ||
layer={computedLayer} | ||
onFeatureDelete={handleFeatureDelete} | ||
onFeatureFetch={handleFeatureFetch} | ||
onFeatureRequest={handleFeatureRequest} | ||
{...props} | ||
/> | ||
) : null; | ||
} |
Oops, something went wrong.