p-lr / MapView

A Fast, memory efficient Android library to display tiled maps, with support for markers, paths, and rotation.
Apache License 2.0
184 stars 38 forks source link

Turn off fade anination on tiles #17

Closed c0dd3vi11 closed 4 years ago

c0dd3vi11 commented 4 years ago

Hi, @peterLaurence, again)

I found that TileCanvasView that performs that animation is internal. Could you recommend the best way to manage how tiles appear or how to remove the animation at all?

p-lr commented 4 years ago

It could be simple - I admit, but in the meantime this is how to do it: There's a TileOptionsProvider that you can assign to the MapView using MapViewConfiguration.setTileOptionsProvider

interface TileOptionsProvider {
    /* Must not be a blocking call - should return immediately */
    @JvmDefault
    fun getColorFilter(row: Int, col: Int, zoomLvl: Int): ColorFilter? = null

    /**
     * Controls the speed of fade in effect when rendering tiles. Higher values make alpha
     * value go to 255 faster. Should be in between (0.0f, 1.0f].
     */
    @JvmDefault
    val alphaTick : Float
        get() = 0.07f
}

You just have to provide an implementation which returns 255f as alphaTick

p-lr commented 4 years ago

You do not have to override getColorFilter method.

p-lr commented 4 years ago

To summarize all this, here's an example:

val tileOptionsProvider = object : TileOptionsProvider {
      override val alphaTick: Float
           get() = 255f
}

val config = MapViewConfiguration(
    5, 8192, 8192, tileSize, tileStreamProvider)
.setMaxScale(2f).setTileOptionsProvider(tileOptionsProvider)

You might have to add this to your android{} section of your build.gradle:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
    jvmTarget = JavaVersion.VERSION_1_8
    freeCompilerArgs = ['-Xjvm-default=compatibility']
}
c0dd3vi11 commented 4 years ago

Thank you for fast replying)

I tried the method and noticed, that 2.0.5 version didn't contain alphaTick method to override it. I applied the lib via gradle implementation 'com.peterlaurence:mapview:2.0.5' and don't know how to fetch the very recent implementation. Could you help me, please?

p-lr commented 4 years ago

Oh my bad.. didn't see that it wasn't released yet. Wait a sec, I'm releasing 2.0.6.

p-lr commented 4 years ago

@c0dd3vi11 2.0.6 is released!

c0dd3vi11 commented 4 years ago

Thank you a lot! ^_^