地图叠加与 ItemizedOverlay 结合使用的性能非常差

发布于 2024-08-28 20:00:25 字数 981 浏览 6 评论 0原文

我正在尝试在地图上显示一个大约 300 点的 png(可绘制)。我正在从 Sqlite 表中检索坐标,并将它们转储到游标中。当我尝试通过解析光标来显示它们时,绘制图像需要很长时间,每个图像大约需要 0.5 秒。我发现这速度慢得令人怀疑,因此了解如何提高性能会有所帮助。这是我执行渲染的代码片段:

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

我尝试隔离所有步骤,看起来速度较慢的是:

itemizedoverlay.doPopulate();

这是我的类中的公共方法它扩展了运行私有 populate() 方法的 ItemizedOverlay。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千仐 2024-09-04 20:00:25

在填充所有项目之前,请勿调用 doPopulate()

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

世界等同你 2024-09-04 20:00:25

我知道这是一个非常古老的问题,但我遇到了类似的问题并找到了解决方案。

在 ItemizedOverlay 的子类中,执行以下操作:

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

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

其作用是拦截绘制请求并禁用阴影层的绘制。下一个效果是,您的标记在投影到地图上时不会有漂亮的阴影,但好处是 MapView 上的滚动性能大幅提高。

您可以通过在标记 PNG 中包含阴影(使用适当的 Alpha)来弥补这一点。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文