Java tile library
The Java tile library is a Gradle-based Java 21 system for converting Mapbox Vector Tiles (MVT) to MapLibre Tiles (MLT), reading MLT back into tile data, and processing tile archives. Its core library provides the reusable tile contract. Command-line programs and auxiliary tools apply that contract to files, archives, and generated tile data.
System purpose
The system turns vector tile data into MLT for storage and use by MapLibre tile consumers. It keeps a Java tile model at the API boundary so callers work with tile content rather than encoded byte streams. The main path is:
flowchart LR
A[MVT tile or tile archive] --> B[Java tile model]
B --> C[Metadata and conversion choices]
C --> D[MLT tile encoding]
D --> E[MLT tile or MLT archive]
E --> F[Java tile model]
The same system also prepares polygon geometry, applies optional compression, updates archive metadata, and checks that decoded output matches the source.
References: java/README.MD• L5-15 java/…/MltConverter.java• L518-553 java/…/MltDecoder.java• L42-63
Gradle modules
The Java area is one Gradle build with three focused modules. The core library is the reusable center. The command-line and tool modules depend on it to run tile conversion and create supporting data.
| Module | System role | Main result |
|---|---|---|
mlt-core | Provides the tile model, MLT conversion, decoding, metadata, geometry handling, and compression choices. | Published org.maplibre:mlt library |
mlt-cli | Applies the core conversion to files and tile archives through encode and decode programs. | Local runnable JARs |
mlt-tools | Creates synthetic MLT data for shared checks and development work. | Generated tile fixtures |
The build uses Java 21 across the modules. The version catalog in java/…/libs.versions.toml keeps shared dependency and plugin versions aligned. The Gradle wrapper uses Gradle 9.9.1, so the wrapper and catalog define the build version contract for contributors and automated builds.
References: java/settings.gradle• L5-9 java/…/libs.versions.toml• L1-48 java/…/gradle-wrapper.properties• L1-9 java/…/build.gradle• L1-7 java/…/build.gradle• L81-83 java/…/build.gradle• L139-150 java/…/build.gradle• L134-178 java/…/build.gradle• L54-58
Tile conversion flow
The conversion flow learns or receives layer metadata before it writes the tile. It stores the geometry and property layout with the encoded tile so the decoder can rebuild the tile without a separate schema request.
When the CLI processes a tile, it follows this sequence:
- Read and decompress the source when needed.
- Decode the MVT into the shared Java tile model.
- Build layer metadata and apply the selected conversion choices.
- Encode the layers as MLT.
- Optionally compress the MLT result for archive storage.
- Optionally decode the result and compare it with the source.
The path is shared by standalone tiles and archive entries. Archive adapters handle storage and tile metadata without changing the tile conversion contract.
References: java/…/Conversion.kt• L153-218 java/…/Encode.kt• L237-328 java/…/MltConverter.java• L625-744
Archive workflows
The CLI supports single-tile work and bulk conversion. Bulk conversion reads source archive metadata, sends each tile through the shared conversion flow, and writes an archive whose tile format and metadata identify MLT output.
| Source | Workflow aim | Destination |
|---|---|---|
| Standalone MVT file | Convert one tile for inspection or storage. | .mlt tile file |
| MBTiles | Convert a SQLite tile set while retaining useful tileset metadata. | MLT MBTiles file |
| Offline database | Update tile records in a copy of the source database and update source metadata when possible. | MLT offline database |
| PMTiles | Read local or remote byte ranges and write an MLT PMTiles archive. | MLT PMTiles file |
PMTiles processing can limit the zoom range and use parallel work. Range reads and a bounded cache support large or remote archives without loading the full source at once.
References: java/README-Encode.md• L3-17 java/…/MBTiles.kt• L24-77 java/…/OfflineDB.kt• L23-61 java/…/PMTiles.kt• L42-69 java/…/PMTiles.kt• L179-275
Geometry tessellation
Tessellation changes polygon geometry into triangle indexes for consumers that need triangles instead of polygon rings. The encoder can perform this work locally or use a configured remote tessellation service.
The local path handles polygons and multipolygons and preserves hole boundaries. The remote path uses the same tile-level role and returns triangle indexes. The choice changes where the work runs, not the meaning of the encoded geometry.
References: java/…/TessellationUtils.java• L21-50 java/…/TessellationUtils.java• L53-110 java/…/MltConverter.java• L815-828
Native resources
The library provides Java string compression and an optional native FSST path. FSST is a string compression choice used by the core encoder when enabled in the conversion settings.
The native path is not required for normal Java operation. The CLI enables it only when the shared library loads successfully. Its build uses CMake, JNI, and an external FSST library. The Java loader and native build must agree on the wrapper location and name.
References: java/…/FsstEncoder.java• L3-35 java/…/FsstJni.java• L5-40 java/…/compile• L1-14 java/…/CMakeLists.txt• L35-73 java/…/Encode.kt• L92-103
Related pages
The Java core codec page explains the reusable encoding and decoding contract in more detail. The Java CLI and tools page explains command-line workflows, archive handling, and auxiliary tile-generation tools.
References: java/README.MD• L7-15 java/README.MD• L222-250
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to the core tile model or embedded metadata must remain compatible with both encoding and decoding, plus the CLI comparison path.
- Changes to archive output must keep the archive tile format, compression flag, MIME metadata, and tileset metadata aligned.
- Changes to the tessellation request or response shape must update both local callers and the remote service contract.
- Changes to native FSST output names or locations must stay aligned across the CMake target, Java loader, and CLI capability check.
- Changes to the Gradle module list or publication settings must preserve the core library as the reusable published artifact and the CLI as a runnable package.
- Changes to the version catalog or Gradle wrapper must remain compatible with the dependency aliases and build plugins used by all three modules.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A layer has no matching metadata or has incompatible property types under the fail policy. | Tile conversion stops instead of producing an unclear schema. | Build metadata from the source tile or select an explicit mismatch policy. |
| A configured remote tessellation service cannot return valid indexes. | Polygon conversion fails for the affected tile. | Use local tessellation when suitable and treat the service as part of the conversion dependency. |
| A PMTiles input is not an MVT archive. | Archive conversion is rejected before tile work starts. | Check the source tile type before conversion. |
| The native FSST wrapper is absent or cannot load. | Native FSST is not enabled. | Use Java FSST or build the wrapper in the location expected by the loader. |
| The Gradle wrapper or version catalog is not compatible with the module build files. | The build cannot resolve its toolchain, plugins, or dependencies. | Keep wrapper, plugin aliases, and module build requirements aligned. |
Key files
| File | Why to read it |
|---|---|
| java/settings.gradle | Defines the Gradle modules and their dependency shape. |
| java/…/libs.versions.toml | Defines shared dependency and plugin versions for the Gradle modules. |
java/gradle/wrapper/gradle-wrapper.properties | Defines the Gradle distribution used by the build wrapper. |
| java/…/MltConverter.java | Shows the system boundary for metadata creation and MLT encoding. |
| java/…/MltDecoder.java | Shows how an MLT tile becomes the shared Java tile model. |
| java/…/Encode.kt | Shows how CLI options become one conversion configuration. |
| java/…/Conversion.kt | Shows the shared per-tile conversion and optional compression or comparison steps. |
| java/…/MBTiles.kt | Shows the archive metadata and database workflow for MBTiles. |
| java/…/PMTiles.kt | Shows range reads, cache use, parallel archive conversion, and repeated-tile handling. |
| java/…/TessellationUtils.java | Shows the local and remote polygon tessellation boundary. |
| java/…/SyntheticMltGenerator.java | Shows the role of auxiliary tools in producing geometry, ID, property, and compression fixtures. |
| java/…/CMakeLists.txt | Shows the native FSST resource boundary and platform build target. |