-
Notifications
You must be signed in to change notification settings - Fork 64
Legends for Vector Layers #880
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
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
4883cb2
legends wip
arjxn-py 85056a1
lint
arjxn-py 29415a4
categorised working
arjxn-py c04b2e8
style fix
arjxn-py 51209f9
don't fire too often
arjxn-py 121fcd3
do something
arjxn-py faed8b2
rework
arjxn-py 2246863
style fix
arjxn-py b955184
horizontal colorbar
arjxn-py 641428e
not needed
arjxn-py ee5affc
not needed
arjxn-py 6ea43d7
lint
arjxn-py d201a78
simplify hook
arjxn-py af8d8d0
property label
arjxn-py 5078608
conditionally render legend
arjxn-py cb002c1
lint
arjxn-py 6483d57
Merge branch 'main' into legends
arjxn-py ef73695
swamps for categorised and gradient for graduated
arjxn-py 2b7badb
max height and overflow for categorised
arjxn-py File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
packages/base/src/dialogs/symbology/hooks/useGetSymbology.ts
This file contains hidden or 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,83 @@ | ||
| import { IJupyterGISModel } from '@jupytergis/schema'; | ||
| import { useEffect, useState } from 'react'; | ||
|
|
||
| interface IUseGetSymbologyProps { | ||
| layerId?: string; | ||
| model: IJupyterGISModel; | ||
| } | ||
|
|
||
| interface IUseGetSymbologyResult { | ||
| symbology: Record<string, any> | null; | ||
| isLoading: boolean; | ||
| error?: Error; | ||
| } | ||
|
|
||
| /** | ||
| * Extracts symbology information (paint/layout + symbologyState) | ||
| * for a given layer from the JupyterGIS model. | ||
| * Keeps symbology updated when the layer changes. | ||
| */ | ||
| export const useGetSymbology = ({ | ||
| layerId, | ||
| model, | ||
| }: IUseGetSymbologyProps): IUseGetSymbologyResult => { | ||
| const [symbology, setSymbology] = useState<Record<string, any> | null>(null); | ||
| const [isLoading, setIsLoading] = useState(true); | ||
| const [error, setError] = useState<Error | undefined>(); | ||
|
|
||
| useEffect(() => { | ||
| if (!layerId) { | ||
| return; | ||
| } | ||
|
|
||
| let disposed = false; | ||
|
|
||
| const fetchSymbology = () => { | ||
| try { | ||
| setIsLoading(true); | ||
| setError(undefined); | ||
|
|
||
| const layer = model.getLayer(layerId); | ||
|
|
||
| if (!layer) { | ||
| throw new Error(`Layer not found: ${layerId}`); | ||
| } | ||
|
|
||
| const params = layer.parameters ?? {}; | ||
| const { symbologyState, color, ...rest } = params; | ||
|
|
||
| const result: Record<string, any> = { | ||
| ...rest, | ||
| ...(color ? { color } : {}), | ||
| ...(symbologyState ? { symbologyState } : {}), | ||
| }; | ||
|
|
||
| if (!disposed) { | ||
| setSymbology(result); | ||
| } | ||
| } catch (err) { | ||
| if (!disposed) { | ||
| setError(err as Error); | ||
| setSymbology(null); | ||
| } | ||
| } finally { | ||
| if (!disposed) { | ||
| setIsLoading(false); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| // initial load | ||
| fetchSymbology(); | ||
|
|
||
| model.sharedModel.awareness.on('change', () => { | ||
| fetchSymbology(); | ||
| }); | ||
|
|
||
| return () => { | ||
| disposed = true; | ||
| }; | ||
| }, [layerId, model]); | ||
|
|
||
| return { symbology, isLoading, error }; | ||
| }; | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should the dependencies include the whole model, or just the piece of the model we care about listening to? Maybe we're firing this hook too much, or not at all because the reference isn't changing but deeply nested values are changing.
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.
I am now using model awareness to update legends - which is why I need model.