Skip to content

fix: georeferenced mercator tiles with correct alignment and overlap handling#131

Merged
fank merged 3 commits into
mainfrom
fix/maptool-georeferenced-tiles
Feb 5, 2026
Merged

fix: georeferenced mercator tiles with correct alignment and overlap handling#131
fank merged 3 commits into
mainfrom
fix/maptool-georeferenced-tiles

Conversation

@fank
Copy link
Copy Markdown
Member

@fank fank commented Feb 5, 2026

Summary

Cherry-picked fixes from feat/maplibre-pmtiles for the internal/maptool tile generation pipeline:

  • Georeferenced mercator tiles: Switch from --profile=raster to --profile=mercator in gdal2tiles so tiles are proper Web Mercator tiles. Add EPSG:4326 georeferencing to VRT matching the armaToLatLng coordinate conversion. Calculate zoom levels dynamically via MercatorZoomForWorld() instead of hardcoded maxZoom=6.
  • Remove 32px tile overlap: Arma satellite tiles have 32px overlap on all edges for in-engine texture blending. Crop to 480px effective size in VRT SrcRect/DstRect to eliminate visible seam duplication. Also upscale undersized 4×4 ocean placeholder tiles to 512×512 via nearest-neighbor.
  • VRT canvas alignment: Use worldSize×worldSize (1 pixel = 1 meter) for the VRT canvas so tiles are placed at correct pixel positions, fixing marker misalignment caused by sparse tile grids stretching the image.

Test plan

  • Run go test ./internal/maptool/... to verify all tests pass
  • Generate PMTiles for a map with sparse satellite tiles (e.g., Altis) and verify markers align with imagery
  • Verify no visible seam duplication at tile boundaries

fank added 3 commits February 5, 2026 17:38
…entation

- Change --profile=raster to --profile=mercator in gdal2tiles so tiles
  are proper Web Mercator tiles that MapLibre can render at correct scale
- Add EPSG:4326 georeferencing to VRT (places image at equator matching
  armaToLatLng coordinate conversion)
- Remove DstYOff flip — satellite tile Y maps directly to image row,
  GeoTransform handles orientation (south-up raster, GDAL reprojects)
- Remove MBTiles y-flip — mercator profile outputs TMS convention,
  same as MBTiles (no conversion needed)
- Calculate zoom levels dynamically via MercatorZoomForWorld instead of
  hardcoded maxZoom=6 (Altis: z10-17, Stratis: z12-16)
- Use math.Round instead of math.Ceil for maxZoom to avoid oversampling
  (Altis: ~14K tiles/~350MB vs ~54K tiles/~1.3GB)
- Add -r average resampling to reduce edge artifacts
- Add minzoom/maxzoom to style.json source metadata
Arma satellite tiles have 32px overlap on all edges for in-engine texture
blending. Crop to 480px effective size in the VRT SrcRect/DstRect to
eliminate visible seam duplication in PMTiles output.

Also upscale undersized 4×4 ocean placeholder tiles to 512×512 via
nearest-neighbor before PNG encoding, so all tiles match the VRT layout.

Other fixes:
- Remove TMS Y-flip in MBTiles (gdal2tiles mercator already uses TMS)
- Add georeferenced EPSG:4326 GeoTransform to VRT (north-up, equator)
- Compute min/max zoom from world size via MercatorZoomForWorld()
- Pass MinZoom/MaxZoom through Job and into map.json/style.json
…gery

The satellite tile grid is sparse — Altis has 1863 tiles spanning X=2-60,
Y=8-55, not the full 64×64 grid. Using (maxTile+1)*tileEffective as VRT
dimensions stretched the image to fill worldSize, causing markers to
misalign: 3× vertical error, 1× horizontal (14.3% vs 4.9% stretch).

Fix: set VRT canvas to worldSize×worldSize (1 pixel = 1 meter). Tiles are
placed at their correct pixel positions; missing ocean tiles are transparent.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 5, 2026

Merging this branch will decrease overall coverage

Impacted Packages Coverage Δ 🤖
github.com/OCAP2/web/internal/maptool 12.66% (-0.14%) 👎

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/OCAP2/web/internal/maptool/mbtiles.go 0.00% (ø) 286 (-7) 0 286 (-7)
github.com/OCAP2/web/internal/maptool/metadata.go 20.12% (+2.01%) 164 (+26) 33 (+8) 131 (+18) 👍
github.com/OCAP2/web/internal/maptool/pipeline.go 31.38% (ø) 188 59 129
github.com/OCAP2/web/internal/maptool/satellite.go 7.37% (-0.79%) 1045 (+77) 77 (-2) 968 (+79) 👎
github.com/OCAP2/web/internal/maptool/tiles.go 2.07% (+1.35%) 290 (+13) 6 (+4) 284 (+9) 👍

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/OCAP2/web/internal/maptool/metadata_test.go
  • github.com/OCAP2/web/internal/maptool/satellite_test.go
  • github.com/OCAP2/web/internal/maptool/tiles_test.go

@fank fank merged commit 2585f06 into main Feb 5, 2026
2 checks passed
@fank fank deleted the fix/maptool-georeferenced-tiles branch February 5, 2026 16:40
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