Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue: GroundOverlay bad placement when invalidate map #1990

Open
Vaxela opened this issue Apr 5, 2024 · 0 comments
Open

Issue: GroundOverlay bad placement when invalidate map #1990

Vaxela opened this issue Apr 5, 2024 · 0 comments

Comments

@Vaxela
Copy link

Vaxela commented Apr 5, 2024

Hi, I'm Lucas, and I'm integrating osmdroid with Jetpack Compose in my project. I've encountered a peculiar issue with ground overlays that I believe is a bug.

Ground Overlay

[ ] Question
[X] Bug
[ ] Improvement
[ ] Build system related
[ ] Performance
[ ] Documentation

Description and/or steps/code to reproduce the problem

The issue doesn't manifest when the zoom level is set to 5 using Mapnik for France. However, on zooming into certain bounding boxes, my ground overlays occasionally do not align with the ground; instead, they appear to float above it.

Initial Setup
I use the zoomToBoundingBox function at the beginning to adjust the map view:
/** * Zoom the map to enclose the specified bounding box, as closely as possible. Must be called * after display layout is complete, or screen dimensions are not known, and will always zoom to * center of zoom level 0.<br> * Suggestion: Check getIntrinsicScreenRect(null).getHeight() &gt; 0 */ public void zoomToBoundingBox(final BoundingBox boundingBox, final boolean animated) { zoomToBoundingBox(boundingBox, animated, 0); }

Fetching and Displaying Overlays
Upon receiving a list of ground overlays from an API call, I process them as follows:
LaunchedEffect(mapOrthomosaicData) { updateOrthomosaicOverlays( mapOrthomosaicData, mapOrthomosaicOverlays, overlayManagerState, mapViewViewModel, ) }

I add these ground overlays to the overlayManager and subsequently invalidate the map to refresh the display:
`fun updateOrthomosaicOverlays(
orthomosaicData: List,
overlays: Map<Int, Overlay>,
overlayManagerState: OverlayManagerState,
mapViewViewModel: MapViewEasyScanViewModel,
) {
val currentOverlays = overlays.keys.toSet()

// Add new overlays
for (ortho in orthomosaicData) {
    if (ortho.id in currentOverlays) continue
    val groundOverlay = GroundOverlay().apply {
        setPosition(
            ortho.corners["topLeft"],
            ortho.corners["topRight"],
            ortho.corners["bottomRight"],
            ortho.corners["bottomLeft"],
        )
        image = ortho.image
    }
    overlayManagerState.overlayManager.add(0, groundOverlay)
    mapViewViewModel.addOrthomosaicOverlay(ortho, groundOverlay)
}
// Remove overlays that are no longer in the data
for (overlay in currentOverlays) {
    if (orthomosaicData.find { it.id == overlay } != null) continue
    overlayManagerState.overlayManager.remove(overlays[overlay])
    mapViewViewModel.removeOrthomosaicOverlay(overlay)
}
overlayManagerState.getMap().invalidate()

}`

Issue
After calling invalidate(), some ground overlays appear to float above the map. This does not happen when manually moving the map with touch; it only occurs when overlays are programmatically updated and the map is invalidated. Temporarily fixing the issue requires a slight zoom adjustment by the user or programmatically, which results in a brief incorrect display of the overlays before correcting itself.

Does anyone have any insights into this issue?

Environment

If it's a bug, version(s) of android this affects:

All

Version of osmdroid the issue relates to:

osmdroidAndroid = "6.1.18"

Zoom in my bounding box waiting that my ground being download :
Capture d’écran 2024-04-05 à 16 32 11

Problem with one ground overlay:
Capture d’écran 2024-04-05 à 16 32 03

Good placement :
Capture d’écran 2024-04-05 à 16 32 35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant