Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Map padding not working properly after sdk update #282

Open
zsoltbakos opened this issue Mar 17, 2020 · 10 comments
Open

Map padding not working properly after sdk update #282

zsoltbakos opened this issue Mar 17, 2020 · 10 comments
Labels

Comments

@zsoltbakos
Copy link

Hi all,

I recently upgraded the sdk in my app from version 7.3.2 to 9.0.1.
In the previous version, I set padding with mapboxMap.setPadding(leftPadding, topPadding, 0, 0). With that, I managed to display my current location in the bottom of the screen, so the upper part of the map is still visible. It is a required feature of the app as it is used by drivers who want to see the upcoming part of their trip. (Image 1)

In the newer version, mapboxMap.setPadding() is deprecated and completely unusable. Padding is not working, when I navigate to my position, it is shown in the center of the screen (Image 2). I found in the docs that it's recommended to use either CameraUpdateFactory.paddingTo() with mapboxMap.moveCamera(), or CameraUpdate.Builder#padding(). The former is simply not working; when I try to navigate to a location, it does nothing. The latter is almost perfect, with the only problem being that it makes the whole map extremely laggy.

Is it a bug in the sdk which will be fixed, or is there any other way for setting the padding of the map?

Image 1 - how it worked in the old version, and should work
mapbox1

Image 2 - how it works in new version, without touching the code
mapbox2

@chloekraw
Copy link
Contributor

@zsoltbakos thanks for all of the detail. We did make an adjustment to the way that padding works, but it should be backwards compatible in that there is a way to achieve the same result as before. Take a look at mapbox/mapbox-gl-native#15444 and see if that helps you update your implementation. cc @LukasPaczos

@LukasPaczos
Copy link

Thanks for reporting the issue @zsoltbakos. There might also be an issue with the order of the calls - to keep backward compatibility, the LocationComponent will internally call the deprecated MapboxMap#setPadding based on the LocationComponentOptions#padding. This can overwrite your value, so I'd recommend activating the component first and only then setting the padding, or provide the padding in the component's options initially.

@zsoltbakos
Copy link
Author

@chloekraw & @LukasPaczos thanks for the tips. I don't use Mapbox's LocationComponent, so maybe that's one way to solve this issue. I'll try it out at the weekend and make a feedback about the result.

@zsoltbakos
Copy link
Author

Sorry for the late reply. Unfortunately, using a locationComponent does not solve my problem. When I set the padding within LocationComponentOptions (which is deprecated), it does simply not work - just like setting it in the mapView's setting. This is how I tried:

            map.locationComponent.activateLocationComponent(
                    LocationComponentActivationOptions
                            .builder(context!!, style!!)
                            .locationEngine(ObuLocationEngine(this))
                            .locationComponentOptions(
                                    LocationComponentOptions
                                            .builder(context!!)
                                            .backgroundTintColor(R.color.transparent)
                                            .foregroundTintColor(R.color.transparent)
                                            .foregroundDrawable(R.drawable.marker_current_position)
                                            .padding(intArrayOf(leftPadding.toInt(), topPadding.toInt(), 0, 0))
                                            .build()
                            )
                            .build()
            )

If I use LocationComponent, and set the padding with a cameraUpdate, it is still very laggy:

        val cameraPosition = CameraPosition.Builder()
                .target(latLng)
                .zoom(map.cameraPosition.zoom.coerceIn(minZoom, maxZoom))
                .tilt(60.0)
                .bearing(bearing)
                .padding(leftPadding, topPadding, 0.0, 0.0)
                .build()
        map.easeCamera(CameraUpdateFactory.newCameraPosition(cameraPosition))

@philemonmerlet
Copy link

@zsoltbakos Did you find a workaround for this issue ? I have the same problem, see #162 . Currently all I can do to avoid the lag is modifying the source transform.cpp to limit the tilt when there is padding, but there are other issues (the zoom level is not the same)...

@zsoltbakos
Copy link
Author

@philemonmerlet No, so I'm still using the old version of the sdk. 😞

@philemonmerlet
Copy link

After playing with the new maxPitchPreference (from MapboxMap or MapboxMapOptions), setting it to 45 instead of 60 seems to restore the correct behavior (no more lag when using padding, and the actual visible pitch is close to before, only a bit more far away). Maybe it can work for your case, it looks similar.

@zsoltbakos
Copy link
Author

Thanks, it seems to fix the issue.

@ulusoyca
Copy link

ulusoyca commented Jun 3, 2020

I think this issue should not be closed. It is still valid. I am using the version 9.2.0 and padding has no effect when I use map.moveCamera(CameraUpdateFactory.paddingTo(...) @LukasPaczos

@zsoltbakos
Copy link
Author

The workaround explained by @philemonmerlet fixed the issue for me, but if you think it is still a bug and the above solution is not working for you, then I reopen it.

@zsoltbakos zsoltbakos reopened this Jun 5, 2020
@stale stale bot added the archived label Dec 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants