Lou·Ka — tous les logements à louer du Québec, un seul endroit.
HTML 98.9%
Python 0.6%
1// -----------------------------------------------------------------------------2// Author: Simon-Pierre Boucher3// Contact: contact@spboucher.ai4// Project: Groupe Ka / Ka Maps (Lou-Ka integration)5// kamaps/adapter.ts : adaptateur de données Lou-Ka → MapProperty.6// Transforme /api/listings.geojson (bbox + filtres) au modèle canonique du7// framework — le domaine Lou-Ka reste dans l'app, la carte n'en sait rien.8// -----------------------------------------------------------------------------9import type {10 BoundsQuery,11 BoundsQueryResult,12 KaDataAdapter,13 MapProperty,14} from "@groupe-ka/ka-maps";15import { bboxToString } from "@groupe-ka/ka-maps";16import type { ListingFilters } from "../api";1718interface LouKaFeatureProps {19 uid: string;20 title: string | null;21 address: string | null;22 price: number | null;23 price_label: string | null;24 unit_type: string | null;25 availability_date: string | null;26 source: string;27 city: string | null;28 sector: string | null;29 area_sqft: number | null;30 image: string | null;31}3233interface LouKaFC {34 type: "FeatureCollection";35 features: {36 geometry: { coordinates: [number, number] };37 properties: LouKaFeatureProps;38 }[];39 totalGeocoded?: number;40 totalMatching?: number;41}4243function toMapProperty(44 coords: [number, number],45 p: LouKaFeatureProps,46): MapProperty {47 return {48 id: p.uid,49 appSource: "lou-ka",50 longitude: coords[0],51 latitude: coords[1],52 kind: "listing",53 listingType: "rent",54 price: p.price ?? undefined,55 propertyType: p.unit_type ?? undefined,56 address: p.address ?? p.title ?? undefined,57 city: p.city ?? undefined,58 region: p.sector ?? undefined,59 thumbnailUrl: p.image ?? undefined,60 originalUrl: `/logement/${encodeURIComponent(p.uid)}`,61 extra: {62 title: p.title,63 priceLabel: p.price_label,64 availabilityDate: p.availability_date,65 source: p.source,66 areaSqft: p.area_sqft,67 sector: p.sector,68 },69 };70}7172/** Adaptateur viewport→données pour la carte Lou-Ka. */73export const louKaMapAdapter: KaDataAdapter = {74 id: "lou-ka-listings",75 appSource: "lou-ka",76 async fetchInBounds(query: BoundsQuery): Promise<BoundsQueryResult> {77 const params = new URLSearchParams();78 const filters = (query.filters ?? {}) as Partial<ListingFilters>;79 for (const [k, v] of Object.entries(filters)) {80 if (v) params.set(k, String(v));81 }82 params.set("bbox", bboxToString(query.bbox));83 params.set("limit", "3000");8485 const res = await fetch(`/api/listings.geojson?${params}`, {86 signal: query.signal,87 });88 if (!res.ok) throw new Error(`Carte : API ${res.status}`);89 const data = (await res.json()) as LouKaFC;9091 return {92 properties: data.features.map((f) =>93 toMapProperty(f.geometry.coordinates, f.properties),94 ),95 totalCount: data.totalMatching,96 };97 },98};99