Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : KA Maps Engine8 * File : sdk/web/demo/react-main.tsx9 * Module : sdk10 * Repository : https://git.spboucher.ai/ka-maps-engine11 * Created : 2026-12-0112 * Last Modified : 2026-12-0113 *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: support@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// Démonstration des liaisons React (@ka/maps/react) : <KaMapView>, <KaLayer>, <KaOverlay>, hooks.43// Montée sous <StrictMode> : la carte doit survivre au double montage de développement.4445import { StrictMode, useMemo, useState } from 'react';46import { createRoot } from 'react-dom/client';47import { KaLayer, KaMapView, KaOverlay, useKaCamera, useKaMap, useKaMapEvent } from '@ka/maps/react';48import type { AppId, Feature, KaMap, Mode } from '@ka/maps';49import { demoMarkers, MONTREAL } from './data.js';5051declare global {52 interface Window {53 kaReact?: { map?: KaMap; ready: boolean; clicks: number; error?: string };54 }55}56window.kaReact = { ready: false, clicks: 0 };5758function Status({ onPick }: { onPick: (f: Feature | null) => void }) {59 const map = useKaMap();60 const cam = useKaCamera();61 useKaMapEvent('load', () => {62 window.kaReact!.ready = true;63 });64 useKaMapEvent('click', (e) => {65 window.kaReact!.clicks++;66 onPick(e.features.find((f) => f.type === 'marker') ?? null);67 });68 return (69 <p className="msg" data-testid="status" role="status">70 {map.backend} · zoom {cam ? cam.zoom.toFixed(1) : '—'}71 </p>72 );73}7475function App() {76 const [mode, setMode] = useState<Mode>('2d');77 const [app, setApp] = useState<AppId | null>('louka');78 const [count, setCount] = useState(120);79 const [picked, setPicked] = useState<Feature | null>(null);80 const data = useMemo(() => demoMarkers(MONTREAL, count), [count]);81 return (82 <div className="layout">83 <nav className="panel" aria-label="Réglages">84 <section>85 <h1>KA Maps — React</h1>86 <p className="notice">Données de démonstration générées au hasard.</p>87 <div className="row">88 <button type="button" aria-pressed={mode === '3d'} onClick={() => setMode(mode === '3d' ? '2d' : '3d')}>89 {mode === '3d' ? 'Passer en 2D' : 'Passer en 3D'}90 </button>91 <button type="button" onClick={() => setApp(app === 'louka' ? 'immoka' : 'louka')}>92 Marque : {app}93 </button>94 <button type="button" onClick={() => setCount(count === 120 ? 300 : 120)}>95 {count} pastilles96 </button>97 </div>98 <p className="msg" data-testid="picked">99 {picked ? `Pastille ${String(picked.id)} : ${String(picked.label)}` : 'Aucune pastille choisie.'}100 </p>101 </section>102 </nav>103 <div className="stage">104 <KaMapView105 className="map"106 aria-label="Carte de démonstration React"107 options={{ center: MONTREAL, zoom: 14, controls: true, assetsUrl: new URLSearchParams(location.search).get('assets') || undefined, renderer: (new URLSearchParams(location.search).get('renderer') as 'auto') || 'auto' }}108 app={app}109 mode={mode}110 onReady={(m) => (window.kaReact!.map = m)}111 onError={(e) => (window.kaReact!.error = `${e.code}: ${e.message}`)}112 fallback={(e) => <p role="alert">Carte indisponible : {e.message}</p>}113 loading={<p className="msg">Chargement de la carte…</p>}114 >115 <KaLayer id="annonces" type="markers" data={data} options={{ cluster: { radius: 56, maxZoom: 15 } }} />116 <Status onPick={setPicked} />117 {picked?.lngLat ? (118 <KaOverlay lngLat={picked.lngLat} options={{ anchor: 'bottom', offset: [0, -14] }} className="demo-popup">119 <strong>{String(picked.label)}</strong> — annonce de démonstration120 </KaOverlay>121 ) : null}122 </KaMapView>123 </div>124 </div>125 );126}127128createRoot(document.getElementById('root')!).render(129 <StrictMode>130 <App />131 </StrictMode>,132);133