你如何控制一个OverlayItem的谷歌Android地图上的大小? [英] How do you control an OverlayItem's size on the Google Android map?

查看:149
本文介绍了你如何控制一个OverlayItem的谷歌Android地图上的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我只是一个黑客的工作在这个岗位讨论几乎完全一样的问题解决方案,他们决定去与根本不会为我工作。我需要一个真正的解决办法,所以我决定逆向工程的Andr​​oid地图源$ C ​​$ C,以找到最佳的解决方案。

So I have almost the exact same problem discussed in this post except that the hack job of a solution that they decided to go with simply isn't going to work for me. I need a real solution, so I decided to reverse engineer the android maps source code to find the best solution.

我目前的解决方案是覆盖在我的课扩展OverlayItem draw方法,但后来我碰上敲击覆盖项目在地图上在比其他位置不起作用(水龙头寄存器中的问题实际的项目绘制)。所以,我只是要不断挖掘,直到找到方法适当搭配覆盖。

My current solution is to override the draw method in my class that extends OverlayItem, but then I run into the problem that tapping on the overlay item on the map doesn't work (the tap registers at a location other than where the actual item is drawn). So, i'm just going to keep digging until I find the proper mix of methods to override.

推荐答案

有关人在那里有同样的问题,因为我的,解决的办法其实很简单。

For anybody out there that has the same problem as me, the solution is actually quite simple.

所有你需要做的是设置在OverlayItem的绘制边界,就像这样:

All you have to do is set the bounds on the OverlayItem's drawable, like this:

Drawable d = myOverlayItem.getMarker(0);
d.setBounds(-xWidth/2, -yWidth/2, xWidth, yWidth);

有关getMarker的参数实际上依赖于overlayItem的状态,但个人对我来说它同样为我所有的国家,所以我也没在意,只是使用0。

The parameter for getMarker actually depends on the state of the overlayItem, but personally for me its the same for all my states so I didn't care and just used 0.

我不知道该解决方案将如何取决于你实际设置范围各不相同,但对我来说,我做到了我的ItemizedOverlay子类的Draw方法中:

I'm not sure how the solution will vary depending on where you actually set the bounds, but for me I did it within the draw method of my ItemizedOverlay subclass:

@Override
public void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow) {
    if (!shadow) {
        // Do your projection calculations here, if necessary

        for (int i = 0; i < mOverlays.size(); i++) {
            Drawable d = mOverlays.get(i).getMarker(0);
            d.setBounds(-width/2, -height/2, width/2, height/2);
        }
    }

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

其值得注意的是,项目覆盖的范围从0,0,这实际上是翻译成OverlayIcon左上角的画布开始。在我的例子,如果你设置宽度为50,高度为50 OverlayItem将集中于它在地图上的位置definied(在OverlayItem的构造函数中设置)绘制。你可以看到这种情况发生在覆盖来源:

Its worth noting that the bounds of the overlay item start from 0,0, which actually is a canvas translated to the top left of the OverlayIcon. In my example, if you set width to 50 and height to 50 the OverlayItem would be drawn on the map centered on it's definied position (set in the OverlayItem's constructor). You can see this happening in the source of Overlay:

protected static void drawAt(Canvas canvas, Drawable drawable, int x, int y, boolean shadow)
  {
      // .... Do Stuff ....

      canvas.save();
      canvas.translate(x, y);

      // .... Do Stuff ....

      drawable.draw(canvas);

      // .... Do Stuff ....

      canvas.restore();
  }

(它发生在canvas.translate调用)

(It happens with the canvas.translate call)

在关闭的机会,有人关心这里是为覆盖完整的源代码。

On the off chance that somebody cares here's the full source for Overlay.

(我花了大量的工作,进行逆向工程maps.jar所以我还不如充分利用我的努力)。

(It took me a lot of work to reverse engineer maps.jar so I might as well get the most out of my effort).

这篇关于你如何控制一个OverlayItem的谷歌Android地图上的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆