Skip to content

Add setOnMapLoadedCallback like in GoogleMap - #60

Merged
afarber merged 1 commit into
mainfrom
map-loaded-callback
Oct 14, 2026
Merged

afarber merged 1 commit into
mainfrom
map-loaded-callback

Conversation

@afarber

@afarber afarber commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Fixes #59

Adds OpenMapView.setOnMapLoadedCallback(OnMapLoadedCallback?), matching Google's GoogleMap.setOnMapLoadedCallback.

  • At the end of MapController.draw() the callback is called once if every visible base tile was drawn from memory and the camera isn't moving. An expired tile shown as offline fallback counts as drawn, and with MapType.NONE there is nothing to wait for
  • It runs on the main thread after the draw pass, so it can safely call snapshot() or change the map
  • Setting it on a map that is already loaded requests a redraw, which then reports it
  • Tile overlays are not waited for, because sparse overlays (e.g. OpenSeaMap) have no tiles for many areas and the callback would never fire
  • Like Google's, it doesn't fire while tiles can't be loaded or while the camera keeps moving
  • null removes a pending callback

Example:

mapView.setOnMapLoadedCallback {
    mapView.snapshot { bitmap -> bitmap?.let { saveToFile(it) } }
}

Tests: new MapLoadedCallbackTest (7 tests). 489 tests pass, coverage 83%. PUBLIC_API.md marks it as implemented.

- Called once after a draw where all visible base tiles were shown
  and the camera was not moving, on the main thread outside the draw
- Setting it on a loaded map triggers a redraw that reports it
- Tile overlays are not waited for, sparse overlays have gaps

Fixes #59
@afarber
afarber merged commit dbf37a2 into main Oct 14, 2026
14 checks passed
@afarber
afarber deleted the map-loaded-callback branch October 14, 2026 13:59
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.

Add setOnMapLoadedCallback

1 participant