fix(geoportal): show UAT name in search results + fix map snap-back
Search results now JOIN GisUat to display UAT name prominently instead of just SIRUTA codes. Map flyTo uses imperative handle instead of stateful props that re-triggered on re-renders. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -67,25 +67,28 @@ export async function GET(req: Request) {
|
||||
// Search by cadastral reference
|
||||
const parcels = await prisma.$queryRaw`
|
||||
SELECT
|
||||
id,
|
||||
"cadastralRef",
|
||||
"areaValue",
|
||||
siruta,
|
||||
enrichment,
|
||||
ST_X(ST_Centroid(ST_Transform(geom, 4326))) as lng,
|
||||
ST_Y(ST_Centroid(ST_Transform(geom, 4326))) as lat
|
||||
FROM "GisFeature"
|
||||
WHERE geom IS NOT NULL
|
||||
AND "layerId" LIKE 'TERENURI%'
|
||||
AND ("cadastralRef" ILIKE ${pattern}
|
||||
OR enrichment::text ILIKE ${`%"NR_CAD":"${q}%`})
|
||||
ORDER BY "cadastralRef"
|
||||
f.id,
|
||||
f."cadastralRef",
|
||||
f."areaValue",
|
||||
f.siruta,
|
||||
f.enrichment,
|
||||
u.name as uat_name,
|
||||
ST_X(ST_Centroid(ST_Transform(f.geom, 4326))) as lng,
|
||||
ST_Y(ST_Centroid(ST_Transform(f.geom, 4326))) as lat
|
||||
FROM "GisFeature" f
|
||||
LEFT JOIN "GisUat" u ON u.siruta = f.siruta
|
||||
WHERE f.geom IS NOT NULL
|
||||
AND f."layerId" LIKE 'TERENURI%'
|
||||
AND (f."cadastralRef" ILIKE ${pattern}
|
||||
OR f.enrichment::text ILIKE ${`%"NR_CAD":"${q}%`})
|
||||
ORDER BY f."cadastralRef"
|
||||
LIMIT ${limit}
|
||||
` as Array<{
|
||||
id: string;
|
||||
cadastralRef: string | null;
|
||||
areaValue: number | null;
|
||||
siruta: string;
|
||||
uat_name: string | null;
|
||||
enrichment: Record<string, unknown> | null;
|
||||
lng: number;
|
||||
lat: number;
|
||||
@@ -94,11 +97,12 @@ export async function GET(req: Request) {
|
||||
for (const p of parcels) {
|
||||
const nrCad = (p.enrichment?.NR_CAD as string) ?? p.cadastralRef ?? "?";
|
||||
const area = p.areaValue ? `${Math.round(p.areaValue)} mp` : "";
|
||||
const uatLabel = p.uat_name ?? `SIRUTA ${p.siruta}`;
|
||||
results.push({
|
||||
id: `parcel-${p.id}`,
|
||||
type: "parcel",
|
||||
label: `Parcela ${nrCad}`,
|
||||
sublabel: [area, `SIRUTA ${p.siruta}`].filter(Boolean).join(" | "),
|
||||
label: `Parcela ${nrCad} — ${uatLabel}`,
|
||||
sublabel: [area, p.uat_name ? `SIRUTA ${p.siruta}` : ""].filter(Boolean).join(" | "),
|
||||
coordinates: p.lng && p.lat ? [p.lng, p.lat] : undefined,
|
||||
});
|
||||
}
|
||||
@@ -106,25 +110,28 @@ export async function GET(req: Request) {
|
||||
// Search by owner name in enrichment JSON
|
||||
const parcels = await prisma.$queryRaw`
|
||||
SELECT
|
||||
id,
|
||||
"cadastralRef",
|
||||
"areaValue",
|
||||
siruta,
|
||||
enrichment,
|
||||
ST_X(ST_Centroid(ST_Transform(geom, 4326))) as lng,
|
||||
ST_Y(ST_Centroid(ST_Transform(geom, 4326))) as lat
|
||||
FROM "GisFeature"
|
||||
WHERE geom IS NOT NULL
|
||||
AND "layerId" LIKE 'TERENURI%'
|
||||
AND enrichment IS NOT NULL
|
||||
AND enrichment::text ILIKE ${pattern}
|
||||
ORDER BY "cadastralRef"
|
||||
f.id,
|
||||
f."cadastralRef",
|
||||
f."areaValue",
|
||||
f.siruta,
|
||||
f.enrichment,
|
||||
u.name as uat_name,
|
||||
ST_X(ST_Centroid(ST_Transform(f.geom, 4326))) as lng,
|
||||
ST_Y(ST_Centroid(ST_Transform(f.geom, 4326))) as lat
|
||||
FROM "GisFeature" f
|
||||
LEFT JOIN "GisUat" u ON u.siruta = f.siruta
|
||||
WHERE f.geom IS NOT NULL
|
||||
AND f."layerId" LIKE 'TERENURI%'
|
||||
AND f.enrichment IS NOT NULL
|
||||
AND f.enrichment::text ILIKE ${pattern}
|
||||
ORDER BY f."cadastralRef"
|
||||
LIMIT ${limit}
|
||||
` as Array<{
|
||||
id: string;
|
||||
cadastralRef: string | null;
|
||||
areaValue: number | null;
|
||||
siruta: string;
|
||||
uat_name: string | null;
|
||||
enrichment: Record<string, unknown> | null;
|
||||
lng: number;
|
||||
lat: number;
|
||||
@@ -133,11 +140,13 @@ export async function GET(req: Request) {
|
||||
for (const p of parcels) {
|
||||
const nrCad = (p.enrichment?.NR_CAD as string) ?? p.cadastralRef ?? "?";
|
||||
const owner = (p.enrichment?.PROPRIETARI as string) ?? "";
|
||||
const uatLabel = p.uat_name ?? `SIRUTA ${p.siruta}`;
|
||||
const ownerShort = owner.length > 60 ? owner.slice(0, 60) + "..." : owner;
|
||||
results.push({
|
||||
id: `parcel-${p.id}`,
|
||||
type: "parcel",
|
||||
label: `Parcela ${nrCad}`,
|
||||
sublabel: owner.length > 60 ? owner.slice(0, 60) + "..." : owner,
|
||||
label: `Parcela ${nrCad} — ${uatLabel}`,
|
||||
sublabel: [ownerShort, p.uat_name ? `SIRUTA ${p.siruta}` : ""].filter(Boolean).join(" | "),
|
||||
coordinates: p.lng && p.lat ? [p.lng, p.lat] : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user