如果标记数量增加,应用速度慢

问题描述 投票:0回答:1

在带有osmDroid和osmBonusPack的OpenStreetMap地图上,我显示了标记,并单击它打开了一个气泡,一切正常,直到需要一定数量的标记。我在地图上放置的标记越多,应用程序的响应性就越差。例如,使用1000个标记,将需要6秒钟的时间显示“工具栏”菜单,而转移到另一个活动(例如简单的文本显示)则需要花费6秒钟。我的代码。

private void creationMarker(GeoPoint arg,
                            String titre,
                            String proximite,
                            String description,
                            String identifiant) {
    double doubleProximite;
    Marker startMarker = new Marker(map);
    startMarker.setPosition(arg);
    startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);

    InfoWindow infoWindow = new MyInfoWindow(R.layout.bonuspack_bubble_black, map);
    ((MyInfoWindow) infoWindow).setTitre(titre);
    ((MyInfoWindow) infoWindow).setDescription(description);
    ((MyInfoWindow) infoWindow).setSubDescription(identifiant);

    startMarker.setTitle(((MyInfoWindow) infoWindow).getTitre());
    startMarker.setTitle(((MyInfoWindow) infoWindow).getDescription());
    startMarker.setTitle(((MyInfoWindow) infoWindow).getSubDescription());
    startMarker.setIcon(getResources().getDrawable(R.drawable.croix_verte, null).mutate());
    startMarker.setInfoWindow(infoWindow);

    doubleProximite = Double.parseDouble(proximite);
    Polygon circle = new Polygon();
    circle.setPoints(Polygon.pointsAsCircle(arg, doubleProximite));

    int myColorZone, myColorCloture;
    myColorZone = this.getResources().getColor(R.color.SurfaceZoneActive, getTheme());
    circle.setFillColor(myColorZone);     // couleur avec arrière plan transparent
    myColorCloture = this.getResources().getColor(R.color.ClotureActive, getTheme());
    circle.setStrokeColor(myColorCloture);// couleur de la circonférence    
    circle.setStrokeWidth(3);            // épaisseur du trait

    map.getOverlays().add(circle);
    map.getOverlays().add(startMarker);

}

我将带有SQL数据库的循环用于标记数据。

我想标记越多,应用程序必须处理的事件就越多。什么解决方案可以解决我的问题。预先感谢您的回答

osmdroid
1个回答
0
投票

标记非常重,或者至少在一段时间前,我遇到了与您类似的性能问题。有可能对其进行优化,但这将意味着修改Osmdroid库并通过此类更改创建请求请求。

尝试进行一些分析,以确保问题不在代码中,而在库(https://developer.android.com/studio/profile/cpu-profiler.html)中。

请注意如何从数据库读取数据-不要在主线程上进行操作,并测量需要多长时间以确保它不是主要问题。

尝试使用Osmdrid的SimpleFastPointOverlay-应该针对更大数量的标记进行优化(尽管它们必须具有相同的图标)。即使它的灵活性不足以满足您的需求,也可以尝试验证Markers是真正的问题。之后,您可以查看源代码并将其用作实现自己的自定义叠加层的学习材料。

© www.soinside.com 2019 - 2024. All rights reserved.