Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : Vrai-Prix8 * File : src/lib/carte.ts9 * Module : lib10 * Repository : https://git.spboucher.ai/vrai-prix11 * Created : 2026-11-2612 * Last Modified : 2026-11-2613 *14 * Author : Simon-Pierre Boucher15 * Position : Professor of Finance16 * Institution : Université du Québec en Outaouais (UQO)17 * Organization : SP Boucher18 * Website : https://spboucher.ai19 * Git : https://git.spboucher.ai20 *21 * Preferred Contact: contact@spboucher.ai22 * Development : dev@spboucher.ai23 * Support : support@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Carte : constantes et accès aux points (/api/map). Module pur, importable côté client.43// La carte affiche des VALEURS ESTIMÉES (jamais des prix demandés).4445/** Jeton Mapbox public (pk.*), restreint par URL côté Mapbox ; surchargé par NEXT_PUBLIC_MAPBOX_TOKEN. */46export const MAPBOX_TOKEN: string =47 process.env.NEXT_PUBLIC_MAPBOX_TOKEN ??48 "pk.eyJ1Ijoic3Bib3VjaGVyIiwiYSI6ImNtc3Fyb3k4djAwOTgyenB3dWt6NHBjc2kifQ.poqLf0ADy3lIh28O-pFI2Q";4950/** Zoom minimal de chargement : sous ce niveau, on invite à zoomer. */51export const MIN_ZOOM_FETCH = 12;5253export const TYPE_FR: Record<string, string> = {54 unifamilial: "Unifamiliale",55 condo_ou_multi: "Condo / multi",56 plex: "Plex",57 chalet: "Chalet",58 terrain: "Terrain",59 maison_mobile: "Maison mobile",60 autre: "Autre",61};6263export interface PointUnite {64 id: string;65 adresse: string | null;66 apt: string | null;67 municipalite: string | null;68 typeProp: string | null;69 lat: number;70 lng: number;71 est2026: number | null;72}7374export interface Bbox {75 west: number;76 south: number;77 east: number;78 north: number;79}8081/** Unités d'évaluation dans la zone visible (contrat : docs/API.md, GET /api/map). */82export async function unitesDansZone(b: Bbox, signal?: AbortSignal, limit = 1500): Promise<PointUnite[]> {83 const bbox = [b.west, b.south, b.east, b.north].map((v) => v.toFixed(6)).join(",");84 const res = await fetch(`/api/map?layer=units&bbox=${bbox}&limit=${limit}`, { signal });85 if (!res.ok) throw new Error(`Carte : API ${res.status}`);86 const data = (await res.json()) as { points: PointUnite[] };87 return data.points;88}8990/** 425 000 → « 425 k » ; 1 250 000 → « 1,25 M » (étiquette de pastille). */91export function valeurCourte(v: number | null | undefined): string {92 if (v == null || !Number.isFinite(v)) return "";93 if (v >= 1_000_000) return `${(v / 1_000_000).toLocaleString("fr-CA", { maximumFractionDigits: 2 })} M`;94 return `${Math.round(v / 1000).toLocaleString("fr-CA")} k`;95}96