Add grid overlay feature with configurable cell size and labels#527
Add grid overlay feature with configurable cell size and labels#527PollenGeo wants to merge 13 commits into
Conversation
|
This looks very nice. Thanks for the contribution. It seems to me that 5000 pixels is quite large for the smallest grid. I could imagine that much smaller tiles could be useful, down to maybe 500 or even less? Although it's tricky to allow smaller values without making the slider increment also smaller (and harder to pick a nice round number). Testing with Image 6416 on merge-ci...
As a first time contributor to OME, could I ask you to fill in the Contributor License Agreement at https://ome-contributing.readthedocs.io/en/latest/cla.html. |
| if (this.gridOverlay) { | ||
| if (!this.gridOverlay.isEnabled()) { | ||
| // Show grid with configured cell size | ||
| this.gridOverlay.showGrid(5, this.gridCellSize, this.gridShowLabels); |
There was a problem hiding this comment.
It's not needed to specify 5 here for lineWidth since a default is specified in the gridOverlay itself.
I found it hard to track down where the 5 was coming from when I changed the default to 2 in the gridOverlay (which was ignored!).
I actually prefer a lineWidth of 2. Maybe this could be configurable in the UI. e.g. option of 1, 2, or 5 px?
There was a problem hiding this comment.
Done, removed the hardcoded 5 so the default from GridOverlay is now used. Making lineWidth configurable in the UI is a good idea, should I include it in this PR or open a separate one?
There was a problem hiding this comment.
Include it here would be nice if possible? thanks
| }); | ||
|
|
||
| // Inicializar grid overlay | ||
| setTimeout(() => { |
There was a problem hiding this comment.
I found that sometimes this timeout is not long enough and that this.viewer is still null after 1500 ms, so the gridOverlay is not created.
A better place to initialise the gridOverlay is at the end of the imageDataReady() function above after this.initViewer(); has been called. Right after this:
// mdi needs to switch image config when using controls
this.getContainer().find('.ol-control').on(
'mousedown',
() => this.context.selectConfig(this.image_config.id))
| if (customCellSize) { | ||
| cellSize = customCellSize; // ← USE THE VALUE PROVIDED | ||
| } else { | ||
| // Fallback: auto-calculate only if not provided | ||
| if (Math.max(width, height) > 50000) { | ||
| cellSize = Math.floor(Math.min(width, height) / 6); | ||
| } else if (Math.max(width, height) > 10000) { | ||
| cellSize = Math.floor(Math.min(width, height) / 10); | ||
| } else { | ||
| cellSize = Math.floor(Math.min(width, height) / 12); | ||
| } | ||
| } |
There was a problem hiding this comment.
I don't recommend the use an auto calculated size for reproducibility.
I also haven't seen it in the plugin, so you should remove these conditions
There was a problem hiding this comment.
Done, removed the auto-calculation logic. Now cellSize only uses the custom value provided.
| /** | ||
| * Update grid line width | ||
| * @memberof Ol3Viewer | ||
| */ | ||
| updateGridLineWidth() { | ||
| if (this.gridOverlay && this.gridEnabled) { | ||
| this.gridOverlay.updateLineWidth(parseInt(this.gridLineWidth)); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Update grid cell size | ||
| * @memberof Ol3Viewer | ||
| */ | ||
| updateGridCellSize() { | ||
| if (this.gridOverlay && this.gridEnabled) { | ||
| // Ensure value is within range | ||
| if (this.gridCellSize < 5000) this.gridCellSize = 5000; | ||
| if (this.gridCellSize > 10000) this.gridCellSize = 10000; | ||
|
|
||
| // Update grid with new size | ||
| this.gridOverlay.updateCellSize(parseInt(this.gridCellSize)); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Toggle grid labels | ||
| * @memberof Ol3Viewer | ||
| */ | ||
| toggleGridLabels() { | ||
| if (this.gridOverlay && this.gridEnabled) { | ||
| this.gridOverlay.toggleLabels(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Indentation level is one too much. Fix it please
|
Regarding Tom's comment on the "Grid" button. It would be nicer if you could find or create a grid icon, so that the button can be consistent with the others in the viewer "toolbar"? Minor comment: In the popup panel, I'm not sure you need the "Medium, Large, Very Large" labels? I think the slider is clear enough without them. |
|
Longer-term suggestion: store the grid state (on/off & size) as an annotation that is automatically detected. |
| this.config.labelSize = labelSize; | ||
| this.config.showLabels = showLabels; | ||
|
|
||
| console.log('Cell size:', cellSize, 'px'); |
There was a problem hiding this comment.
This is currently logging Cell size: true px here, and then it hangs below in an infinite loop.
| if (this.gridOverlay) { | ||
| if (!this.gridOverlay.isEnabled()) { | ||
| // Show grid with configured cell size | ||
| this.gridOverlay.showGrid(this.gridCellSize, this.gridShowLabels); |
There was a problem hiding this comment.
First argument for showGrid() should be lineWidth
- Updated the grid control button layout and functionality. - Removed the fixed size presets (Medium, Large, Very Large). - Added a new option to customize the grid line thickness.
Updated grid overlay configuration and functionality for improved performance and usability. Single layer — Two separate VectorLayers (grid + labels) merged into one, using a style function that branches on gridType. No className — Removed custom class names that were creating a separate canvas intercepting pointer events and blocking ROI drawing. insertAt() instead of splice() — Replaced direct array manipulation with the proper Collection API, fixing the broken enable/disable toggle.
Updated grid line width to 2 and modified grid display logic to use the line width parameter.
|
Everything looks good. Try to add your |
|
I opened PollenGeo#1 against this branch which should address most of the outstanding issues. |
This prevents controls buttons overlapping, but is also nicer to have slightly bigger viewers
Grid overlay thanks Will, these are excellent changes, and we will continue to study them and review the recommendations.
|
Now that my changes are merged, it's easier to see the changes and cleanup that I missed. E.g. need to check for unused css classes. I found these don't seem to be used anywhere now and can be removed. Just give it a "final" test and check that everything is working as expected. |






Hi, We welcome your comments and would like to add the following