如何获取OSM中单击的ItemizedIconOverlay的索引

时间:2017-01-13 13:14:54

标签: java android overlay osmdroid itemizedoverlay

当用户点击图标时,如何获取ItemizedIconOverlay<OverlayItem> anotherItemizedIconOverlay的索引位置?例如,当用户点击/单击第一个图标时,它应该得到整数0

List<GeoPoint> nodes = nodeCoordinates();
ArrayList<OverlayItem> anotherOverlayItemArray = new ArrayList<>();
Drawable newMarker = getResources().getDrawable(R.drawable.marker_node);

for(int i = 0; i < nodes.size(); i++) {
    anotherOverlayItemArray.add(new OverlayItem("Road", "Nodes", nodes.get(i)));
    anotherOverlayItemArray.get(i).setMarker(newMarker);
}

ItemizedIconOverlay<OverlayItem> anotherItemizedIconOverlay
            = new ItemizedIconOverlay<>(
            this, anotherOverlayItemArray, null);
map.getOverlays().add(anotherItemizedIconOverlay);

1 个答案:

答案 0 :(得分:1)

这里有一个例子 https://github.com/osmdroid/osmdroid/blob/master/OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/data/SampleMilitaryIconsItemizedIcons.java

确认,格式化问题......

`

itemOverlay = new ItemizedOverlayWithFocus&lt;&gt;(new ArrayList(),                        new ItemizedIconOverlay.OnItemGestureListener(){                             @覆盖                             public boolean onItemSingleTapUp(final int index,final OverlayItem item){                                  Toast.makeText(                                          背景下,                                          &#34;项目&#39;&#34; + item.getTitle()+&#34;&#39; (index =&#34; + index                                                  +&#34;)单击“#34;,Toast.LENGTH_LONG)。show();                                  返回true;                             }

                        @Override
                        public boolean onItemLongPress(final int index, final OverlayItem item) {
                             Toast.makeText(
                                     context,
                                     "Item '" + item.getTitle() + "' (index=" + index
                                             + ") got long pressed", Toast.LENGTH_LONG).show();
                             return false;
                        }
                   }, context);

`