开发者

android mapview overlay popup hide

i have a mapview and overlay items which 开发者_Python百科when tap on shows popuo with text. what I want is when user taps on map outside of these overlay items or popup hide the popup if its currently visible.


The only way to do it (as I know), is adding new overlay to your map, witch serves as the popup. When you tap outside of the overlay, just remove it from overlay list.

This means you have to draw and handle events for your popup by yourself.


Ive been trying to acheive the same, this is exactly what i want :- http://proxy.latest.xuemath.appspot.com/img?s=aR.1f.1be6ifej.2ec/_Fbk8IlxNQXM/S-ruq97dRWI/AAAAAAAAELY/s-o3onSReiU/s400/kml_google_maps_v3.bmp

i have implemented googleMapView with overlays, i have one issue i want to show a popup when clicked on each overlay, and when i click on another overlay the previous popus should disappear and new one should appear at the clicked location(ie projection points). And popup shouldnt appear when i click anywhere else on screen.Im using onTap event to record onclick. (map_overlay) is the layout that i want to show when someone click a projection point on the map. The code is below and map_overlay.xml could be any file.

Class: ItemizedOverlay:-

public boolean onTap(GeoPoint p, MapView mapView) {

LayoutInflater inflater = (LayoutInflater)cContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

LayoutParams lp = new MapView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT, p, LayoutParams.WRAP_CONTENT);
LinearLayout view = (LinearLayout)inflater.inflate(R.layout.map_overlay, null);

mapView.removeView(view);    
mapView.invalidate();    
mapView.addView(view,lp);

mapView.invalidate();

return true;
}

Below is the Main class in which im displaying projection points which is working fine and im calling I have implemented the onTap event in another class as shown above:

public class MapView extends MapActivity{ private ArrayList overlayItem ;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.large_mapview);
    mapView = (MapView) findViewById(R.id.mapview);
   // mapView.setBuiltInZoomControls(true);

    List<Overlay> mapOverlays = mapView.getOverlays();
    Drawable drawable = this.getResources().getDrawable(R.drawable.mappointer2);
    ItemizedOverlay itemizedoverlay = new ItemizedOverlay(drawable,this);
    OverlayItem overlayitem;
    GeoPoint point;
    double lat;
    double lng;        

    for (int i = 0; i < overlayItem.size(); i++) {

        lat = Double.parseDouble(overlayItem.get(i).getLatitude());
        lng = Double.parseDouble(overlayItem.get(i).getLongitude());
        point = new GeoPoint((int) (lat * 1E6),(int) (lng * 1E6));

        overlayitem = new OverlayItem(point, i+"".toString(), overlayItem.get(i).getDetails().toString());
        itemizedoverlay.addOverlay(overlayitem);
        mapOverlays.add(itemizedoverlay);

    }

    mapView.invalidate();
}

}

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜