我有 osmdroid,overlayswithfocus,当我们单击在覆盖的标注或弹出窗口显示,但我需要它回到正常的叠加时我触摸其他叠加图。所以,我需要帮助请。和我的添加叠加的 for 循环调用此函数。
在osmdroid中添加marker并事件的实现。
在osmdroid 地图中添加marker 并添加事件
主要采用ItemizedOverlayWithFocus图层并添加
ItemizedIconOverlay.OnItemGestureListener事件监听实现
package com.geoserver.osmdroid; import java.util.ArrayList; import org.osmdroid.ResourceProxy; import org.osmdroid.DefaultResourceProxyImpl; import org.osmdroid.tileprovider.util.CloudmadeUtil; import org.osmdroid.util.GeoPoint; import org.osmdroid.views.MapView; import org.osmdroid.views.overlay.ItemizedIconOverlay; import org.osmdroid.views.overlay.ItemizedOverlayWithFocus; import org.osmdroid.views.overlay.MinimapOverlay; import org.osmdroid.views.overlay.OverlayItem; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.RelativeLayout; import android.widget.RelativeLayout.LayoutParams; import android.widget.Toast; /** * * 在osmdroid 地图中添加marker 并添加事件 * * 主要采用ItemizedOverlayWithFocus图层并添加 * ItemizedIconOverlay.OnItemGestureListener事件监听实现 * final ArrayList<OverlayItem> items = new ArrayList<OverlayItem>(); items.add(new OverlayItem("Hannover", "Tiny SampleDescription", new GeoPoint(52370816, 9735936))); // Hannover items.add(new OverlayItem("Berlin", "This is a relatively short SampleDescription.", new GeoPoint(52518333, 13408333))); // Berlin items.add(new OverlayItem( "Washington", "This SampleDescription is a pretty long one. Almost as long as a the great wall in china.", new GeoPoint(38895000, -77036667))); // Washington items.add(new OverlayItem("San Francisco", "SampleDescription", new GeoPoint(37779300, -122419200))); // San Francisco this.mMyLocationOverlay = new ItemizedOverlayWithFocus<OverlayItem>( items, new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() { @Override public boolean onItemSingleTapUp(final int index, final OverlayItem item) { Toast.makeText( SampleWithMinimapItemizedoverlayWithFocus.this, "Item '" + item.mTitle + "' (index=" + index + ") got single tapped up", Toast.LENGTH_LONG).show(); return true; } @Override public boolean onItemLongPress(final int index, final OverlayItem item) { Toast.makeText( SampleWithMinimapItemizedoverlayWithFocus.this, "Item '" + item.mTitle + "' (index=" + index + ") got long pressed", Toast.LENGTH_LONG).show(); return false; } }, mResourceProxy); this.mMyLocationOverlay.setFocusItemsOnTap(true); this.mMyLocationOverlay.setFocusedItem(0); this.mOsmv.getOverlays().add(this.mMyLocationOverlay); * @Title: * @Description: 实现TODO * @Copyright:Copyright (c) 2011 * @Company: * @Date:2012-9-6 * @author longgangbai * @version 1.0 */ public class SampleWithMinimapItemizedoverlayWithFocus extends Activity { // =========================================================== // Constants // =========================================================== private static final int MENU_ZOOMIN_ID = Menu.FIRST; private static final int MENU_ZOOMOUT_ID = MENU_ZOOMIN_ID + 1; // =========================================================== // Fields // =========================================================== private MapView mOsmv; private ItemizedOverlayWithFocus<OverlayItem> mMyLocationOverlay; private ResourceProxy mResourceProxy; // =========================================================== // Constructors // =========================================================== /** Called when the activity is first created. */ @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); mResourceProxy = new DefaultResourceProxyImpl(getApplicationContext()); final RelativeLayout rl = new RelativeLayout(this); CloudmadeUtil.retrieveCloudmadeKey(getApplicationContext()); this.mOsmv = new MapView(this, 256); rl.addView(this.mOsmv, new RelativeLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); /* Itemized Overlay */ { /* * Create a static ItemizedOverlay showing a some Markers on some * cities. */ final ArrayList<OverlayItem> items = new ArrayList<OverlayItem>(); items.add(new OverlayItem("Hannover", "Tiny SampleDescription", new GeoPoint(52370816, 9735936))); // Hannover items.add(new OverlayItem("Berlin", "This is a relatively short SampleDescription.", new GeoPoint(52518333, 13408333))); // Berlin items.add(new OverlayItem( "Washington", "This SampleDescription is a pretty long one. Almost as long as a the great wall in china.", new GeoPoint(38895000, -77036667))); // Washington items.add(new OverlayItem("San Francisco", "SampleDescription", new GeoPoint(37779300, -122419200))); // San Francisco /* OnTapListener for the Markers, shows a simple Toast. */ this.mMyLocationOverlay = new ItemizedOverlayWithFocus<OverlayItem>( items, new ItemizedIconOverlay.OnItemGestureListener<OverlayItem>() { @Override public boolean onItemSingleTapUp(final int index, final OverlayItem item) { Toast.makeText( SampleWithMinimapItemizedoverlayWithFocus.this, "Item '" + item.mTitle + "' (index=" + index + ") got single tapped up", Toast.LENGTH_LONG).show(); return true; } @Override public boolean onItemLongPress(final int index, final OverlayItem item) { Toast.makeText( SampleWithMinimapItemizedoverlayWithFocus.this, "Item '" + item.mTitle + "' (index=" + index + ") got long pressed", Toast.LENGTH_LONG).show(); return false; } }, mResourceProxy); this.mMyLocationOverlay.setFocusItemsOnTap(true); this.mMyLocationOverlay.setFocusedItem(0); this.mOsmv.getOverlays().add(this.mMyLocationOverlay); } /* MiniMap */ { MinimapOverlay miniMapOverlay = new MinimapOverlay(this, mOsmv.getTileRequestCompleteHandler()); this.mOsmv.getOverlays().add(miniMapOverlay); } this.setContentView(rl); } @Override public boolean onCreateOptionsMenu(final Menu pMenu) { pMenu.add(0, MENU_ZOOMIN_ID, Menu.NONE, "ZoomIn"); pMenu.add(0, MENU_ZOOMOUT_ID, Menu.NONE, "ZoomOut"); return true; } @Override public boolean onMenuItemSelected(final int featureId, final MenuItem item) { switch (item.getItemId()) { case MENU_ZOOMIN_ID: this.mOsmv.getController().zoomIn(); return true; case MENU_ZOOMOUT_ID: this.mOsmv.getController().zoomOut(); return true; } return false; } }