Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ bool fetchMap(LGFX_Sprite &map, double longitude, double latitude, uint8_t zoom,
```

- Overflowing `longitude` are wrapped and normalized to +-180°.
- Overflowing `latitude` are clamped to +-90°.
- Overflowing `latitude` are clamped to +-85°.
- Valid range for the `zoom` level is from `getMinZoom()` to `getMaxZoom()`.
- `timeoutMS` can be used to throttle the amount of downloaded tiles per call.
Setting it to anything other than `0` sets a timeout. Sane values start around ~100ms.
**Note:** No more tiles will be downloaded after the timeout expires, but tiles that are downloading will be finished.
**Note:** No more tile downloads will be started after the timeout expires, but tiles that are downloading will be finished.
**Note:** You might end up with missing map tiles. Or no map at all if you set the timeout too short.

### Free the psram memory used by the tile cache
Expand Down
7 changes: 6 additions & 1 deletion src/OpenStreetMap-esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,13 @@ bool OpenStreetMap::fetchMap(LGFX_Sprite &mapSprite, double longitude, double la
return false;
}

// Web Mercator projection only supports latitudes up to ~85.0511°.
// See https://en.wikipedia.org/wiki/Web_Mercator_projection#Formulas
// We use 85.0° as a safe and simple boundary.
constexpr double MAX_MERCATOR_LAT = 85.0;

longitude = fmod(longitude + 180.0, 360.0) - 180.0;
latitude = std::clamp(latitude, -90.0, 90.0);
latitude = std::clamp(latitude, -MAX_MERCATOR_LAT, MAX_MERCATOR_LAT);

tileList requiredTiles;
computeRequiredTiles(longitude, latitude, zoom, requiredTiles);
Expand Down