moagrius / TileView

TileView is a subclass of android.view.ViewGroup that asynchronously displays, pans and zooms tile-based images. Plugins are available for features like markers, hotspots, and path drawing.
MIT License
1.46k stars 336 forks source link

Tiles outside the image are created #531

Open inneke-dc opened 5 years ago

inneke-dc commented 5 years ago

I've noticed that sometimes a row or column is set on a tile that is outside of the image's bounds. This originates from TileView.computeAndRenderTilesInViewport(): the grid is too large. This affects the Tile.mDestinationRect. Later in Tile.decode(), this same row and column is used to render a tile with mStreamProvider.getStream(). Is there a reason why these non-existing tiles are rendered?

The problem that I'm experiencing is that in my project the tiles are loaded with http requests, and our client's server returns white tiles for invalid coordinates. True, this is just a bad design and the server should return an error or empty stream, but maybe other people have issues with this as well.

Thank you for maintaining this library the way you do and always being quick to answer, I appreciate it.

tva-TIS commented 5 years ago

Is it possible that this is linked to the problem I described in https://github.com/moagrius/TileView/issues/530 ?

inneke-dc commented 5 years ago

It seems to be the same problem, yes. It's happening when the image does not completely fill the TileView. In that case, additional rows are requested at the bottom to completely fill the view (the top is fine - my image is centered). However, the images I'm using have a larger full scale resolution than the container. You seemed to only have issues with very small images.

moagrius commented 5 years ago

with open source projects like this where i have very little time, if you can find or identify the specific issue (in this case, i think the suggestion is that there's something wrong with how the grid is calculated), that'd certainly help me get it fixed, considering the very limited amount of time i have to work on issues. if not, i'll give it a shot next time i can; probably a month or so. sorry for the hassle.

tva-TIS commented 5 years ago

with open source projects like this where i have very little time, if you can find or identify the specific issue (in this case, i think the suggestion is that there's something wrong with how the grid is calculated), that'd certainly help me get it fixed, considering the very limited amount of time i have to work on issues. if not, i'll give it a shot next time i can; probably a month or so. sorry for the hassle.

Might have some time to look into it myself. Just to be sure: @inneke-dc you are using version 4.0.7 too, right?

inneke-dc commented 5 years ago

I think I got it but I'm not sure if it will cover all cases. It seemed to fix it for me in a layout where the image is centered in the TileView and where the scaling starts at a 'fitCenter' state:

tileView.setMinimumScaleMode(ScalingScrollView.MinimumScaleMode.CONTAIN) tileView.setScaleLimits(0f, 2f)

When changing the TileView.updateViewport() from

mViewport.right = mViewport.left + getMeasuredWidth(); mViewport.bottom = mViewport.top + getMeasuredHeight();

to

mViewport.right = mViewport.left + Math.min(getMeasuredWidth(), getScaledWidth()); mViewport.bottom = mViewport.top + Math.min(getMeasuredHeight(), getScaledHeight());

just the right amount of rows and columns are created.

I do not know what else will be affected by this however.

inneke-dc commented 5 years ago

with open source projects like this where i have very little time, if you can find or identify the specific issue (in this case, i think the suggestion is that there's something wrong with how the grid is calculated), that'd certainly help me get it fixed, considering the very limited amount of time i have to work on issues. if not, i'll give it a shot next time i can; probably a month or so. sorry for the hassle.

Might have some time to look into it myself. Just to be sure: @inneke-dc you are using version 4.0.7 too, right?

Yes, I'm using the most recent code.

tva-TIS commented 5 years ago

mViewport.right = mViewport.left + Math.min(getMeasuredWidth(), getScaledWidth()); mViewport.bottom = mViewport.top + Math.min(getMeasuredHeight(), getScaledHeight());

Tested this with my project too. Solves the issue for small images too.

moagrius commented 5 years ago

This is awesome! Thanks so much for digging in. I may need to make some minor tweaks but this looks very promising - I'll try to get his verified (and committed, hopefully) as soon as I get some time (I'll shoot for Mon-Tues of next week - gone all weekend).

Thanks again! Nice open source-ery ;)