diff --git a/.changeset/default-coordinate-system-selection.md b/.changeset/default-coordinate-system-selection.md new file mode 100644 index 00000000..682f8cef --- /dev/null +++ b/.changeset/default-coordinate-system-selection.md @@ -0,0 +1,5 @@ +--- +"@spatialdata/vis": patch +--- + +Auto-select the coordinate system when a SpatialData object has exactly one. Previously the picker started unselected (showing "Select a coordinate system") even when there was only one choice, and a separate effect would eagerly pick the first of several. Now selection defaults only in the unambiguous single-coordinate-system case; multi-system datasets still require an explicit choice. diff --git a/packages/vis/src/SpatialCanvas/index.tsx b/packages/vis/src/SpatialCanvas/index.tsx index 3329fb74..c2545b8e 100644 --- a/packages/vis/src/SpatialCanvas/index.tsx +++ b/packages/vis/src/SpatialCanvas/index.tsx @@ -457,16 +457,16 @@ function SpatialCanvasInner({ vw, ]); - useEffect(() => { - if (coordinateSystems.length > 0 && !coordinateSystem) { - actions.setCoordinateSystem(coordinateSystems[0]); - } - }, [coordinateSystems, coordinateSystem, actions]); - useEffect(() => { actions.reset(); - if (coordinateSystem && coordinateSystems.includes(coordinateSystem)) { - actions.setCoordinateSystem(coordinateSystem); + const nextCoordinateSystem = + coordinateSystem && coordinateSystems.includes(coordinateSystem) + ? coordinateSystem + : coordinateSystems.length === 1 + ? coordinateSystems[0] + : null; + if (nextCoordinateSystem) { + actions.setCoordinateSystem(nextCoordinateSystem); } }, [coordinateSystem, coordinateSystems, actions]);