How to capture the end of Zoom In / Out animation from MapController?

Just an interesting request here, is there any way to capture when the zoom animation sequence ended when called:

MapController.zoomIn() or MapController.zoomOut(); 

I know that it starts the animation sequence to increase / decrease to the next level, however it is not known how I can find / google search, etc. to find out when it will finish this sequence. I need to be able to run the update command when it is stopped, so my map is updated correctly.

I found that by running the update command after calling the above function, Projection is not at the reduction level, but somewhere in between (therefore, I cannot show all the data I need).

+4
source share
1 answer

I have to admit that I swore here, this is a hack, but it works fine. I started with the need to know when the scale occurred, and as soon as I connected to it (and after some interesting debugging), I found that some of the values โ€‹โ€‹were โ€œbetween the scaling valuesโ€, so I had to wait until the scale was completed.

As suggested elsewhere in Stack Overflow, my zoom viewer is an overridden MapView.dispatchDraw that checks if the zoom level has changed the last time.

In addition to this, I added the isResizing method, which checks if the timestamp is more than 100 ms, since the getLongitudeSpan value has stopped changing. It works great. Here is the code:

My first post! Whoo Hoo!

Public class MapViewWithZoomListener extends MapView {

 private int oldZoomLevel = -1; private List<OnClickListener> listeners = new ArrayList<OnClickListener>(); private long resizingLongitudeSpan = getLongitudeSpan(); private long resizingTime = new Date().getTime(); public MapViewWithZoomListener(Context context, String s) { super(context, s); } public MapViewWithZoomListener(Context context, AttributeSet attributeSet) { super(context, attributeSet); } public MapViewWithZoomListener(Context context, AttributeSet attributeSet, int i) { super(context, attributeSet, i); } public boolean isResizing() { // done resizing if 100ms has elapsed without a change in getLongitudeSpan return (new Date().getTime() - resizingTime < 100); } public void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); if (getZoomLevel() != oldZoomLevel) { new AsyncTask() { @Override protected Object doInBackground(Object... objects) { try { if (getLongitudeSpan() != resizingLongitudeSpan) { resizingLongitudeSpan = getLongitudeSpan(); resizingTime = new Date().getTime(); } Thread.sleep(125); //slightly larger than isMoving threshold } catch (InterruptedException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(Object o) { super.onPostExecute(o); if (!isResizing() && oldZoomLevel != getZoomLevel()) { oldZoomLevel = getZoomLevel(); invalidate(); for (OnClickListener listener : listeners) { listener.onClick(null); } } } }.execute(); } } public void addZoomListener(OnClickListener listener) { listeners.add(listener); } 
+1
source

Source: https://habr.com/ru/post/1337418/


All Articles