Class PMTileGrid

java.lang.Object
org.jorigin.geotools.map.PMTileGrid

public final class PMTileGrid extends Object
Helper for the Pseudo-Mercator ("PM") quadtree tile grid in EPSG:3857 — the de-facto standard for web tile services (OSM, Google, IGN Geoplateforme WMTS "PM" / WMS-R).

Used by CachedRendererJFX to split WMS-R GetMap requests into 256×256 grid-aligned tiles, so the server's tile cache is hit reliably and the identical URLs can be shared across pan/zoom operations (URL-keyed client cache).

Grid parameters

  • Origin (top-left): (-20037508.3427892, +20037508.3427892)
  • Tile size: 256 px
  • Zoom 0 resolution: 156543.0339280410 m/px
  • Each zoom level halves the resolution (doubles the tile count per axis)
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
    A grid-aligned PM tile descriptor.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final double
    Pixel resolution at zoom level 0 (meters/pixel).
    static final int
    Clamp for the selected zoom level (most servers support up to ~22).
    static final int
    Safety cap on the number of tiles returned per request.
    static final double
    Origin X (minimum easting) of the PM grid, in EPSG:3857.
    static final double
    Origin Y (maximum northing) of the PM grid, in EPSG:3857.
    static final int
    Tile size in pixels.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    levelFor(double worldPerPixel)
    Picks the PM zoom level whose pixel resolution is closest to the view's pixel-to-world ratio, so tiles are fetched at the right detail level without over- or under-sampling.
    static double
    resolutionAt(int level)
    get the pixel resolution (m/px) at the given zoom level.
    tilesForBbox(org.geotools.geometry.jts.ReferencedEnvelope bbox, int level)
    Enumerates all PM tiles at level that overlap bbox.
    static double
    tileSpanAt(int level)
    Get the world-unit span covered by a single tile at the given zoom level.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ORIGIN_X

      public static final double ORIGIN_X
      Origin X (minimum easting) of the PM grid, in EPSG:3857.
      See Also:
    • ORIGIN_Y

      public static final double ORIGIN_Y
      Origin Y (maximum northing) of the PM grid, in EPSG:3857.
      See Also:
    • BASE_RES_MPP

      public static final double BASE_RES_MPP
      Pixel resolution at zoom level 0 (meters/pixel).
      See Also:
    • TILE_SIZE_PX

      public static final int TILE_SIZE_PX
      Tile size in pixels.
      See Also:
    • MAX_LEVEL

      public static final int MAX_LEVEL
      Clamp for the selected zoom level (most servers support up to ~22).
      See Also:
    • MAX_TILES_PER_REQUEST

      public static final int MAX_TILES_PER_REQUEST
      Safety cap on the number of tiles returned per request.
      See Also:
  • Method Details

    • levelFor

      public static int levelFor(double worldPerPixel)
      Picks the PM zoom level whose pixel resolution is closest to the view's pixel-to-world ratio, so tiles are fetched at the right detail level without over- or under-sampling.
      Parameters:
      worldPerPixel - the view's resolution in world-units/pixel (typically envelope.getWidth() / viewWidth)
      Returns:
      zoom level clamped to [0, MAX_LEVEL]
    • resolutionAt

      public static double resolutionAt(int level)
      get the pixel resolution (m/px) at the given zoom level.
      Parameters:
      level - the zoom level
      Returns:
      the pixel resolution (m/px) at the given zoom level
    • tileSpanAt

      public static double tileSpanAt(int level)
      Get the world-unit span covered by a single tile at the given zoom level.
      Parameters:
      level - the zoom level
      Returns:
      the world-unit span covered by a single tile at the given zoom level
    • tilesForBbox

      public static List<PMTileGrid.PMTile> tilesForBbox(org.geotools.geometry.jts.ReferencedEnvelope bbox, int level)
      Enumerates all PM tiles at level that overlap bbox. The returned tiles are grid-aligned (their extents are snapped to the PM grid, independent of the exact query bbox), which is what makes their URLs stable across pan/zoom and hittable in the WMS-R tile cache.

      Stops early if the request would produce more than MAX_TILES_PER_REQUEST tiles (defensive cap against wrong zoom levels or absurdly large bounding boxes) and returns an empty list.

      Parameters:
      bbox - the query envelope; must carry an EPSG:3857 CRS (caller's responsibility to check)
      level - the zoom level (see levelFor(double))
      Returns:
      the overlapping tiles, empty if none or if capped out