When clicking on Fornsök, Wikipedia and DigitaltMuseum on the map, the info window now opens as before the migration. Also fixed so the map updates when layer changes or something is found.

This commit is contained in:
2025-10-02 18:20:47 +02:00
parent 72d9b879c4
commit 674136ec50
3 changed files with 81 additions and 32 deletions

View File

@@ -26,6 +26,9 @@ import app.klottr.net.NoteDTO
import app.klottr.net.Wikipedia
import app.klottr.net.WikipediaPage
import app.klottr.platform.hasFgLocationPerms
import app.klottr.ui.DmDialog
import app.klottr.ui.FornsokDialog
import app.klottr.ui.WikiArticleDialog
import app.klottr.util.Config
import app.klottr.util.SettingsStore
import app.klottr.util.distanceMeters
@@ -70,6 +73,10 @@ fun MapDialog(
var selUri by remember { mutableStateOf<String?>(null) }
var selId by remember { mutableStateOf<String?>(null) } // klotter-id vid behov
var selLayer by remember { mutableStateOf<String?>(null) } // "Klotter", "Wikipedia", "Fornsök", ...
var selWiki by remember { mutableStateOf<WikipediaPage?>(null) }
var selForn by remember { mutableStateOf<FornsokItem?>(null) }
var selDm by remember { mutableStateOf<DigitaltMuseumItem?>(null) }
// Map state for shared MapContainer
val mapState = remember {
@@ -101,19 +108,6 @@ fun MapDialog(
myLat = current.value?.lat
myLon = current.value?.lon
}
//
//
// LaunchedEffect(Unit) {
// val fused = GmsLocationServices.getFusedLocationProviderClient(context)
// val loc = try {
// fused.lastLocation.await()
// ?: fused.getCurrentLocation(Priority.PRIORITY_HIGH_ACCURACY, null).await()
// } catch (_: Exception) { null }
// if (loc != null) {
// myLat = loc.latitude
// myLon = loc.longitude
// }
// }
LaunchedEffect(myLat, myLon, showKlotter, showWiki, wikiRadius, showDm, dmRadius, showFornsok, fornsokRadius) {
val lat = myLat; val lon = myLon
@@ -230,28 +224,23 @@ fun MapDialog(
id.startsWith("wiki:") -> {
val pid = id.removePrefix("wiki:")
wiki.firstOrNull { it.pageId.toString() == pid }?.let { w ->
val url = "https://sv.m.wikipedia.org/?curid=${w.pageId}"
setSel(w.lat, w.lon, w.title, url, "Wikipedia")
onOpenUrl(w.title, url)
selWiki = w
}
}
id.startsWith("dm:") -> {
val mid = id.removePrefix("dm:")
dm.firstOrNull { (it.webUrl ?: it.url) == mid }?.let { dmi ->
val url = dmi.webUrl ?: dmi.url
setSel(dmi.lat, dmi.lon, dmi.title, url, "DigitaltMuseum")
url?.let { onOpenUrl(dmi.title, it) }
selDm = dmi
}
}
id.startsWith("forn:") -> {
val fid = id.removePrefix("forn:")
forn.firstOrNull { (it.uri ?: it.title) == fid }?.let { f ->
setSel(f.lat, f.lon, f.title, f.uri, "Fornsök")
f.uri?.let { onOpenUrl(f.title, it) }
selForn = f
}
}
}
},
},
onReady = { ctrl ->
mapController = ctrl
ctrl.setMyLocationEnabled(hasFgLocationPerms())
@@ -274,6 +263,26 @@ fun MapDialog(
Button(onClick = onClose) { Text("Stäng") }
}
)
if (selWiki != null) {
WikiArticleDialog(
pageId = selWiki!!.pageId,
lat = selWiki!!.lat,
lon = selWiki!!.lon,
onClose = { selWiki = null }
)
}
if (selForn != null) {
FornsokDialog(
item = selForn!!,
onClose = { selForn = null }
)
}
if (selDm != null) {
DmDialog(
item = selDm!!,
onClose = { selDm = null }
)
}
}
// Keep map in sync with state changes, camera position, enabled features.