针对ItemizedOverlay <overlayitem> </overlayitem>的Android Map低性能

时间:2012-09-03 18:16:31

标签: android performance

我有

 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);
    }        

}

我需要加载大约10万个点。

我还有另一个会创建多边形(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上加载第二个叠加。

如何加快申请速度?

1 个答案:

答案 0 :(得分:1)

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

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