WMTS constructor throws when given bounding rectangle outside of tiling scheme
- Dominant language
- JavaScript
- Stars
- 15.8k
- Forks
- 3.9k
- Avg merge
- 4d 6h
- Merged PRs (30d)
- 34
Description
I'm parsing a WMTS Capabilities document to automatically create WMTS Imagery Providers. This generally works pretty well but I ran into a problem with [this one](https://basemap.nationalmap.gov/arcgis/rest/services/USGSHydroCached/MapServer/WMTS/1.0.0/WMTSCapabilities.xml). They specify a bounding box that I'm converting to a Rectangle for the constructor's `rectangle` parameter.
````
-179.99999463556182 -88.99999992161116
179.99999550841463 88.99999992161116
````
When you pass that value (via `Rectangle.fromDegrees`) you wind up with a bounding rectangle such that the call to `TilingScheme.positionToTileXY` [here in the WMTS provder constructor](https://github.com/AnalyticalGraphicsInc/cesium/blob/1.52/Source/Scene/WebMapTileServiceImageryProvider.js#L211) returns undefined -- the corners of the bounding rectangle are determined to fall outside of the tiling scheme's rectangle. This means that 2 lines later the references to the x and y coordinates of those tiles will throw, all the way out of the constructor.
I traced this through the [WebMercatorTilingScheme constructor](https://github.com/AnalyticalGraphicsInc/cesium/blob/1.52/Source/Core/WebMercatorTilingScheme.js#L42) and it looks like the bounding rectangle for the default version of that (no arguments) winds up being between about 85 degrees N/S. So, it looks like in the interim, I can either clamp my Rectangle construction to avoid passing bounds outside of 85 degrees (probably fine for my use case), or I can construct my own replacement tiling scheme (which I haven't done before and probably don't need to invest time in learning).
What's the long term fix for this? Maybe it's using the intersection of the tiling scheme rectangle with the `rectangle` argument as the actual bounds -- that's probably the approach I'll use. But it definitely shouldn't just throw due to an unchecked null-pointer error, at least.
Contributor guide
Research direction
Start in Source/Scene/WebMapTileServiceImageryProvider.js around the constructor call to TilingScheme.positionToTileXY, then read WebMercatorTilingScheme.js and Rectangle.fromDegrees. Reproduce the failure with the WMTS capabilities bounding box and determine the expected handling when bounds exceed the tiling scheme. Done means the constructor no longer throws for this input and the behavior is covered by an appropriate test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100