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

rectangular tiles #28

Open
crypto-sh opened this issue Aug 18, 2021 · 2 comments
Open

rectangular tiles #28

crypto-sh opened this issue Aug 18, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@crypto-sh
Copy link

supporting rectangular tiles just like the previous library (TileView).

@p-lr
Copy link
Owner

p-lr commented Aug 18, 2021

Ah.. I was hoping never to see that feature request. Alright. It certainly isn't a difficult thing to do - however a significant part of the code base would be impacted.

@p-lr p-lr added the enhancement New feature or request label Aug 18, 2021
@devjta
Copy link

devjta commented Sep 12, 2024

@crypto-sh @p-lr that was actually quite easy.

In the non-compose one, its in TileCanvasView.kt and in drawTiles, which i already needed to change, because of our tiles having 1 pixel more on each side (so 258x258, while calucation tileSize is 256).

`

        val tileScaled = (tileSize / scaleForLevel).toInt()

        val imgMultiplier = (tileScaled / 256) //if zoomed out, it could be more than 256

        val l = tile.col * tileScaled

        val t = tile.row * tileScaled

        val r = l + tileScaled.coerceAtMost(tile.bitmap.width * imgMultiplier)

        val b = t + tileScaled.coerceAtMost(tile.bitmap.height * imgMultiplier)

        source.set(0, 0, tileScaled.coerceAtMost(tile.bitmap.width.coerceAtMost(256)),

            tileScaled.coerceAtMost(tile.bitmap.height.coerceAtMost(256)))

        dest.set(l, t, r, b)
        //...
       canvas.drawBitmap(tile.bitmap, source, dest, paint)`

In the compose one, its in TileCanvas. Still testing around, but it looks quite good.

The tile.bitmap.width.coerceAtMost(256) is needed, because our tiles can be bigger than 256. But it should never pick them for the source.

So important was, to reduce the destination rectangle. Not sure if source is needed.

Edit: Why is it so damn hard to post code here..

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

No branches or pull requests

4 participants
@devjta @p-lr @crypto-sh and others