如何在osmdroid中的Polygon中获取onTap? [英] How to get onTap in Polygon in osmdroid?

查看:174
本文介绍了如何在osmdroid中的Polygon中获取onTap?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我绘制了很多多边形.其中有些重叠.我希望能够检测到多边形内的一个拍子,并显示一个对话框,说它在多边形内被单击(该多边形应该在拍子上被检测到).可以通过 ItemizedIconOverlay 看到这种属性,我们可以通过点击OverlayItem来检测所有OverlayItem.如何在多边形上实现呢?

I have lot's of polygon drawn. Some of which overlaps. I want to be able to detect a tap inside the polygon and display a dialog saying it was clicked inside the polygon (this polygon should be detected on tap). This kind of property can be seen with ItemizedIconOverlay where we can detect all of the OverlayItem with the tap on the OverlayItem. How to implement this on polygon?

我绘制和添加多边形的方法是:

The way I draw and add Polygon is:

MyPolygon myNewPolygon = new MyPolygon(this);
myPolygon.setPoints(Polygon.pointsAsCircle(new GeoPoint(38.948714, -76.831918), 20000.0));
map.getOverlays().add(myPolygon);
myNewPolygon.setPoints(Polygon.pointsAsCircle(new GeoPoint(38.851777, -77.037878), 20000.0));
map.getOverlays().add(myNewPolygon);

推荐答案

有不同的答案,具体取决于您要实现的目标.

There are various answers, depending on what you want to achieve exactly.

简单的情况:如果只想打开气泡,则只需按照教程中的说明将InfoWindow设置为Polygon.

Simple case: if you just want to have a bubble opening, then just set an InfoWindow to your Polygon, as described in the tutorial.

如果您还有其他需要:对于多边形",没有可用的侦听器,对于标记"和多段线"也没有(可能是对请求的增强?).

If you want anything else: for Polygons, there is no Listener available, as there are for Markers and Polylines (an enhancement to request, maybe?).

因此,您可以做的是Polygon子类-就像处理MyPolygon一样.然后覆盖onTap方法-或最有可能的onSingleTapConfirmed-并实现所需的行为.

So what you can do is sub-class Polygon - as you did with your MyPolygon. Then override onTap method - or most likely onSingleTapConfirmed - and implement the behaviour you need.

查看

Looking at Polygon.onSingleTapConfirmed source may help (hit test for instance).

这篇关于如何在osmdroid中的Polygon中获取onTap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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