Skip to content

Conversation

@harshasiddartha
Copy link

Description

Fixes issue #2325 by restricting zooming and panning in the data inspector to the dataset's extent.

Currently, the inspector shows 0/0/0 (zoom level 0/0/0) which works for global datasets but not for local/smaller datasets. This PR implements zoom and pan restrictions based on TileJSON metadata.

Changes

  • Fetch TileJSON when the inspector dialog opens from the API endpoint /{source_ids}
  • Extract metadata from TileJSON: bounds, minzoom, maxzoom, and center
  • Configure map with:
    • initialViewState using center coordinates if available
    • minZoom and maxZoom restrictions
    • maxBounds to prevent panning outside the dataset extent
    • fitBounds() to automatically fit the map to the dataset bounds when available
  • Handle both raster and vector sources with appropriate configuration
  • Update tests to mock TileJSON fetch calls

Technical Details

The implementation:

  1. Fetches TileJSON asynchronously when the dialog opens
  2. Applies restrictions through both React props (initialViewState, minZoom, maxZoom, maxBounds) and direct map API calls (setMinZoom, setMaxZoom, setMaxBounds, fitBounds)
  3. Handles cases where TileJSON loads after the map has already initialized
  4. Gracefully continues without restrictions if TileJSON fetch fails

Testing

  • Updated existing tests to mock TileJSON fetch
  • Added test to verify TileJSON is fetched when dialog opens
  • All existing tests continue to pass

Screenshots

Before: Inspector showed blank map with no restrictions (0/0/0)
After: Inspector restricts zoom/pan to dataset bounds and fits to extent

Related Issues

Closes #2325

@harshasiddartha harshasiddartha changed the title Fix #2325: Restrict zooming and panning on the data inspector fix: restrict zooming and panning on the data inspector (#2325) Nov 1, 2025
- Fetch TileJSON when inspector dialog opens
- Extract bounds, minzoom, maxzoom, and center from TileJSON
- Configure map with initialViewState and restrictions
- Apply bounds restrictions to prevent panning outside dataset extent
- Set min/max zoom limits based on TileJSON data
- Fit map to bounds when available, otherwise use center
- Update tests to mock TileJSON fetch calls
@harshasiddartha harshasiddartha force-pushed the fix/restrict-zoom-pan-inspector branch from 3881bfa to 45c5c58 Compare November 1, 2025 11:38
Copy link
Member

@CommanderStorm CommanderStorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

I tested the code and the first case (a raster layer) works.
The second case however (a vector map) does not seem to work nicely:

image

You can reproduce this by running:

VITE_MARTIN_BASE=https://nav.tum.de/martin npm run dev

and then visting http://localhost:3001/?inspect=shortbread&tab=tiles

Comment on lines +198 to +203
onLoad={() => {
// Configure bounds for raster sources after map loads
if (tileJSON) {
configureMapBounds();
}
}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You always seem to configure this twice:

  • once in the react component
  • once in the onLoad callback

Could you explain this? 🤔
Seems a bit strange

Comment on lines +99 to +100
fetch(buildMartinUrl(`/${name}`))
.then((response) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this is very react-y.

I think the current recomendation is to use <Suspense + asyncData and just wrap the components where we need the data.

At least this is explained like this here:

https://stackoverflow.com/questions/53332321/react-hook-warnings-for-async-function-in-useeffect-useeffect-function-must-ret

What do you think? 🤔

@CommanderStorm CommanderStorm marked this pull request as draft November 5, 2025 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restrict zooming and panning on the data inspector

2 participants