开发者

Android MapView ItemizedOverlay Draw onTap

I am trying to draw a custom shape in Draw method of Ite开发者_C百科mizedOverlay. Is it possible to get onTap event for the shape drawn. Currently onTap works for default drawable/marker. How to make it work for the shape drawn in Draw method?


It looks like you can override the hittest method from itemized overlay.

Replace the method with a test to see if you hit your shape. Please post your solution here for others afterwards.

Here is the original android version

    protected boolean hitTest(OverlayItem item, Drawable marker, int hitX, int hitY) {
            Point eventPos = new Point(hitX, hitY);
            Point itemHitPosOnDisplay = calculateItemPostionRelativeToDisplay(item.getPoint());
            Point distance = Point.substract(eventPos, itemHitPosOnDisplay);
            if (marker == null) {
                    marker = this.defaultMarker;
            }
            if (Math.abs(distance.x) < marker.getIntrinsicWidth() / 2
                            && Math.abs(distance.y) < marker.getIntrinsicHeight() / 2) {
                    return true;
            }
            return false;
    }

Regards, Stéphane

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜