Skip to content

Work offline: keep an area, and cache what is viewed - #63

Merged
octopranav merged 2 commits into
mainfrom
android-offline-area
Sep 24, 2026
Merged

octopranav merged 2 commits into
mainfrom
android-offline-area

Conversation

@octopranav

@octopranav octopranav commented Sep 23, 2026 •

Copy link
Copy Markdown
Owner

What

The app now works offline in two ways.

An area the reader keeps. "Keep this area offline" in the anchor group fetches the 25 landmark shards around the place and keeps them on the device: 184 kB around downtown Toronto. There, with no connection:

  • the anchor list works
  • reading an anchored line works, when the line gives its region
  • finding a place by name works

Wherever the app has already been used.

  • The map draws from the tiles it has already drawn. The map library's own cache is raised from 50 MB to 200 MB.
  • The landmark shards met while looking around are cached apart from kept areas, in the app's cache and trimmed to 20 MB. They are never counted as kept.

The map is not downloaded

An area's map at full detail is about 17,000 tiles, an estimated 50 to 150 MB from sampling each zoom level. OpenFreeMap's terms, updated 9 September 2026, rule out attempting "to collect data from the service in automated ways without permission". Fetching an area's tiles in the background would be exactly that. So offline the map is whatever the reader has already looked at, and the kept-area note says so.

The kept area is centred on the place

The website keeps the grid cell one level above the shards. It is the same size, but fixed to the grid: downtown Toronto sits in the corner of its cell (43.21 to 45.00 N, 81.60 to 79.21 W), which stops about 15 km east of downtown. The app keeps the five by five block of shards around the place's own shard instead. That reaches 100 km every way: the east of the city (G3T9), Muskoka to the north, Niagara to the south.

Rules

  • Whole or nothing. An area is recorded as kept only once all 25 shards have come back, so it never fails offline where it was promised to work.
  • Kept means asked for. Only what the reader chose to keep is reported as kept. The seen-shard cache is a convenience the system may clear. Forget gives back both, as the website's Forget does.
  • When a kept copy is used. A kept shard is read when it comes from the archive the site is serving, or when there is no connection to ask. Offline, an older landmark is better than none.
  • A name alone is never enough offline. An anchored line resolves offline only when it gives its region, because nothing on the device can show a name is unique.
  • Offline results say where they came from. A name search answered from the device says so, and that a name two places share within one region is not there.
  • A short list says so. At the edge of what is on the device, the anchor list shows what it has and says places are missing.
  • Where the files live. Kept areas are in noBackupFilesDir: out of the device's backup, and out of the cache the system may empty.

Checks

  • 91 core tests pass. New ones cover:
    • the centred area: 25 distinct shards around 1,000 random places, always including every shard the place's box needs; wrapping at the date line; stopping at the pole
    • the area's size by latitude
    • offline name search from device landmarks
    • offline anchored lines needing their region; removing that guard fails the test
  • On the emulator, from a cleared install:
    • With nothing kept, Toronto's map drew offline after a restart, from the map cache, and its 87 landmarks came from the seen cache.
    • Keeping recorded centre G3RJ, 25 shards and 184 kB, including G3T9 (east Toronto) and G3R5 (Muskoka).
    • Offline, nathan found Nathan Phillips Square from the device, with the note, and picking it went there.
    • An anchored line read offline against a kept landmark. A name alone asked for a connection.
    • Back online, Forget removed the kept areas and the seen shards.

The anchor group gains "Keep this area offline": the cell around the place,
200 km north to south, fetched as its 25 shards of the website's landmark
archive and kept on the device, 84 kB around Toronto. There the anchor list
works with no connection, and so does reading an anchored line, against the
kept landmarks when it gives its region. A name on its own is still refused
offline, since nothing on the device can show it is unique.

An area is kept whole or not at all, so it never fails offline where it was
promised not to. Only what the reader asked for is written or counted as
kept; shards fetched while looking around stay in memory. A kept shard is
read when it comes from the archive the site is serving, or when there is no
connection to ask. When part of a point's box cannot be read, at the edge of
a kept area, the list shows what it has and says places are missing. Forget
gives everything back. The folder is kept out of the device's backup and out
of the cache the system may empty.
The map is not downloaded ahead of being looked at: an area at full detail
is about 17,000 tiles, and the tile provider's terms rule out collecting its
data in automated ways without permission. Instead the map library's own
cache grows from 50 MB to 200 MB, so the map draws offline wherever it has
already been looked at, and the landmark shards met while looking around are
cached too, in the app's cache and trimmed to 20 MB, never counted as kept.
Forget empties that cache with the kept areas.

With no connection to the name index, a name is found among the landmarks
on the device, kept or seen, and the list says that is where it came from.

The kept area is now the five by five block of shards around the place's
own rather than the grid cell above it: the same 25 shards, but reaching
100 km every way. Around downtown Toronto the grid cell stopped 15 km east;
the centred block takes in the east of the city and reaches Muskoka.
@octopranav octopranav changed the title Keep an area's landmarks offline in the app Work offline: keep an area, and cache what is viewed Sep 24, 2026
@octopranav
octopranav merged commit 9b10e48 into main Sep 24, 2026
21 checks passed
@octopranav
octopranav deleted the android-offline-area branch September 24, 2026 12:06
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.

1 participant