Issue
I have a MapView that will contain alot of overlays. For this i've extended the Overlay class as i've heard it has better performance than ItemizedOverlay (that was calling populate for every element). When the map is moved or zoomed, in the MapActivity, I select only the visible drawables and I call:
protected void RefreshOverlay() {
Log.e("||||||||||||||||||||||||||", "RefrashOverlay()");
mapOverlays.clear();
mapOverlays.add(new OverlayElements(zonesP,getApplicationContext()));
}
The class OverlayElements extends Overlay and here i do all the drawings:
public void draw(Canvas canvas, MapView mapview, boolean shadow) {
super.draw(canvas, mapview, shadow);
int i;
int sz=zonesP.size();
int style;
ZoneProperties zone;
//paint.setAntiAlias(true);
pp = new Point();
int zoomLevelC=mapview.getZoomLevel();
Projection pr = mapview.getProjection();
for(i=0;i<sz;i++)
{
zone=zonesP.get(i);
if(zone.visible==true)
{
pr.toPixels(zone.point, pp);
xp = pp.x;
yp = pp.y;
if(zone.zoneSizePx<500)
{
//----------
Log.e("zone radious>>",zone.zoneSizePx+"<<");
int alfa;
style=(int)i%2;
Log.e("style>>",i+">>"+r[i]+" "+g[i]+" "+b[i]);
paint.setColor(Color.rgb(r[style],g[style],b[style]));
alfa=(18-zoomLevelC)*35;
if(alfa>255)
alfa = 200;
else
if(alfa<0) alfa = 20;
paint.setAlpha(alfa);
canvas.drawCircle(xp, yp, zone.zoneSizePx, paint);
}
if(zone.select!=0)
if(zone.vState==2)
canvas.drawBitmap(getDrawRes(zone.select,zone.eSizePx),xp,yp,null);
}
//----------------
}
}
Well, yeah this drawing isn't that fast :) . Should i go back ItemizedOverlay, and if so how can i make the populate call only once? Any optimization idea? Thank you!! :)
Solution
You do not call populate()
on an ItemizedOverlay
until all of the items are ready, not for each item.
when i have similar drawables on the Map, i call only once populate() but mostly i have different one
That does not matter.
How could i add a new drawable without creating a new ItemizedOverlay?
Override getMarker()
in a custom subclass of OverlayItem
. Here is a sample project demonstrating this, where the drawable is toggled between different images at runtime.
Answered By - CommonsWare
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.