Add Native Leaflet Retina Support for Raster Tiles#2074
Open
acalcutt wants to merge 4 commits intomaptiler:masterfrom
Open
Add Native Leaflet Retina Support for Raster Tiles#2074acalcutt wants to merge 4 commits intomaptiler:masterfrom
acalcutt wants to merge 4 commits intomaptiler:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an opt-in configuration flag to enable high-DPI (“Retina”) raster rendering in the Leaflet-based viewer by translating requests to TileServer-GL’s native @2x tile endpoints, while removing legacy mapbox.js-era retina code from the templates.
Changes:
- Injects Leaflet’s
{r}modifier into rendered raster tile URLs in the raster viewer template whenleafletRetinais enabled. - Removes obsolete
layer.scalePrefixlogic from thevieweranddatatemplates. - Exposes
leafletRetinafrom server options to templates and documents it in configuration docs.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/server.js |
Passes leafletRetina config into Handlebars template data as leaflet_retina. |
public/templates/viewer.tmpl |
Conditionally injects {r} into raster tile URL templates to enable @2x fetching. |
public/templates/data.tmpl |
Removes legacy scalePrefix code from the data viewer template. |
docs/config.rst |
Documents the new leafletRetina configuration option and its default. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add Native Leaflet Retina Support for Raster Tiles
Description
This PR updates the Handlebars templates and server configuration to properly support Retina (High-DPI) displays on the Leaflet-based raster map viewer using TileServer-GL's native
@2xrendering capabilities.Previously, the templates contained obsolete
layer.scalePrefixcode intended for older versions of mapbox.js. Simply enabling Leaflet'sdetectRetina: truecauses Leaflet to attempt fetching four tiles from thez+1zoom level, which can put unnecessary strain on the server, create rendering inconsistencies (smaller labels), and potentially fetch tiles beyond max zoom bounds, breaking the view.Instead, this PR dynamically injects Leaflet's
{r}modifier into theviewer.tmplTileJSON endpoint string, elegantly translating the tile requests directly into TileServer-GL's native high-resolution@2xrendered endpoints (/{z}/{x}/{y}@2x.pnginstead of/{z}/{x}/{y}.png).Changes
public/templates/data.tmpl: Removed obsoletelayer.scalePrefixlogic. Ensured retina is completely disabled here because the raw data endpoint does not generate raster-scaled outputs, avoiding 404s and zooming bugs.public/templates/viewer.tmpl: Removed obsolete mapbox.js code. Dynamically injects the{r}tag into the raster rendering URL so Leaflet properly pulls@2xendpoints instead of shifting zoom levels.src/server.js: Added theleafletRetinaoption, defaulting tofalse(to preserve existing behavior while allowing opt-in testing).docs/config.rst: Documented the newleafletRetinaconfiguration option.Motivation and Context
Native rendering of High DPI output provides significantly better maps on modern devices without requiring the client browser to cobble together mismatched zoom levels.
However, because this natively causes the server to generate larger images (
@2x), it can use extra CPU/Memory resources. To preserve current behavior and ensure stability, this option is disabled by default.To use it, an administrator must dynamically opt-in by setting
"leafletRetina": truewithin theirconfig.jsonoptions.Testing Instructions
leafletRetinaexplicitly set to true. Verify the current behavior works exactly as before.optionsinconfig.json, add"leafletRetina": trueand restart the server.@2xendpoint in the network tab.