fix(PlaceCard): correct boundary fetch for basemap label clicks

When clicking city/area labels with wikidataId, the wikidata path now:
1. Always runs when wikidataId is present (removed OSM data guard)
2. Sets osm_type='R' and osm_id from wikidata's osm_relation_id
3. This allows Effect 3 (fetchPlaceDetails) to then fetch wiki_summary

Also prevents Effect 2 (reverse geocode) from overwriting OSM data
that was already set by the wikidata path.

Fixes: boundary outline, fly-to-bounds, wiki summary display

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Matt 2026-05-01 18:51:39 +00:00
commit 871662bccf

View file

@ -359,6 +359,8 @@ export function PlaceCard({ place, variant = "preview", expanded = true, onToggl
if (result?.raw?.osm_type && result?.raw?.osm_id) {
const current = useStore.getState().selectedPlace
if (current && current.lat === placeLat && current.lon === placeLon) {
// Skip if OSM data already set (e.g., by wikidata path with osm_relation_id)
if (current.raw?.osm_type && current.raw?.osm_id) return
// Merge OSM data into raw, preserving existing data
useStore.getState().setSelectedPlace({
...current,
@ -393,7 +395,7 @@ export function PlaceCard({ place, variant = "preview", expanded = true, onToggl
}, [osmType, osmId, placeLat, placeLon])
useEffect(() => {
if (osmType && osmId) return
// Always run wikidata path when wikidataId is present
if (!wikidataId) return
const controller = new AbortController()
fetchPlaceByWikidata(wikidataId, controller.signal).then((data) => {
@ -405,6 +407,16 @@ export function PlaceCard({ place, variant = "preview", expanded = true, onToggl
osm_relation_id: data.osm_relation_id,
extratags: { ...(prev && prev !== "loading" ? prev.extratags : {}), ...data.extratags },
}))
// Set OSM data from wikidata response so Effect 3 can fetch wiki_summary
if (data.osm_relation_id) {
const current = useStore.getState().selectedPlace
if (current && current.lat === placeLat && current.lon === placeLon) {
useStore.getState().setSelectedPlace({
...current,
raw: { ...current.raw, osm_type: "R", osm_id: data.osm_relation_id }
})
}
}
if (data?.boundary) {
const current = useStore.getState().selectedPlace
if (current && current.lat === placeLat && current.lon === placeLon) {
@ -417,7 +429,7 @@ export function PlaceCard({ place, variant = "preview", expanded = true, onToggl
}
})
return () => controller.abort()
}, [wikidataId, osmType, osmId, placeLat, placeLon])
}, [wikidataId, placeLat, placeLon])
useEffect(() => {
if (variant !== "preview" || !userLocation || placeLat == null || placeLon == null) { setDriveTime(null); return }