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

MarkerView is not removed from the MapView #27

Closed
sana-20 opened this issue Aug 12, 2021 · 5 comments
Closed

MarkerView is not removed from the MapView #27

sana-20 opened this issue Aug 12, 2021 · 5 comments

Comments

@sana-20
Copy link

sana-20 commented Aug 12, 2021

Hi Peter.

I added a custom marker with an animation but it is not removed from the mapview.

class AnimMarker(context: Context) :  AppCompatImageView(context)

This method is called when the grey star button is clicked.

    private var animMarker : AnimMarker? = null

    private fun addAnimMarker(){
        animMarker = AnimMarker(requireContext()).apply{
            setImageResource(R.drawable.ic_twotone_lens_24)
            val anim = AlphaAnimation(0.0f, 1.0f)
            anim.duration = 1000
            anim.repeatCount = Animation.INFINITE
            anim.repeatMode = Animation.REVERSE
            this.startAnimation(anim)
        }

        mapView.addMarker(animMarker!!, 4096.0, 4096.0)
    }

This method is called when the yellow star button clicked again.

    private fun removeAnimMarker() {
        mapView.removeView(animMarker)
    }

Do you have any clue to solve this?

sample.mp4
@p-lr
Copy link
Owner

p-lr commented Aug 12, 2021

Hi,

You should use MapView.removeMarker(marker) api, not removeView:

private fun removeAnimMarker() {
    mapView.removeMarker(animMarker)
}

@sana-20
Copy link
Author

sana-20 commented Aug 13, 2021

Hi @peterLaurence.

It does not work though I changed the code as you answered.
Not only does the marker still remain, but it is not anchored in the center position that I set. (4096, 4096)
It moved whenever the map's zoom level or camera position changed.

sample2.mp4

@p-lr
Copy link
Owner

p-lr commented Aug 13, 2021

Hi @sana-20 ,

I can't reproduce your issue. I've updated the demo of MapView to showcase how to remove a marker. Inside the "Map and Markers demo", you'll see a red circular marker which you can remove/add using the button at the bottom.
See the code is in MapMarkersFragment of the demo.

I suggest that you make a github repo reproducing your issue.

@sana-20
Copy link
Author

sana-20 commented Aug 13, 2021

Hi @peterLaurence,

I really appreciate your help.
Adding and removing a marker works perfectly without an animation.
But the tricky part is when I added an animation to a marker.
Even though I clicked a remove button, it does not disappear.
It looks like gone at glance, but when you changed the zoom level, you can see a marker still remaining.

See the code here.

@p-lr
Copy link
Owner

p-lr commented Aug 13, 2021

Indeed, with an animation set, I could reproduce.
I managed to solve the issue by invoking clearAnimation() on the marker right before removing it. So for your use case:

private fun removeAnimMarker() {
    animMarker?.clearAnimation()
    mapView.removeMarker(animMarker)
}

You can use this fix in the meantime. I'll add clearAnimation in the MapView.removeMarker api.

@p-lr p-lr closed this as completed Oct 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants