Skip to content

Commit

Permalink
Fix marker info window covering search bar and filter row
Browse files Browse the repository at this point in the history
Part of #12
  • Loading branch information
AaroKoinsaari committed Nov 6, 2024
1 parent b886b66 commit 0e6210b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import androidx.compose.ui.zIndex
import com.aarokoinsaari.accessibilitymap.R
import com.aarokoinsaari.accessibilitymap.intent.MapIntent
import com.aarokoinsaari.accessibilitymap.model.AccessibilityInfo
Expand Down Expand Up @@ -204,8 +205,12 @@ fun MapScreen(
onClusterItemClick = { clusterItem ->
onIntent(MapIntent.MapClick(clusterItem))
coroutineScope.launch {
val adjustedPosition = LatLng(
clusterItem.position.latitude + 0.003,
clusterItem.position.longitude
)
cameraPositionState.animate(
update = CameraUpdateFactory.newLatLng(clusterItem.position),
update = CameraUpdateFactory.newLatLng(adjustedPosition),
durationMs = 200
)
}
Expand All @@ -231,6 +236,42 @@ fun MapScreen(
)
}

// Since ClusterItem info windows currently cannot be customized,
// for now the only reasonable solution is to insert the custom info
// window according to the selected cluster item. This should be changed
// when the issue mentioned above is closed and Marker Composables can be used instead.
state.selectedClusterItem?.let { selectedItem ->
val screenPosition =
cameraPositionState.projection?.toScreenLocation(selectedItem.position)

if (screenPosition != null) {
var popupSize by remember { mutableStateOf(IntSize.Zero) }
val markerHeight =
with(LocalDensity.current) { 24.dp.roundToPx() }

MarkerInfoWindow(
item = selectedItem,
onClick = { onIntent(MapIntent.SelectPlace(selectedItem.placeData)) },
modifier = Modifier
.onGloballyPositioned { coordinates ->
popupSize = coordinates.size
}
.offset {
IntOffset(
x = screenPosition.x - (popupSize.width / 2),
y = screenPosition.y - popupSize.height - markerHeight
)
}
.background(
color = Color.White,
shape = RoundedCornerShape(16.dp)
)
.padding(16.dp)
.clickable { onIntent(MapIntent.SelectPlace(selectedItem.placeData)) }
)
}
}

Column(
modifier = Modifier
.fillMaxWidth()
Expand Down Expand Up @@ -263,7 +304,9 @@ fun MapScreen(
)
}
},
modifier = Modifier.fillMaxWidth()
modifier = Modifier
.fillMaxWidth()
.zIndex(1f)
)

FilterChipRow(
Expand All @@ -273,6 +316,7 @@ fun MapScreen(
.fillMaxWidth()
.background(Color.Transparent)
.padding(horizontal = 12.dp, vertical = 4.dp)
.zIndex(1f)
)
}

Expand Down Expand Up @@ -304,42 +348,6 @@ fun MapScreen(
)
}
}

// Since ClusterItem info windows currently cannot be customized,
// for now the only reasonable solution is to insert the custom info
// window according to the selected cluster item. This should be changed
// when the issue mentioned above is closed and Marker Composables can be used instead.
state.selectedClusterItem?.let { selectedItem ->
val screenPosition =
cameraPositionState.projection?.toScreenLocation(selectedItem.position)

if (screenPosition != null) {
var popupSize by remember { mutableStateOf(IntSize.Zero) }
val markerHeight =
with(LocalDensity.current) { 24.dp.roundToPx() }

MarkerInfoWindow(
item = selectedItem,
onClick = { onIntent(MapIntent.SelectPlace(selectedItem.placeData)) },
modifier = Modifier
.onGloballyPositioned { coordinates ->
popupSize = coordinates.size
}
.offset {
IntOffset(
x = screenPosition.x - (popupSize.width / 2),
y = screenPosition.y - popupSize.height - markerHeight
)
}
.background(
color = Color.White,
shape = RoundedCornerShape(16.dp)
)
.padding(16.dp)
.clickable { onIntent(MapIntent.SelectPlace(selectedItem.placeData)) }
)
}
}
}
}

Expand Down Expand Up @@ -555,10 +563,10 @@ private fun moveCameraToUserLocation(

private fun AccessibilityStatus?.getAccessibilityStatusStringRes(): Int =
when (this) {
FULLY_ACCESSIBLE -> R.string.wheelchair_access_fully_accessible
LIMITED_ACCESSIBILITY -> R.string.wheelchair_access_limited_accessibility
NOT_ACCESSIBLE -> R.string.wheelchair_access_not_accessible
else -> R.string.wheelchair_access_unknown
FULLY_ACCESSIBLE -> R.string.accessibility_status_yes
LIMITED_ACCESSIBILITY -> R.string.accessibility_status_limited
NOT_ACCESSIBLE -> R.string.no
else -> R.string.accessibility_status_unknown
}

private fun AccessibilityStatus.getAccessibilityColor(): Color =
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,5 @@
<string name="place_details_basic_details_headline">Accessibility</string>
<string name="place_details_basic_details_parking">Parking:</string>
<string name="place_details_basic_details_floor">On floor:</string>
<string name="accessibility_status_limited">limited</string>
</resources>

0 comments on commit 0e6210b

Please sign in to comment.