如何从 MapController 捕获放大/缩小动画的结尾?

发布于 2024-10-14 16:37:47 字数 282 浏览 0 评论 0原文

这里只是一个有趣的查询,有没有一种方法可以在调用时捕获缩放动画序列何时结束:

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

我知道它确实会启动动画序列以放大/缩小到下一个级别,但是我没有已知的方法可以查找/谷歌搜索等来找出它何时完成该序列。我需要能够在停止时运行更新命令,以便我的地图正确更新。

我发现通过在调用上述函数后运行更新命令,投影不是来自缩小级别,而是介于两者之间(因此我无法显示我需要的所有数据)。

Just an interesting query here, is there a way to capture when a zoom animation sequence has ended when calling either:

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

I know that it does kick off an animation sequence to zoom in/out to the next level, however there is no known way I can find/google search, etc to find out when it finishes that sequence. I need to be able to run an update command when that is stopped so my map updates correctly.

I've found that by running the update command after calling the above function the Projection isn't from the zoom out level but somewhere inbetween (so I can't show all the data I need).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余生再见 2024-10-21 16:37:47

我不得不承认我在这里下注了,这是一个黑客,但效果很好。我一开始需要知道缩放何时发生,一旦我陷入其中(经过一些有趣的调试),我发现一些值是“缩放之间”值,所以我需要等到缩放完成后。

正如 Stack Overflow 上其他地方所建议的,我的缩放侦听器是一个重写的 MapView.dispatchDraw,它检查缩放级别自上次以来是否已更改。

除此之外,我添加了一个 isResizing 方法,用于检查自 getLongitudeSpan 值停止更改以来时间戳是否超过 100 毫秒。效果很好。这是代码:

我的第一篇 Stack Overflow 帖子!呼呼!

公共类 MapViewWithZoomListener 扩展 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);
}

I have to admit I punted here, it's a hack but it works great. I started off with a need to know when a zoom occured, and once I hooked into that (and after some interesting debugging) I found some values were "between zoom" values, so I needed to wait till after the zoom was done.

As suggested elsewhere on Stack Overflow my zoom listener is an overridden MapView.dispatchDraw that checks to see if the zoom level has changed since last time.

Beyond that I added an isResizing method that checks if the timestamp is more than 100ms since the getLongitudeSpan value stopped changing. Works great. Here is the code:

My very first Stack Overflow 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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文