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

ZoomIn/ZoomOut/Rotate programmatically with animation #15

Closed c0dd3vi11 closed 4 years ago

c0dd3vi11 commented 4 years ago

Hello, @peterLaurence! I got one more problem.

I was trying to make buttons to zoom in/out and rotate back to north-up position.

Zooming in/out. I found this: mapView.smoothScaleFromCenter(mapView.scale * 1.5f). And the opposite is mapView.smoothScaleFromCenter(mapView.scale / 1.5f). But when I call the functions too fast then MapView starts blinking.

Rotating. The best way is do mapView.setAngle(referentialData.angle). But this performs without animation. Could you help me how to do it proper with animation?

p.s. Perfect SDK, btw) Thank you for making it!

p-lr commented 4 years ago

Hi,

I'll create another issue for zoom-in/out. About rotating, you can use your own animator, like so:

private fun animateMapViewToNorth() {
        /* Wrapper class, necessary for the the animator to work (which uses reflection to infer
         * method names..) */
        @Suppress("unused")
        val wrapper = object {
            fun setAngle(angle: Float) {
                mapView?.setAngle(angle)
            }

            fun getAngle(): Float {
                return referentialData.angle
            }
        }
        ObjectAnimator.ofFloat(wrapper, "angle", 0f).apply {
            interpolator = DecelerateInterpolator()
            duration = 800
            start()
        }
    }
c0dd3vi11 commented 4 years ago

Thank you! I tried animateMapViewToNorth and it works very well!

c0dd3vi11 commented 4 years ago

Also about zoom-in/out. I've just found the mistake... I did the same calculation on referentialData.scale (data.scale = 1.5f) before I was calling `mapView.smoothScaleFromCenter(mapView.scale 1.5f)`. So, after I removed all started working well too!

Sorry for misleading you 🤗