spb/toit-ka Public
Toit-Ka — louer ou acheter un toit au Québec, un seul endroit (fusion Lou-Ka × Immo-Ka) — www.toit-ka.com
Python 40.2%
TypeScript 39%
CSS 20.2%
HTML 0.7%
1// -----------------------------------------------------------------------------2// Author: Simon-Pierre Boucher3// Contact: contact@spboucher.ai4// Project: Toit-Ka5// kamaps/adapter.ts : adaptateur Toit-Ka -> MapProperty (framework Ka Maps).6// L'univers (louer/acheter) devient listingType rent/sale — chaque famille a7// son style de marqueur (voir theme.ts).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 ToitKaFeatureProps {19 uid: string;20 tx: "louer" | "acheter";21 title: string | null;22 address: string | null;23 price: number | null;24 price_label: string | null;25 type: string | null;26 bedrooms: number | null;27 bathrooms: number | null;28 source: string;29 city: string | null;30 sector: string | null;31 image: string | null;32}3334interface ToitKaFC {35 type: "FeatureCollection";36 features: {37 geometry: { coordinates: [number, number] };38 properties: ToitKaFeatureProps;39 }[];40 totalGeocoded?: number;41 totalMatching?: number;42}4344function toMapProperty(coords: [number, number], p: ToitKaFeatureProps): MapProperty {45 const louer = p.tx === "louer";46 return {47 id: p.uid,48 appSource: louer ? "lou-ka" : "immo-ka",49 longitude: coords[0],50 latitude: coords[1],51 kind: "listing",52 listingType: louer ? "rent" : "sale",53 price: p.price ?? undefined,54 propertyType: p.type ?? undefined,55 bedrooms: p.bedrooms ?? undefined,56 bathrooms: p.bathrooms ?? undefined,57 address: p.address ?? p.title ?? undefined,58 city: p.city ?? undefined,59 region: p.sector ?? undefined,60 thumbnailUrl: p.image ?? undefined,61 originalUrl: `/annonce/${encodeURIComponent(p.uid)}`,62 extra: {63 tx: p.tx,64 title: p.title,65 priceLabel: p.price_label,66 source: p.source,67 },68 };69}7071/** Adaptateur viewport -> données pour la carte Toit-Ka. */72export const toitKaMapAdapter: KaDataAdapter = {73 id: "toit-ka-listings",74 appSource: "immo-ka",75 async fetchInBounds(query: BoundsQuery): Promise<BoundsQueryResult> {76 const params = new URLSearchParams();77 const filters = (query.filters ?? {}) as Partial<ListingFilters>;78 for (const [k, v] of Object.entries(filters)) {79 if (v && k !== "sort") params.set(k, String(v));80 }81 params.set("bbox", bboxToString(query.bbox));82 params.set("limit", "3000");8384 const res = await fetch(`/api/listings.geojson?${params}`, {85 signal: query.signal,86 });87 if (!res.ok) throw new Error(`Carte : API ${res.status}`);88 const data = (await res.json()) as ToitKaFC;8990 return {91 properties: data.features.map((f) =>92 toMapProperty(f.geometry.coordinates, f.properties),93 ),94 totalCount: data.totalMatching,95 };96 },97};98