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

No tiles visible, ability to center? #24

Closed
timhughes89 opened this issue Mar 19, 2021 · 1 comment
Closed

No tiles visible, ability to center? #24

timhughes89 opened this issue Mar 19, 2021 · 1 comment

Comments

@timhughes89
Copy link

timhughes89 commented Mar 19, 2021

Hi,

I was reading one of your other threads and you mentioned the ability to centre the maps after the config - any chance you could share how to do this please?

Also when loading have to zoom for scroll to start becoming visible?

Here's my config setup

`
val tileSize = 256
val config = MapViewConfiguration(
levelCount = map.levelCount,
fullWidth = map.fullWidth,
fullHeight = map.fullHeight,
tileSize = tileSize,
tileStreamProvider = tileStreamProvider
).apply {
setMaxScale(2f)
setMinimumScaleMode(MinimumScaleMode.FILL)
setPadding(12800)
}

    binding.mapview.configure(config)
    binding.mapview.defineBounds(0.0, 0.0, 1.0, 1.0)

    Timer().schedule(object : TimerTask() {
        override fun run() {
            if (binding.mapview.width != 0 && binding.mapview.height != 0) {
                this.cancel()
                binding.mapview.scrollTo( binding.mapview.width / 2, binding.mapview.height / 2)
            }
        }
    }, 1, 5)`
@p-lr
Copy link
Owner

p-lr commented Mar 20, 2021

Hi,

The MapView configuration should be done inside onCreateView(). You can find examples in the demo package. Like this one.
That should solve the tile visibility issue. Although I also suspect your padding setting to have something to do with that. Usually, the padding is a multiple of tileSize (like one or two). The padding is the number in pixels which is virtually added to the visible part on the screen to compute the tiles that should be fetched. A huge padding like that will trigger way too much tiles to be loaded and cause memory strain on your device.

As for centering, you can do the following in onStart():

post {
   if (binding.mapview.width != 0 && binding.mapview.height != 0) {
          this.cancel()
          binding.mapview.scrollToAndCenter( binding.mapview.width / 2, binding.mapview.height / 2)
   }
}

I also replaced scrollTo with scrollToAndCenter().

@p-lr p-lr closed this as completed Mar 29, 2021
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

2 participants