Repository Public
1#!/usr/bin/env python32# =============================================================================3# SP BOUCHER | SOFTWARE & RESEARCH4# ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# PROJECT METADATA8# -----------------------------------------------------------------------------9# Project : KA Maps Engine10# File : themes/tools/build.py11# Description : Génère les sept thèmes `themes/<nom>.json` (format12# kastyle/1) depuis une structure commune.13# Module : themes14# Repository : https://git.spboucher.ai/ka-maps-engine15# Created : 2026-12-0116# Last Modified : 2026-12-0117#18# =============================================================================19# AUTHOR & PROFESSIONAL AFFILIATION20# =============================================================================21#22# Author : Simon-Pierre Boucher23# Position : Professor of Finance24# Institution : Université du Québec en Outaouais (UQO)25# Department : Département des sciences administratives26# Organization : SP Boucher27#28# Website : https://spboucher.ai29# Git : https://git.spboucher.ai30#31# =============================================================================32# OFFICIAL CONTACT DIRECTORY33# =============================================================================34#35# General : info@spboucher.ai36# Professional : contact@spboucher.ai37# Direct : simon@spboucher.ai38# Research : research@spboucher.ai39# Development : dev@spboucher.ai40# Support : support@spboucher.ai41# Security/Admin : admin@spboucher.ai42# Notifications : notifications@spboucher.ai43#44# Preferred Contact: support@spboucher.ai45#46# =============================================================================47# COPYRIGHT & INTELLECTUAL PROPERTY48# =============================================================================49#50# Copyright (c) 202651# Simon-Pierre Boucher52#53# All rights reserved where applicable.54#55# This file is governed by the applicable project license,56# copyright notices, institutional agreements and relevant law.57#58# Unless expressly authorized by the applicable license or59# rights holder, copying, redistribution, sublicensing,60# publication and commercial exploitation are not permitted.61#62# Existing third-party rights and notices remain unaffected.63#64# =============================================================================65# CONFIDENTIALITY & SECURITY66# =============================================================================67#68# Classification : Public69# Distribution : Public repository; use is governed by the project license70# Security Contact : admin@spboucher.ai71#72# Access to this source does not independently grant permission73# to redistribute or disclose confidential materials.74#75# Do not embed credentials, private keys, access tokens,76# certificates or confidential personal information.77#78# =============================================================================79# LICENSE & MAINTENANCE80# =============================================================================81#82# License : None specified (no license file in this repository)83# Maintainer : Simon-Pierre Boucher84# Technical Contact: dev@spboucher.ai85#86# =============================================================================87# END OF SP BOUCHER SOURCE HEADER88# =============================================================================8990"""Génère les sept thèmes `themes/<nom>.json` (format kastyle/1) depuis une structure commune.9192Les fichiers JSON restent la donnée livrée (le moteur ne lit qu'eux) ; ce script est l'atelier :93une seule structure de couches (mêmes identifiants dans les sept thèmes, pour que les variantes de94marque et les essais du moteur s'y retrouvent), une palette et quelques partis pris par thème.9596 python3 themes/tools/build.py # écrit les sept thèmes97 python3 themes/tools/build.py signature # un seul9899Après toute modification : `themes/tools/check.py` (contrastes, daltonisme) puis100`themes/tools/render.py <thème>` (planches).101"""102import json103import os104import sys105106from palettes import THEMES107108ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))109110111def st(pairs, base=None, mul=1.0, step=False):112 d = {"stops": [[z, round(v * mul, 3) if isinstance(v, (int, float)) else v] for z, v in pairs]}113 if base:114 d["base"] = base115 if step:116 d["step"] = True117 return d118119120GROUND = ["!in", "struct", 1, 2]121TUNNEL = ["==", "struct", 2]122BRIDGE = ["==", "struct", 1]123NOLINK = ["!=", "link", 1]124125# Hiérarchie routière. Largeurs en px logiques ; à z20 elles suivent le terrain (rue locale ≈ 5 m).126# `far` : zoom jusqu'auquel la route est un simple trait d'encre (pas encore de liseré) ; `near` :127# zoom où elle est devenue une chaussée claire entre deux filets.128ROADS = [129 # id, filtre de genre, zoom min, largeur, liseré (px de chaque côté), couleur, couleur liseré, far, near130 ("service", [["==", "kind", "service"]], 14, [[14, 0.6], [15, 1.2], [16, 3], [18, 13], [20, 50]],131 [[14.8, 0], [15.5, 0.4], [17, 0.7], [20, 1.2]], "road-service", "casing-soft", 14.6, 15.4),132 ("minor", [["==", "kind", "minor"]], 12, [[12, 0.5], [13, 0.9], [14, 2.0], [16, 7], [18, 26], [20, 100]],133 [[13.2, 0], [14, 0.5], [16, 0.8], [20, 1.5]], "road", "casing", 13.2, 14),134 ("tertiary", [["==", "kind", "tertiary"], NOLINK], 10, [[10, 0.5], [12, 1.0], [14, 3.0], [16, 9], [18, 32], [20, 120]],135 [[12.2, 0], [13, 0.5], [14, 0.7], [16, 0.9], [20, 1.6]], "road", "casing", 12.2, 13),136 ("secondary", [["==", "kind", "secondary"], NOLINK], 9, [[9, 0.6], [11, 1.1], [13, 2.4], [14, 3.8], [16, 10], [18, 36], [20, 135]],137 [[11.6, 0], [12.4, 0.5], [14, 0.75], [16, 0.95], [20, 1.7]], "road", "casing", 11.6, 12.4),138 ("link", [["==", "link", 1], ["in", "kind", "motorway", "trunk", "primary", "secondary", "tertiary"]], 10,139 [[10, 0.5], [12, 1.2], [14, 3], [16, 8], [18, 28], [20, 105]],140 [[11.6, 0], [12.5, 0.5], [16, 0.9], [20, 1.6]], "road-major", "casing-major", 11.6, 12.5),141 ("primary", [["==", "kind", "primary"], NOLINK], 7, [[7, 0.6], [10, 1.1], [12, 2.2], [14, 4.5], [16, 11], [18, 40], [20, 150]],142 [[10.8, 0], [11.8, 0.55], [14, 0.8], [16, 1.0], [20, 1.8]], "road-major", "casing-major", 10.8, 11.8),143 ("trunk", [["==", "kind", "trunk"], NOLINK], 6, [[6, 0.7], [9, 1.2], [12, 2.8], [14, 5.0], [16, 12], [18, 44], [20, 170]],144 [[10, 0], [11.2, 0.6], [12, 0.8], [16, 1.05], [20, 1.9]], "road-major", "casing-major", 10, 11.2),145 ("motorway", [["==", "kind", "motorway"], NOLINK], 5, [[5, 0.8], [8, 1.4], [10, 2.1], [12, 3.4], [14, 5.6], [16, 13], [18, 48], [20, 180]],146 [[9.6, 0], [11, 0.65], [12, 0.85], [16, 1.15], [20, 2.0]], "road-motorway", "casing-motorway", 9.6, 11),147]148LIGHT_WAYS = [149 # id, zoom min, largeur, tirets, couleur, opacité150 ("path", 15, [[15, 0.6], [17, 1.1], [19, 2.4], [20, 5]], [2.5, 2], "path", 0.85),151 ("cycleway", 14.5, [[14, 0.6], [17, 1.2], [19, 2.6], [20, 5]], [5, 1.5], "cycleway", 0.85),152 ("track", 13, [[13, 0.6], [16, 1.6], [18, 5], [20, 18]], [6, 2], "track", 0.85),153]154RAIL_W = [[8, 0.5], [12, 0.9], [14, 1.3], [16, 2], [18, 4], [20, 9]]155156157def road_color(t, key, far, near, major=False):158 """Trait d'encre de loin, chaussée claire de près."""159 far_key = "road-far-major" if major else "road-far"160 return {"stops": [[far, "@" + far_key], [near, "@" + key]]}161162163def road_layers(t):164 L = []165 rs = t.get("road_scale", 1.0)166 cs = t.get("casing_scale", 1.0)167168 def group(suffix, struct, group_name):169 out = []170 for lid, minz, width, dash, color, op in LIGHT_WAYS:171 p = {"color": "@" + color, "width": st(width, 1.5, t.get("path_scale", 1.0)), "dash": dash, "cap": "butt", "join": "round", "opacity": op}172 if struct is BRIDGE:173 p["casing-color"] = "@land"174 p["casing-width"] = 1.2175 if struct is TUNNEL:176 p["opacity"] = 0.45177 out.append({"id": f"road-{lid}{suffix}", "type": "line", "source": "road", "group": group_name,178 "filter": ["all", ["==", "kind", lid], struct], "minzoom": minz, "paint": p})179 for lid, kinds, minz, width, casing, color, ccolor, far, near in ROADS:180 mz = minz if struct is GROUND or minz >= 11 else 11181 p = {"color": road_color(t, color, far, near, lid in ("motorway", "trunk")), "width": st(width, 1.6, rs), "join": "round"}182 if struct is GROUND:183 p["casing-color"] = "@" + ccolor184 p["casing-width"] = st(casing, mul=cs)185 p["cap"] = "round"186 elif struct is BRIDGE:187 p["casing-color"] = "@casing-bridge"188 p["casing-width"] = st([[z, v * 1.5] for z, v in casing], mul=cs)189 p["cap"] = "butt"190 else:191 p["color"] = {"stops": [[far, "@road-far-tunnel"], [near, "@road-tunnel"]]}192 p["casing-color"] = "@casing-tunnel"193 p["casing-width"] = st(casing, mul=cs)194 p["cap"] = "butt"195 p["dash"] = None196 p = {k: v for k, v in p.items() if v is not None}197 out.append({"id": f"road-{lid}{suffix}", "type": "line", "source": "road", "group": group_name,198 "filter": ["all", *kinds, struct], "minzoom": mz, "paint": p})199 return out200201 L += group("-tunnel", TUNNEL, "tunnel")202 L.append({"id": "road-ferry", "type": "line", "source": "road", "filter": ["==", "kind", "ferry"], "minzoom": 8,203 "paint": {"color": "@ferry", "width": st([[8, 0.6], [14, 1.2], [18, 2]]), "dash": [5, 4]}})204 L += group("", GROUND, "road")205 if t.get("centerlines"):206 # Convention de dessin : l'axe des voies principales en trait mixte (long, court).207 L.append({"id": "road-axis", "type": "line", "source": "road",208 "filter": ["all", ["in", "kind", "motorway", "trunk", "primary", "secondary"], NOLINK, GROUND], "minzoom": 15,209 "paint": {"color": "@axis", "width": st([[15, 0.5], [20, 1.0]]), "dash": [14, 4, 2, 4], "opacity": 0.8}})210 rail = {"color": "@rail", "width": st(RAIL_W, 1.4)}211 L.append({"id": "rail", "type": "line", "source": "road", "filter": ["all", ["==", "kind", "rail"], GROUND], "minzoom": 9,212 "paint": {**rail, "casing-color": "@land", "casing-width": st([[12, 0], [14, 0.8]])}})213 L.append({"id": "rail-ties", "type": "line", "source": "road", "filter": ["all", ["==", "kind", "rail"], ["!=", "struct", 2]], "minzoom": 15.5,214 "paint": {"color": "@rail", "width": st([[z, w * 3.2] for z, w in RAIL_W], 1.4), "dash": [0.14, 1.0], "cap": "butt", "opacity": 0.7}})215 L.append({"id": "rail-tunnel", "type": "line", "source": "road", "filter": ["all", ["==", "kind", "rail"], TUNNEL], "minzoom": 12,216 "paint": {**rail, "dash": [4, 3], "opacity": 0.45}})217 # Transports : le métro en trait plein fin, le REM et le train en trait mixte, le tramway en pointillé.218 # Couleur officielle de la ligne (attribut `colour` : vert, orange, jaune, bleu du métro) quand le thème le veut ;219 # à défaut, ou si l'attribut manque, l'encre neutre `transit`. Un filet de la teinte du sol détache le trait.220 official = t.get("transit_colour", False)221 tw = st([[10, 0.7], [13, 1.1], [16, 1.6], [19, 2.4]], mul=1.35 if official else 1.0)222 to = t.get("transit_opacity", 0.5) if not official else 0.9223 tc = ["attr", "colour", "@transit"] if official else "@transit"224 tcase = {"casing-color": "@land", "casing-width": st([[11, 0], [12.5, 0.6], [16, 1.0]])} if official else {}225 L.append({"id": "transit-subway", "type": "line", "source": "transit", "filter": ["all", ["==", "$type", "line"], ["==", "kind", "subway"]], "minzoom": 11,226 "paint": {"color": tc, "width": tw, "opacity": to, **tcase}})227 L.append({"id": "transit-rail", "type": "line", "source": "transit", "filter": ["all", ["==", "$type", "line"], ["in", "kind", "light_rail", "train"]], "minzoom": 10,228 "paint": {"color": tc, "width": tw, "opacity": to, "dash": [6, 1.5, 1.2, 1.5], "cap": "butt"}})229 L.append({"id": "transit-tram", "type": "line", "source": "transit", "filter": ["all", ["==", "$type", "line"], ["==", "kind", "tram"]], "minzoom": 12,230 "paint": {"color": tc, "width": tw, "opacity": to, "dash": [1, 1.5], "cap": "butt"}})231 L += group("-bridge", BRIDGE, "bridge")232 L.append({"id": "rail-bridge", "type": "line", "source": "road", "filter": ["all", ["==", "kind", "rail"], BRIDGE], "minzoom": 12,233 "paint": {**rail, "casing-color": "@casing-bridge", "casing-width": 1.2}})234 return L235236237def base_layers(t):238 # `land_far` : fond propre à la vue d'ensemble (paliers de zoom) — de nuit la terre s'éclaircit de loin pour se239 # détacher de l'eau (retour T1 d'Immo-Ka) et rejoint `land` à l'échelle de la ville.240 L = [{"id": "background", "type": "background", "paint": {"color": {"stops": t["land_far"]} if t.get("land_far") else "@land"}}]241 lc_op = st(t.get("landcover_opacity", [[4, 0.35], [7, 0.6], [10, 0.9], [13, 1.0]]))242 for k in ["glacier", "rock", "sand", "farmland", "scrub", "grass", "wetland", "forest"]:243 L.append({"id": f"landcover-{k}", "type": "fill", "source": "landcover", "filter": ["==", "kind", k], "paint": {"color": "@" + k, "opacity": lc_op}})244 lu = [("residential", 9), ("commercial", 11), ("industrial", 10), ("airport", 9), ("military", 10), ("quarry", 11), ("parking", 14),245 ("school", 12), ("hospital", 12), ("cemetery", 11), ("park", 9), ("golf", 10), ("pitch", 13)]246 for k, mz in lu:247 f = ["in", "kind", "school", "university"] if k == "school" else ["==", "kind", k]248 p = {"color": "@" + k}249 if k == "pitch":250 p.update({"outline-color": "@pitch-line", "outline-width": 0.75})251 if k == "park" and t.get("park_outline"):252 p.update({"outline-color": "@park-line", "outline-width": st([[12, 0], [14, 0.6], [18, 0.9]])})253 L.append({"id": f"landuse-{k}", "type": "fill", "source": "landuse", "filter": f, "minzoom": mz, "paint": p})254 L.append({"id": "hillshade", "type": "hillshade", "maxzoom": t.get("hillshade_maxzoom", 17),255 "paint": {"opacity": st(t.get("hillshade_opacity", [[5, 0.5], [12, 0.4], [16, 0.12]])), "exaggeration": t.get("hillshade_exaggeration", 1.0)}})256 ws = t.get("waterway_scale", 1.0)257 L.append({"id": "waterway-small", "type": "line", "source": "waterway", "filter": ["all", ["in", "kind", "stream", "drain"], ["!=", "tunnel", 1]], "minzoom": 12,258 "paint": {"color": "@waterway", "width": st([[12, 0.5], [16, 1.6], [20, 6]], 1.4, ws), "cap": "round"}})259 L.append({"id": "waterway-river", "type": "line", "source": "waterway", "filter": ["all", ["in", "kind", "river", "canal"], ["!=", "tunnel", 1]], "minzoom": 8,260 "paint": {"color": "@waterway", "width": st([[8, 0.6], [12, 1.6], [16, 5], [20, 18]], 1.4, ws), "cap": "round"}})261 L.append({"id": "water", "type": "fill", "source": "water",262 "paint": {"color": "@water", "outline-color": "@water-line", "outline-width": st(t.get("shore", [[6, 0.0], [9, 0.5], [13, 0.8], [17, 1.1]]))}})263 L.append({"id": "water-basin", "type": "fill", "source": "water", "filter": ["in", "kind", "basin", "reservoir"], "minzoom": 12, "paint": {"color": ["mix", "@water", "@land", 0.18]}})264 # Lots : la limite de propriété se dessine en trait mixte à deux points (convention d'arpentage).265 L.append({"id": "parcel", "type": "line", "source": "parcel", "minzoom": t.get("parcel_minzoom", 16),266 "paint": {"color": "@parcel", "width": st(t.get("parcel_width", [[16, 0.4], [19, 0.9]])), "dash": [9, 2, 1.2, 2, 1.2, 2]}})267 b = t["boundaries"]268 for level, mz in [(10, 12), (8, 10), (6, 8), (4, 2), (2, 0)]:269 color, width, dash = b[level]270 p = {"color": "@" + color, "width": st(width), "join": "round"}271 if dash:272 p["dash"] = dash273 L.append({"id": f"boundary-{level}", "type": "line", "source": "boundary", "filter": ["all", ["==", "level", level], ["!=", "maritime", 1]], "minzoom": mz, "paint": p})274 L.append({"id": "boundary-maritime", "type": "line", "source": "boundary", "filter": ["all", ["<=", "level", 4], ["==", "maritime", 1]], "minzoom": 3,275 "paint": {"color": "@water-line", "width": st([[3, 0.5], [10, 1.0]]), "dash": [5, 4]}})276 return L277278279def building_layers(t):280 common = {"opacity": st([[13, 0.6], [14.5, 1.0]]), "min-height": 2.5, "vertical-gradient": t.get("vertical_gradient", 0.25),281 "height-attr": "h", "base-attr": "mh", "height-unit": 0.1, "default-height": 7,282 "flat-outline-width": st(t.get("building_outline", [[13, 0.3], [16, 0.7], [19, 1.1]]))}283 # Arêtes au trait en 3D (haut et pied des murs) : le thème « blueprint » se lit comme une axonométrie.284 if t.get("edges"):285 common.update({"edge-color": "@" + t.get("edge_color", "building-outline"), "edge-width": t.get("edge_width", 1.3)})286 # Provenance des hauteurs : c'est une vérité de la 3D. Dans les thèmes généraux la hachure des toits (hauteur estimée287 # ou mesure du bloc) n'apparaît qu'avec les volumes ; à plat, les empreintes restent unies (la carte 2D ne doit pas288 # griser sous les pastilles et les noms de rue). `hatch_always` la garde aussi à plat (blueprint, financial, city3d).289 vol = {} if t.get("hatch_always") else {"pattern-volumes-only": True}290 # Règle de vérité : une hauteur estimée par défaut (hs = 3, ou provenance absente) n'a jamais le291 # dessin d'une hauteur mesurée (hs = 1) ou déduite des étages (hs = 2).292 return [293 {"id": "building-estimated", "type": "extrusion", "source": "building", "filter": ["!in", "hs", 1, 2, 4], "minzoom": 13,294 "paint": {**common, "roof-color": "@roof-estimated", "wall-color": "@wall-estimated", "flat-color": "@building-estimated",295 "flat-outline-color": "@building-outline-estimated",296 # Hauteur estimée (hs = 3) : toit hachuré, pour ne jamais la confondre avec une hauteur mesurée.297 "pattern": "hatch", "pattern-spacing": 6, **vol}},298 # Mesure du bloc (hs = 4) : une mesure LiDAR, mais celle du bloc et non de ce bâtiment — couleurs d'une299 # hauteur mesurée, toit à hachure légère (pas double de celui d'une estimation) pour ne pas la confondre.300 {"id": "building-block", "type": "extrusion", "source": "building", "filter": ["==", "hs", 4], "minzoom": 13,301 "paint": {**common, "roof-color": "@roof", "wall-color": "@wall", "flat-color": "@building", "flat-outline-color": "@building-outline",302 "pattern": "hatch", "pattern-spacing": 12, **vol}},303 {"id": "building", "type": "extrusion", "source": "building", "filter": ["in", "hs", 1, 2], "minzoom": 13,304 "paint": {**common, "roof-color": "@roof", "wall-color": "@wall", "flat-color": "@building", "flat-outline-color": "@building-outline"}},305 ]306307308def symbol_layers(t):309 up = "uppercase" if t.get("street_caps") else "none"310 ls_street = 0.08 if t.get("street_caps") else 0.02311 sz = t.get("text_scale", 1.0)312 pz = t.get("poi_zoom", 0) # décalage d'apparition des lieux (le thème minimal les retarde)313 halo = {"halo-color": "@halo", "halo-width": t.get("halo_width", 1.5)}314315 def sym(id, source, filt, minz, maxz=None, **paint):316 d = {"id": id, "type": "symbol", "source": source}317 if filt:318 d["filter"] = filt319 if minz is not None:320 d["minzoom"] = minz321 if maxz is not None:322 d["maxzoom"] = maxz323 p = {k.replace("_", "-"): v for k, v in paint.items()}324 for k, v in halo.items():325 p.setdefault(k, v)326 d["paint"] = p327 return d328329 def ts(pairs):330 return st(pairs, mul=sz)331332 def poi(id, kinds, minz, color, shape, prio, size=5.5, maxz=None):333 icon = {"shape": shape, "image": "{kind}", "image-size": st([[minz, 13], [18, 17]]), "color": "@" + color, "size": st([[minz, size - 0.5], [18, size + 1.5]]),334 "stroke-color": "@halo", "stroke-width": 1.2 if shape != "ring" else 1.8}335 return sym(id, "poi", ["in", "kind", *kinds], min(minz + pz, 17), maxz, text_field="{name}", font="medium" if prio < 91 else "regular",336 text_size=ts([[14, 10], [18, 12]]), color="@" + color, priority=prio, rank_attr="rank", max_width=8, text_anchor="top",337 text_offset=[0, 0.6], padding=5, icon=icon)338339 L = [340 sym("housenum", "housenum", None, 17, text_field="{num}", font="regular", text_size=ts([[17, 9.5], [20, 12]]), color="@ink-faint", priority=99, padding=3, halo_width=1.0),341 # Lieux utiles au logement, du plus fin au plus structurant. Formes : carré = enseignement et342 # savoir, anneau = santé, point = commerce et nature (en attendant l'atlas d'icônes).343 poi("poi-station", ["station"], 17, "ink-soft", "dot", 96, 4.5),344 poi("poi-clinic", ["clinic"], 16.5, "poi-health", "ring", 95, 5),345 poi("poi-commerce", ["grocery", "pharmacy", "mall"], 15.5, "poi-commerce", "dot", 94, 5),346 poi("poi-library", ["library"], 15.5, "poi-education", "square", 93, 5),347 poi("poi-school", ["school"], 15, "poi-education", "square", 92, 5),348 poi("poi-park", ["park"], 14.5, "park-ink", "dot", 91, 5),349 poi("poi-airport", ["airport"], 13, "ink-soft", "square", 90.5, 6),350 poi("poi-college", ["college"], 14, "poi-education", "square", 90.2, 6.5),351 poi("poi-major", ["university", "hospital"], 13.5, "poi-major", "square", 90, 7, 15),352 poi("poi-hospital", ["hospital"], 15, "poi-health", "ring", 89.5, 7.5),353 poi("poi-university", ["university"], 15, "poi-education", "square", 89, 7),354 sym("landuse-label", "landuse", ["all", ["has", "name"], ["in", "kind", "park", "cemetery", "golf", "university", "hospital", "airport"]], 13,355 text_field="{name}", font="regular", text_size=ts([[13, 10], [18, 13]]), color="@park-ink", letter_spacing=0.02, max_width=7, priority=88, padding=6),356 sym("road-label-small", "road", ["all", ["has", "name"], ["in", "kind", "service", "path", "cycleway", "track"]], 17,357 text_field="{name}", font="regular", text_size=ts([[17, 10], [20, 12]]), color="@ink-soft", placement="line", repeat=500, priority=87, letter_spacing=ls_street, transform=up),358 sym("road-label-minor", "road", ["all", ["has", "name"], ["in", "kind", "minor", "tertiary"]], 15,359 text_field="{name}", font="regular", text_size=ts([[15, 10], [18, 12.5], [20, 14]]), color="@ink-soft", placement="line", repeat=420, priority=85, letter_spacing=ls_street, transform=up),360 sym("waterway-label", "waterway", ["has", "name"], 12, text_field="{name}", font="regular", text_size=ts([[12, 10], [17, 12.5]]), color="@water-ink",361 placement="line", repeat=600, priority=82, letter_spacing=0.1),362 sym("water-label", "water", ["all", ["has", "name"], ["!=", "kind", "ocean"]], 8, text_field="{name}", font="medium", text_size=ts([[8, 10], [14, 13.5]]),363 color="@water-ink", letter_spacing=0.12, max_width=7, priority=80, padding=24, halo_color=["alpha", "@water", 0.6], halo_width=1.0),364 sym("water-label-ocean", "water", ["all", ["has", "name"], ["==", "kind", "ocean"]], 2, text_field="{name}", font="medium", text_size=ts([[2, 11], [8, 16]]),365 color="@water-ink", transform="uppercase", letter_spacing=0.3, max_width=8, priority=78, padding=30, halo_color=["alpha", "@water", 0.6], halo_width=1.0),366 sym("place-neighbourhood", "place", ["==", "kind", "neighbourhood"], 13, 17, text_field="{name}", font=t.get("district_font", "regular"),367 text_size=ts([[13, 9.5], [16, 11.5]]), color="@" + t.get("district_ink", "ink-faint"), transform="uppercase", letter_spacing=0.16, max_width=7, priority=75, rank_attr="rank", padding=6),368 sym("road-label-major", "road", ["all", ["has", "name"], ["in", "kind", "motorway", "trunk", "primary", "secondary"]], 12,369 text_field="{name}", font="medium", text_size=ts([[12, 10], [16, 12.5], [20, 15]]), color="@" + t.get("street_ink", "ink"), placement="line", repeat=480, priority=70,370 letter_spacing=ls_street + 0.01, transform=up),371 sym("transit-station-minor", "transit", ["all", ["==", "$type", "point"], ["==", "kind", "bus_terminal"]], 14, text_field="{name}", font="medium",372 text_size=ts([[14, 10], [18, 12]]), color="@ink-soft", text_anchor="top", text_offset=[0, 0.6], max_width=8, priority=67, padding=4,373 icon={"shape": "square", "color": "@halo", "size": 6, "stroke-color": "@transit-ink", "stroke-width": 1.5}),374 # Gares et REM : carré plein ; métro : anneau. La forme porte le mode, pas la couleur.375 sym("transit-station-rail", "transit", ["all", ["==", "$type", "point"], ["in", "kind", "rem", "train"]], 11, text_field="{name}", font="medium",376 text_size=ts([[11, 10], [18, 12.5]]), color="@ink", text_anchor="top", text_offset=[0, 0.65], max_width=8, priority=64, padding=4,377 icon={"image": "{kind}", "image-size": st([[11, 12], [16, 17]]), "shape": "square", "color": "@transit-ink", "size": st([[11, 5], [16, 7.5]]), "stroke-color": "@halo", "stroke-width": 1.5}),378 sym("transit-station", "transit", ["all", ["==", "$type", "point"], ["==", "kind", "metro"]], 12, text_field="{name}", font="medium",379 text_size=ts([[12, 10], [18, 12.5]]), color="@ink", text_anchor="top", text_offset=[0, 0.65], max_width=8, priority=65, padding=4,380 icon={"image": "{kind}", "image-size": st([[11, 12], [16, 17]]), "shape": "ring", "color": "@transit-ink", "size": st([[12, 6], [16, 9.5]]), "stroke-color": "@halo", "stroke-width": 2.2}),381 sym("place-suburb", "place", ["==", "kind", "suburb"], 11, 16, text_field="{name}", font="medium", text_size=ts([[11, 10], [15, 13]]),382 color="@" + t.get("suburb_ink", "ink-soft"), transform="uppercase", letter_spacing=0.14, max_width=7, priority=60, rank_attr="rank", padding=6),383 sym("place-hamlet", "place", ["==", "kind", "hamlet"], 12, 17, text_field="{name}", font="regular", text_size=ts([[12, 10], [16, 12]]), color="@ink-soft",384 max_width=7, priority=58, rank_attr="rank", padding=4),385 sym("place-village", "place", ["==", "kind", "village"], 10, 16, text_field="{name}", font="regular", text_size=ts([[10, 10.5], [14, 13.5]]), color="@ink",386 max_width=7, priority=50, rank_attr="rank", padding=4),387 sym("road-shield", "road", ["all", ["has", "ref"], ["in", "kind", "primary", "secondary"]], 11, text_field="{ref}", font="semibold", text_size=9.5,388 color="@shield-ink", repeat=700, priority=47, padding=10, halo_width=0,389 icon={"shape": "shield", "color": "@shield", "size": 3, "stroke-color": "@shield-stroke", "stroke-width": 1}),390 sym("road-shield-major", "road", ["all", ["has", "ref"], ["in", "kind", "motorway", "trunk"]], 7, text_field="{ref}", font="semibold",391 text_size=st([[7, 9], [12, 10.5]]), color="@shield-major-ink", repeat=600, priority=45, padding=12, halo_width=0,392 icon={"shape": "shield", "color": "@shield-major", "size": 3, "stroke-color": "@shield-major-stroke", "stroke-width": 1}),393 sym("place-town", "place", ["==", "kind", "town"], 7, 15, text_field="{name}", font="medium", text_size=ts([[7, 10.5], [12, 15]]), color="@ink", max_width=7,394 priority=40, rank_attr="rank", padding=4),395 sym("place-city", "place", ["==", "kind", "city"], 9, 15, text_field="{name}", font="semibold", text_size=ts([[9, 15], [14, 24]]), color="@ink",396 letter_spacing=-0.005, max_width=8, priority=30, rank_attr="rank", padding=4, halo_width=1.8),397 sym("place-city-far", "place", ["all", ["==", "kind", "city"], ["not", ["<=", "rank", 2]]], 4.5, 9, text_field="{name}", font="medium",398 text_size=ts([[4, 10], [9, 13.5]]), color="@ink", max_width=8, priority=31, rank_attr="rank", padding=3, text_anchor="left", text_offset=[0.5, 0],399 icon={"shape": "dot", "color": "@halo", "size": st([[4, 3.5], [9, 5]]), "stroke-color": "@ink", "stroke-width": 1.2}),400 # Métropoles et capitales : plus grandes, placées avant les autres villes.401 sym("place-city-major", "place", ["all", ["==", "kind", "city"], ["<=", "rank", 2]], 3, 9, text_field="{name}", font="semibold",402 text_size=ts([[3, 11], [9, 17]]), color="@ink", max_width=8, priority=29, rank_attr="rank", padding=3, text_anchor="left", text_offset=[0.5, 0],403 icon={"shape": "square", "color": "@ink", "size": st([[3, 4], [9, 6]]), "stroke-color": "@halo", "stroke-width": 1.25}),404 sym("place-province", "place", ["==", "kind", "province"], 3, 8, text_field="{name}", font="medium", text_size=ts([[3, 9.5], [7, 14]]), color="@ink-soft",405 transform="uppercase", letter_spacing=0.22, max_width=8, priority=20, rank_attr="rank", padding=6),406 sym("place-country", "place", ["==", "kind", "country"], 0, 6, text_field="{name}", font="semibold", text_size=ts([[1, 10], [5, 15]]), color="@ink",407 transform="uppercase", letter_spacing=0.18, max_width=7, priority=10, rank_attr="rank", padding=6),408 ]409 return L410411412def markers(t):413 m = {414 "pill": {415 "font": "semibold", "text-size": 12.5, "padding": [9, 5], "radius": 11, "pointer": 5,416 "shadow-color": "@pill-shadow", "shadow-radius": 4, "shadow-offset-y": 1, "outline-fill": "@pill-paper",417 "states": {418 "default": {"fill": "@accent", "text": "@accent-ink", "stroke": "@pill-line", "stroke-width": 1.5, "scale": 1},419 "hover": {"fill": ["darken", "@accent", 0.06], "scale": 1.06},420 "selected": {"fill": "@accent-selected", "text": "@accent-selected-ink", "stroke": "@accent-selected-line", "stroke-width": 2.25, "scale": 1.14},421 "visited": {"fill": "@accent-seen", "text": "@accent-seen-ink", "stroke-width": 1, "scale": 0.92},422 },423 # Vérité des données : la nature change la FORME (plein, contour continu, contour en tirets).424 "natures": {"observe": {"mode": "solid"}, "estime": {"mode": "outline"}, "hypothese": {"mode": "outline", "dash": [3, 2], "opacity": 0.92}},425 "kinds": {426 "_note": "genres communs aux quatre produits ; une marque en ajoute dans sa variante",427 "good": {"default": {"fill": "@accent-good", "text": "@accent-good-ink"}},428 "high": {"default": {"fill": "@accent-high", "text": "@accent-high-ink"}},429 "sold": {"default": {"fill": "@accent-sold", "text": "@accent-sold-ink"}},430 "featured": {"default": {"fill": "@accent-selected", "text": "@accent-selected-ink", "stroke": "@accent", "stroke-width": 2}},431 },432 },433 "cluster": {"colors": [[2, ["mix", "@accent", "@pill-paper", 0.22]], [100, "@accent"], [2000, ["mix", "@accent", "@accent-selected", 0.5]]],434 "sizes": [[2, 30], [10, 36], [100, 46], [1000, 58]], "text": "@accent-ink", "stroke": "@pill-line", "stroke-width": 2,435 "font": "semibold", "text-size": 12.5, "opacity": 1},436 "point": {"radius": 4.5, "color": "@accent", "stroke-color": "@pill-line", "stroke-width": 1.25, "opacity": 1},437 "selection": {"color": "@accent", "width": 2.5, "fill": ["alpha", "@accent", 0.22], "pulse-color": ["alpha", "@accent", 0.4], "pulse-duration": 1600, "pulse-scale": 1.7},438 "heat": {"radius": 28, "intensity": 1, "opacity": 0.82,439 "ramp": [[0, ["alpha", "@heat-1", 0]], [0.2, ["alpha", "@heat-1", 0.55]], [0.5, ["alpha", "@heat-2", 0.8]], [0.8, ["alpha", "@heat-3", 0.9]], [1, "@heat-4"]]},440 "columns": {"color": "@accent", "opacity": 0.9, "side-shade": 0.24, "outline-color": ["alpha", "@ink", 0.25], "width": 24},441 "tools": {"line-color": "@ink", "line-width": 2, "line-dash": [5, 4], "fill-color": ["alpha", "@accent", 0.14], "vertex-color": "@pill-paper",442 "vertex-stroke-color": "@ink", "vertex-radius": 4.5, "label-color": "@ink", "label-halo-color": "@halo", "label-size": 12},443 "polygon": {"fill": ["alpha", "@accent", 0.16], "stroke": "@accent", "stroke-width": 1.5},444 "line": {"stroke": "@accent", "stroke-width": 2.5},445 }446 return m447448449def scales():450 h = ["@heat-0", "@heat-1", "@heat-2", "@heat-3", "@heat-4"]451 c = ["@cool-0", "@cool-1", "@cool-2", "@cool-3", "@cool-4"]452 d = ["@cool-div-2", "@cool-div-1", "@neutral", "@heat-div-1", "@heat-div-2"]453 lin = lambda cols, lo=0.0, hi=1.0: [[round(lo + (hi - lo) * i / (len(cols) - 1), 3), x] for i, x in enumerate(cols)]454 stp = lambda cols, lo=0.0, hi=1.0: [[round(lo + (hi - lo) * i / len(cols), 3), x] for i, x in enumerate(cols)]455 return {456 "_note": "rampes de référence normalisées, vérifiées par themes/tools/check.py (clarté monotone, daltonisme) ; une couche d'application fournit d'ordinaire ses propres bornes",457 "value": {"type": "linear", "stops": lin(h), "nullColor": "@null"},458 "value-steps": {"type": "steps", "stops": stp(h), "nullColor": "@null"},459 "yield": {"type": "linear", "stops": lin(c), "nullColor": "@null"},460 "yield-steps": {"type": "steps", "stops": stp(c), "nullColor": "@null"},461 "diverging": {"type": "linear", "stops": lin(d, -1, 1), "nullColor": "@null"},462 "diverging-steps": {"type": "steps", "stops": stp(d, -1, 1), "nullColor": "@null"},463 }464465466def build(name):467 t = THEMES[name]468 doc = {469 "kastyle": 1, "name": name, "version": "1.1.0", "minEngine": "0.1.0",470 "_description": t["description"],471 "_source": "généré par themes/tools/build.py depuis themes/tools/palettes.py — modifier la source, pas ce fichier",472 "defaults": t.get("defaults", {"mode": "2d", "pitch": 0, "bearing": 0}),473 "palette": t["palette"],474 "background": {"stops": t["land_far"]} if t.get("land_far") else "@land",475 "light": t["light"],476 "terrain": t["terrain"],477 "layers": base_layers(t) + road_layers(t) + building_layers(t) + symbol_layers(t),478 "markers": markers(t),479 "scales": scales(),480 }481 for lid, patch in t.get("layer_patches", {}).items():482 layer = next(l for l in doc["layers"] if l["id"] == lid)483 for k, v in patch.items():484 if k in ("minzoom", "maxzoom"):485 layer[k] = v486 elif v is None:487 layer["paint"].pop(k, None)488 else:489 layer["paint"][k] = v490 for k, v in t.get("marker_patches", {}).items():491 sect, key = k.split(".")492 doc["markers"][sect][key] = v493 path = os.path.join(ROOT, f"{name}.json")494 with open(path, "w") as f:495 json.dump(doc, f, ensure_ascii=False, indent=1)496 f.write("\n")497 return len(doc["layers"])498499500if __name__ == "__main__":501 for n in sys.argv[1:] or THEMES:502 print(n, build(n), "couches")503