添加到许多注释后,GLSurfaceView(SKMapSurfaceView)会冻结

时间:2016-08-15 10:44:05

标签: android glsurfaceview skmaps

即时通讯使用Skobbler地图框架,我在地图上渲染注释时遇到问题。这个SKMapSurfaceView类扩展了GLSurfaceView并使用渲染模式RENDER_WHEN_DIRTY进行渲染。此类提供方法addAnnotation(),它向地图添加注释。在反编译他们的代码之后我发现了这个:

public void addAnnotation(final SKAnnotation var1, final SKAnimationSettings var2) {
    if(var1 != null) {
        SKLogging.writeLog("SKMapSurfaceView", " Add annotation using ID =  " + var1.getUniqueID(), 0);
        this.deleteAnnotation(var1.getUniqueID());
        if(var1.getAnnotationView() != null && var1.getAnnotationView().getView() != null) {
            SKLogging.writeLog("SKMapSurfaceView", "@addAnnotationFromView ", 0);
            final SKCoordinate var4;
            if((var4 = var1.getLocation()) != null) {
                final SKAnnotationView var5 = var1.getAnnotationView();
                if(this.getContext() instanceof Activity && var5 != null) {
                    ((Activity)this.getContext()).runOnUiThread(new Runnable() {
                        public void run() {
                            View var1x;
                            if((var1x = var5.getView()) != null) {
                                if(var1x.getMeasuredWidth() == 0 || var1x.getMeasuredHeight() == 0) {
                                    LayoutParams var2x = new LayoutParams(-2, -2);
                                    var1x.setLayoutParams(var2x);
                                    var1x.measure(0, 0);
                                }

                                final int var6 = var1x.getMeasuredWidth();
                                final int var3 = var1x.getMeasuredHeight();
                                SKMapSurfaceView var10000 = SKMapSurfaceView.this;
                                final int var4x = SKMapSurfaceView.b(var6, var3);
                                final Bitmap var5x = SKMapSurfaceView.b(var1x);
                                SKMapSurfaceView.this.queueEvent(new Runnable() {
                                    public void run() {
                                        int var1x = (int)((float)(this.a / 2) + var1.getOffset().getX());
                                        int var2x = (int)((float)(this.a / 2) + var1.getOffset().getY());
                                        SKLogging.writeLog("SKMapSurfaceView", "@addAnnotationFromView properSize=" + this.a + " centerX=" + var1x + " centerY=" + var2x, 0);
                                        String var3 = var5.getReuseIdentifierWithId();
                                        Bitmap var4x = this.b;
                                        if(SKMapSurfaceView.this.o.get(var3) == null) {
                                            SKLogging.writeLog("SKMapSurfaceView", "Bitmap DOESN\'T EXIST " + this.a + " " + this.c + " " + this.d, 0);
                                            if(var3 != null) {
                                                SKMapSurfaceView.this.o.put(var3, this.b);
                                            }
                                        } else {
                                            SKLogging.writeLog("SKMapSurfaceView", "Bitmap  EXISTS ", 0);
                                            var4x = (Bitmap)SKMapSurfaceView.this.o.get(var3);
                                        }

                                        SKMapSurfaceView var10000 = SKMapSurfaceView.this;
                                        Bitmap var5x = SKMapSurfaceView.b(var4x, this.a);
                                        if(SKMapSurfaceView.this.a.addgpsuserpoifromarray(var1.getUniqueID(), SKMapSurfaceView.a(var5x), var4.getLongitude(), var4.getLatitude(), 5, this.a, this.a, var1x, var2x, var1.getMininumZoomLevel(), 0, var2.getAnimationType().getValue(), var2.getAnimationEasingType().getValue(), var2.getDuration())) {
                                            SKMapSurfaceView.a(SKMapSurfaceView.this, var1);
                                        }

                                    }
                                });
                            }

                        }
                    });
                }
            }
        } else {
            SKLogging.writeLog("SKMapSurfaceView", "addAnnotationWithTextureId  ", 0);
            this.queueEvent(new Runnable() {
                public void run() {
                    SKCoordinate var1;
                    if((var1 = this.a.getLocation()) != null) {
                        double[] var2;
                        if((var2 = this.c.a.gpstomercator(var1.getLongitude(), var1.getLatitude())) != null) {
                            this.c.a.addcustomiconext(this.a.getUniqueID(), var2[0], var2[1], this.a.getAnnotationType(), this.b.getAnimationType().getValue(), this.b.getAnimationEasingType().getValue(), this.b.getDuration());
                        }

                        SKMapSurfaceView.a(this.c, this.a);
                    } else {
                        SKLogging.writeLog("SKMapSurfaceView", "@addAnnotationWithTextureId - Please set provide a location for the annotation to be added ", 1);
                    }
                }
            });
        }

        this.requestRender();
    }

}

它创建了2个新的runnable。第一个是在ui线程上运行的,我从ui线程调用该方法,所以这应该同步完成。第二个runnable使用GLSurfaceView.queueEvent()排队,然后调用requestRender()。

我的问题是,如果我要在循环中添加多个注释:

for (SKAnnotation annotation : myListOfAnnotations){
    skMapSurfaceView.addAnnotation(annotation);
}

如果myListOfAnnotations有大约50个项目(在较慢的设备上可以减少),地图会冻结,直到所有注释都被渲染。

这会导致冻结的原因是什么?对于在GL中排队的许多事件,还是在很短的时间内多次调用requestRender,或者我在这里做些什么?我怎样才能防止这种情况发生?有没有办法计算排队事件?或者某些方法在添加所有注释后停止渲染并渲染它?

提前感谢您的任何帮助或建议。

0 个答案:

没有答案