Files
quartier/xl/style.ts
Jules NényandClaude Opus 5.5 0f3305c722 Prototype XL : étiquettes des communes allégées (min_zoom de la tuile), villes en encre
Mesures du lot faites sur ce style : premier affichage 390 x 844, 15 requêtes, 1 616 574 octets
transférés, un seul hôte, plage d'octets 206.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWGVn3MeAPFsoCSyLs2zZW
2026-11-06 15:39:33 +01:00

141 lines
5.8 KiB
TypeScript

// Le style « papier et trait » de la carte XL (brief P3). Tout vient de la palette de la démo
// (maquette/style.css) ; aucune adresse d'un autre hôte : les glyphes et les tuiles sont résolus
// depuis l'adresse de la page, au moment de construire le style.
import type { StyleSpecification, LayerSpecification } from 'maplibre-gl';
// --- Constantes qui renversent les décisions (RECAP §2) ---------------------------------------
/** Zoom maximal des tuiles extraites (D2 : plus grand zoom dont le fichier reste sous 60 Mo). */
export const ZOOM_MAX = 14;
/** Zoom minimal de la vue (P4). */
export const ZOOM_MIN = 8;
/** Vue de départ (P4) : Tarbes, inclinaison 45°, cap nord. `zoom` est le réglage qui pèse le plus sur le premier affichage. */
export const VUE_DEPART = { centre: [0.0653, 43.2387] as [number, number], zoom: 10, pitch: 45, bearing: 0 };
/** Bornes de la vue (P4) : le rectangle de D1. */
export const BORNES: [[number, number], [number, number]] = [[-0.4, 42.65], [0.55, 43.55]];
/** Fichier de tuiles, relatif à la page (D4). */
export const TUILES = 'tuiles/bigorre.pmtiles';
/** Police des étiquettes : un seul jeu de glyphes servi par le build (P1). */
export const POLICE = 'NotoSansRegular';
/** Routes visibles avant le zoom 11 : départementales et au-dessus (P3). */
export const ROUTES_TOT = ['highway', 'major_road'];
/** Zoom d'apparition du bâti (P3). */
export const ZOOM_BATI = 13;
// Palette : recopiée de maquette/style.css (:root). Aucun hex nouveau.
export const PAL = {
papier: '#efeee2', // --papier
papier2: '#fffdf6', // --papier-2
encre: '#102a3a', // --encre
encre2: '#3f5563', // --encre-2
trait: '#ddd8c4', // --trait
eau: '#3a74a8', // --eau
eauFond: '#e1ebf5', // --eau-fond
vivant: '#8f7b22', // --vivant
auj: '#6b6458', // --auj
} as const;
export const ATTRIBUTION =
'<a href="https://protomaps.com" target="_blank" rel="noopener">Protomaps</a> · <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener">© OpenStreetMap</a>';
// -------------------------------------------------------------------------------------------------
const nom: any = ['coalesce', ['get', 'name:fr'], ['get', 'name']];
function couches(): LayerSpecification[] {
return [
{ id: 'fond', type: 'background', paint: { 'background-color': PAL.papier } },
{
id: 'forets',
type: 'fill',
source: 'bigorre',
'source-layer': 'landuse',
filter: ['in', ['get', 'kind'], ['literal', ['forest', 'wood']]],
paint: { 'fill-color': PAL.vivant, 'fill-opacity': 0.2, 'fill-antialias': false },
},
{
id: 'eau-surfaces',
type: 'fill',
source: 'bigorre',
'source-layer': 'water',
filter: ['==', ['geometry-type'], 'Polygon'],
paint: { 'fill-color': PAL.eau, 'fill-opacity': 0.42 },
},
{
id: 'eau-cours',
type: 'line',
source: 'bigorre',
'source-layer': 'water',
filter: ['all', ['==', ['geometry-type'], 'LineString'], ['any', ['in', ['get', 'kind'], ['literal', ['river', 'canal']]], ['>=', ['zoom'], 11]]],
paint: { 'line-color': PAL.eau, 'line-opacity': 0.75, 'line-width': ['interpolate', ['linear'], ['zoom'], 8, 0.5, 12, 1.2, 14, 2] },
},
{
id: 'bati',
type: 'fill',
source: 'bigorre',
'source-layer': 'buildings',
minzoom: ZOOM_BATI,
paint: { 'fill-color': PAL.auj, 'fill-opacity': 0.28 },
},
{
id: 'limites-communes',
type: 'line',
source: 'bigorre',
'source-layer': 'boundaries',
filter: ['all', ['==', ['get', 'kind'], 'locality'], ['==', ['to-string', ['get', 'kind_detail']], '8']],
paint: { 'line-color': PAL.encre2, 'line-opacity': 0.32, 'line-width': 0.7, 'line-dasharray': [2, 3] },
},
{
id: 'routes',
type: 'line',
source: 'bigorre',
'source-layer': 'roads',
filter: [
'any',
['in', ['get', 'kind'], ['literal', ROUTES_TOT]],
['all', ['>=', ['zoom'], 11], ['==', ['get', 'kind'], 'minor_road']],
],
layout: { 'line-cap': 'round', 'line-join': 'round' },
paint: {
'line-color': PAL.auj,
'line-opacity': ['match', ['get', 'kind'], 'minor_road', 0.4, 0.7],
'line-width': ['interpolate', ['linear'], ['zoom'], 8, ['match', ['get', 'kind'], 'highway', 0.9, 0.5], 12, ['match', ['get', 'kind'], 'highway', 1.6, 'minor_road', 0.5, 1], 14, ['match', ['get', 'kind'], 'highway', 2.4, 'minor_road', 1, 1.6]],
},
},
{
id: 'communes',
type: 'symbol',
source: 'bigorre',
'source-layer': 'places',
filter: ['all', ['==', ['get', 'kind'], 'locality'], ['in', ['get', 'kind_detail'], ['literal', ['city', 'town', 'village']]], ['<=', ['coalesce', ['get', 'min_zoom'], 0], ['zoom']]],
layout: {
'text-field': nom,
'text-font': [POLICE],
'text-size': ['interpolate', ['linear'], ['zoom'], 8, ['match', ['get', 'kind_detail'], 'city', 16, 'town', 14, 11], 13, ['match', ['get', 'kind_detail'], 'city', 20, 'town', 17, 14]],
'symbol-sort-key': ['-', 0, ['coalesce', ['get', 'population_rank'], 0]],
'text-padding': 4,
'text-max-width': 8,
},
paint: { 'text-color': ['match', ['get', 'kind_detail'], 'village', PAL.encre2, PAL.encre], 'text-halo-color': PAL.papier2, 'text-halo-width': 1.4 },
},
];
}
/** Le style complet. `page` est l'adresse de la page (location.href) : tout se résout depuis elle. */
export function construireStyle(page: string): StyleSpecification {
const base = new URL('./', page).href;
return {
version: 8,
name: 'Bigorre, papier et trait (prototype XL)',
glyphs: `${base}xl/glyphs/{fontstack}/{range}.pbf`,
sources: {
bigorre: {
type: 'vector',
url: `pmtiles://${base}${TUILES}`,
attribution: ATTRIBUTION,
},
},
layers: couches(),
};
}