-
Notifications
You must be signed in to change notification settings - Fork 69
Add Heatmap layer #384
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
Add Heatmap layer #384
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
753a0dc
Start adding heatmap layer
gjmooney 16487f8
Add heatmap to layer context menu
gjmooney 41d71e4
Get features into dropdown on form
gjmooney b29448e
Clean up
gjmooney 1a3ac03
Add color to schema
gjmooney b7d5b5a
Add heatmap symbology panel
gjmooney 0c78689
Layer form something
gjmooney 271af61
Add symbology state
gjmooney fac4db9
Iterate
gjmooney 74648ca
Clean up
gjmooney aad232f
Refactor _onLayersChanged
gjmooney 5e6026b
Implement layer type changing
gjmooney e15f823
Set type in symbology
gjmooney 44ee711
IDK what rjsf wants anymore
gjmooney 559f234
Recreate layer when changing feature
gjmooney 3cd6c97
Add blur and radius to symbology
gjmooney 602956e
Update color ramp css
gjmooney 6763111
Remove blur and radius from form
gjmooney 75c85a4
Capitalize form labels
gjmooney 503271a
Remove icon and fix label
gjmooney 06cca6e
Clean up
gjmooney 0949824
Choose defaults betters
gjmooney 3e3c87f
Add notebook api for heatmap
gjmooney 9290eac
Add heatmaps to Notebook test
gjmooney 29d3ecf
Update Playwright Snapshots
github-actions[bot] 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
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
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
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
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
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
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
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
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
128 changes: 128 additions & 0 deletions
128
packages/base/src/dialogs/symbology/vector_layer/types/Heatmap.tsx
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,128 @@ | ||
| import colormap from 'colormap'; | ||
| import React, { useEffect, useRef, useState } from 'react'; | ||
| import CanvasSelectComponent from '../../components/color_ramp/CanvasSelectComponent'; | ||
| import { ISymbologyDialogProps } from '../../symbologyDialog'; | ||
|
|
||
| const Heatmap = ({ | ||
| context, | ||
| state, | ||
| okSignalPromise, | ||
| cancel, | ||
| layerId | ||
| }: ISymbologyDialogProps) => { | ||
| if (!layerId) { | ||
| return; | ||
| } | ||
| const layer = context.model.getLayer(layerId); | ||
| if (!layer?.parameters) { | ||
| return; | ||
| } | ||
| const [selectedRamp, setSelectedRamp] = useState(''); | ||
| const [heatmapOptions, setHetamapOptions] = useState({ | ||
| radius: 8, | ||
| blur: 15 | ||
| }); | ||
| const selectedRampRef = useRef('cool'); | ||
| const heatmapOptionsRef = useRef({ | ||
| radius: 8, | ||
| blur: 15 | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| populateOptions(); | ||
|
|
||
| okSignalPromise.promise.then(okSignal => { | ||
| okSignal.connect(handleOk, this); | ||
| }); | ||
|
|
||
| return () => { | ||
| okSignalPromise.promise.then(okSignal => { | ||
| okSignal.disconnect(handleOk, this); | ||
| }); | ||
| }; | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| selectedRampRef.current = selectedRamp; | ||
| heatmapOptionsRef.current = heatmapOptions; | ||
| }, [selectedRamp, heatmapOptions]); | ||
|
|
||
| const populateOptions = async () => { | ||
| let colorRamp; | ||
|
|
||
| if (layer.parameters?.symbologyState) { | ||
| colorRamp = layer.parameters.symbologyState.colorRamp; | ||
| } | ||
|
|
||
| setSelectedRamp(colorRamp ? colorRamp : 'cool'); | ||
| }; | ||
|
|
||
| const handleOk = () => { | ||
| if (!layer.parameters) { | ||
| return; | ||
| } | ||
|
|
||
| const colorMap = colormap({ | ||
| colormap: selectedRampRef.current, | ||
| nshades: 9, | ||
| format: 'hex' | ||
| }); | ||
|
|
||
| const symbologyState = { | ||
| renderType: 'Heatmap', | ||
| colorRamp: selectedRampRef.current | ||
| }; | ||
|
|
||
| layer.parameters.symbologyState = symbologyState; | ||
| layer.parameters.color = colorMap; | ||
| layer.parameters.blur = heatmapOptionsRef.current.blur; | ||
| layer.parameters.radius = heatmapOptionsRef.current.radius; | ||
| layer.type = 'HeatmapLayer'; | ||
|
|
||
| context.model.sharedModel.updateLayer(layerId, layer); | ||
|
|
||
| cancel(); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="jp-gis-layer-symbology-container"> | ||
| <div className="jp-gis-symbology-row"> | ||
| <label htmlFor="color-ramp-select">Color Ramp:</label> | ||
| <CanvasSelectComponent | ||
| selectedRamp={selectedRamp} | ||
| setSelected={setSelectedRamp} | ||
| /> | ||
| </div> | ||
| <div className="jp-gis-symbology-row"> | ||
| <label htmlFor={'vector-value-select'}>Radius:</label> | ||
| <input | ||
| type="number" | ||
| value={heatmapOptions.radius} | ||
| className="jp-mod-styled" | ||
| onChange={event => | ||
| setHetamapOptions(prevState => ({ | ||
| ...prevState, | ||
| radius: +event.target.value | ||
| })) | ||
| } | ||
| /> | ||
| </div> | ||
| <div className="jp-gis-symbology-row"> | ||
| <label htmlFor={'vector-value-select'}>Blur:</label> | ||
| <input | ||
| type="number" | ||
| value={heatmapOptions.blur} | ||
| className="jp-mod-styled" | ||
| onChange={event => | ||
| setHetamapOptions(prevState => ({ | ||
| ...prevState, | ||
| blur: +event.target.value | ||
| })) | ||
| } | ||
| /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default Heatmap; |
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
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.
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.
Is it the only possible source type?
I'm only asking because I'm curious, allowing the form to create multiple source types is another task on itself (also not sure we want to allow it)
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 think it should work with any vector source that uses points.