Skip to content
Mike Dunn edited this page Oct 1, 2016 · 11 revisions
I'm using large Paths and am getting crashes or ANRs
EDIT: TileView now supports custom path drawing implementation. Just extend DrawablePath and pass those instances to TileView.drawPath. The built-in path drawing mechanism uses Canvas.drawPath, which is notably inefficient. Each path is tested with .quickReject before it's drawn, but that's about it. Canvas.drawLines is much more efficient, but looks poor with Paint more complex than a single pixel. If you need larger paths, consider writing your own implementation (with Canvas.drawLines, or a custom bitmap), and adding it to the View tree of the TileView. You can listen for scale changes and react appropriate in whatever fashion makes the most sense for you implementation.
Tiles aren't being rendered
This is probably due to a caught out-of-memory exception... the notorious "bitmap exceeds vm budget". These are caught (and discarded) in the default implementation but you're free free to provide your own. In general, it's very unlikely you'll have a tile missing if you've got a well-considered setup. The widget only displays the tiles that are visible. If you're missing some, make sure you're using enough tile sets: a tile set that scales down a lot will need to render lots of small tiles, but each will take up as much memory as it would at full size. If you're seeing lots of small tiles, then you should probably add another tile set at half the size. You can also try smaller individual tiles (256 is default, but any size is supported - try 128).
When the device sleeps, I get a crash or ANR when waking.
Make sure your call TileView.clear() in your Activity's onPause method, and TileView.resume() in the Activity's onResume.
When I use slideToAndCenter or moveToAndCenter, it doesn't center...
Both the centering methods use the dimensions of the View to figure out where center should be. This is not available during onCreate (or similar methods); height and width will be returned as 0, so no offset will be applied. This is not a TileView limitation, it how the Android framework layout mechanism is ordered. For most devices, you can just .post() a Runnable in onCreate to do what you want - (again, in *most* devices) this Runnable won't run() until layout's done. For devices that don't respect this, AFAIK there's no "clean" way to get around it - you can count layout passes and compare it getChildCount in onLayout, but that's clunky at best.
How do I maintain the center point while setting scale?
This is now available in the convenience method TileView.setScaleFromCenter
How do I get relative coordinates (e.g., latitude and longitude) from a pixel value like a touch event?
TileView now provides convenience methods to reverse translation on the CoordinateTranslater object:
public double translateAbsoluteToRelativeX( int x );
public double translateAbsoluteToRelativeY( int y );
public double translateAndScaleAbsoluteToRelativeX( int x, float scale );
public double translateAndScaleAbsoluteToRelativeY( int y, float scale );

Touch events are relative to the edge of the screen, so remember to add getScrollX/Y to the x or y parameter, e.g.,

double longitude = tileView.getCoordinateTranslater().translateAndScaleAbsoluteToRelativeX( tileView.getScrollX() + event.getX(), tileView.getScale() );
Clone this wiki locally