【问题标题】:Android Map low performance for ItemizedOverlay<OverlayItem>ItemizedOverlay<OverlayItem> 的 Android 地图性能低下
【发布时间】:2012-09-03 18:16:31
【问题描述】:

我有

 public class MyItemsOverlay extends ItemizedOverlay<OverlayItem>{
private List<OverlayItem> items=new ArrayList<OverlayItem>();
private Drawable marker=null;   
private StatusData data;    
private MapView mapView;
 private PopupPanel panel;

public MyItemsOverlay (Drawable defaultMarker, View view, LayoutInflater getLayoutInflater) {       
    super(defaultMarker);
      this.marker=defaultMarker;               
      mapView=(MapView) view.findViewById(R.id.mapview);
      panel=new PopupPanel(R.layout.details_popup,getLayoutInflater, mapView);
      data=new StatusData (mapView.getContext());
      items=  protectedZoneData.GetItems();  

      populate();
}

 @Override
    protected OverlayItem createItem(int i) {
      return(items.get(i));
    }


  @Override
    public int size() {
      return(items.size());
    }

  @Override
    protected boolean onTap(int i) {

      OverlayItem item=getItem(i);
      GeoPoint geo=item.getPoint();       

      View view=panel.getView();

      ((TextView)view.findViewById(R.id.latitude))
        .setText(String.valueOf(geo.getLatitudeE6()/1000000.0));
      ((TextView)view.findViewById(R.id.longitude))
        .setText(String.valueOf(geo.getLongitudeE6()/1000000.0));
      ((TextView)view.findViewById(R.id.Name))
                              .setText(item.getTitle());
      ((TextView)view.findViewById(R.id.Description))
                              .setText(item.getSnippet());

      panel.show();
      hidePopup();
      return(true);
    }        

}

我需要加载大约 100 000 个点。

我还有另一个叠加层可以创建多边形(100 000 个多边形)

public class MyPolygonOverlay  extends Overlay{

private StatusData data; 

private Projection projection;
ArrayList<ArrayList<GeoPoint>> geArrayList;

public MyPolygonOverlay(Context context, MapView mapView)
{
    data=new StatusData(context);

    projection=mapView.getProjection();
    geArrayList=data.GetPoyigonGeoPoints();


}

public void draw(Canvas canvas, MapView mapView, boolean shadow){
    super.draw(canvas, mapView, shadow);



    for (int i = 0; i < geArrayList.size(); i++) {
         Path path = new Path();
         ArrayList<GeoPoint> geoPoints=geArrayList.get(i);
         for (int j = 0; j <geoPoints.size(); j++) {

               GeoPoint gP1 =geoPoints.get(j);
               Point currentScreenPoint = new Point();

                Projection projection = mapView.getProjection();
                projection.toPixels(gP1, currentScreenPoint);

                if (j == 0){
                  path.moveTo(currentScreenPoint.x, currentScreenPoint.y);                    

                }                  
                else
                {
                  path.lineTo(currentScreenPoint.x, currentScreenPoint.y);
                }
            }
           canvas.drawPath(path, GetPaint());

}
}

在缩放级别 5 上加载第一个叠加层,然后在缩放 8 上加载第二个叠加层。

如何加快我的申请速度?

【问题讨论】:

    标签: android performance


    【解决方案1】:

    在一个位图上绘制叠加层并使用该位图代替重绘每个多边形。

    您只需要根据缩放级别计算位图的缩放比例。

    【讨论】:

    • 嗨,我是安卓新手。你有我的例子吗?
    • 基本上你只需要在位图上绘制并存储它。阅读一些关于它的教程或尝试一下:stackoverflow.com/questions/4160149/… 你只需要创建一个位图,并且绘图应该是相同的......
    • 但是位图会吃掉我的记忆?
    • 性能主要伴随着内存成本。但是一两个位图不应该对您的内存消耗产生如此巨大的影响。基本上这是你唯一的选择(除了减少点数......)
    猜你喜欢
    • 1970-01-01
    • 2010-09-06
    • 2011-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-15
    • 2011-11-03
    • 2019-08-16
    相关资源
    最近更新 更多