开发者

Performance of map overlay in conjunction with ItemizedOverlay is very poor

I am trying to display one png (drawable) on a map in about 300 points. I am retrieving the coordinates from a Sqlite table, dumping them in a cursor. When I try to display them by parsing through the cursor, it takes for ever for the images to be drawn, about .5 second per image. I find that to be suspiciously slow, so some insight on how I can increase performance would help. Here is the snippet of my code that does the rendering:

while (!mFlavorsCursor.开发者_高级运维isAfterLast())
            {

                Log.d("cursor",""+(i++));
              point = new GeoPoint(
                      (int)(mFlavorsCursor.getFloat(mFlavorsCursor.getColumnIndex(DataBaseHelper.KEY_LATITUDE))*1000000),
                      (int)(mFlavorsCursor.getFloat(mFlavorsCursor.getColumnIndex(DataBaseHelper.KEY_LONGITUDE))*1000000));
              overlayitem = new OverlayItem(point, "", "");
              itemizedoverlay.addOverlay(overlayitem);
              itemizedoverlay.doPopulate();
              mFlavorsCursor.moveToNext();
            }
            mapOverlays.add(itemizedoverlay);

I tried to isolate all the steps and it looks like the slow one is this:

itemizedoverlay.doPopulate();

This is a public method in my class that extends ItemizedOverlay that runs the private populate() method.


Do not call doPopulate() until you have populated all the items.


I know this is a very old question but I was having a similar issue and found a solution.

In your subclass of ItemizedOverlay, do this:

@Override
public void draw(Canvas canvas,
        MapView mapView,
        boolean shadow) {

    if (!shadow)
        super.draw(canvas, mapView, shadow);
}

What this does is intercept the draw request and disables the drawing of the shadow layer. The next effect is that your markers won't have pretty shadows on them projected onto the map, but the upside is a radical increase in scroll performance on the MapView.

You can compensate for this by just including shadows in your marker PNG's (using appropriate alpha).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜