ArcGIS for Android 获取webmap的popup window(FeatureLayer)

要显示webmap中FeatureLayer中的popup window 比显示DynamicLayer中的popup window容易的多。以下代码,是在遍历查找到含有popopInfo的信息的FeatureLayer之后,并查询这些FeatureLayer在触摸处的Graphic,最后这些Graphic为参数,实例化出popup,加入到PopupContainer中待显示。具体代码如下:

public class FeaturePopupActivity extends Activity {
	
	MapView mMapView ;
	ProgressDialog dio;
	int count;//代表还需要查询多少个图层
	PopupContainer container;//储存Popup
	myPopupViewDialog popDio;//自定定义PopupContainerView显示方式

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mMapView = new MapView(this, "http://www.arcgis.com/home/item.html?id=81d2dcf906cf4df4889ec36c8dc0c1f9", "", "");
        setContentView(mMapView);
        dio=new ProgressDialog(this);
        dio.setMessage("正在查找...");
        mMapView.setOnStatusChangedListener(new OnStatusChangedListener(){
			public void onStatusChanged(Object arg0, STATUS arg1) {
				if(arg0==mMapView && arg1==STATUS.INITIALIZED){
					mMapView.setOnSingleTapListener(new MyTouchLis());
				}
			}
        });
    }
    
    
    
    class MyTouchLis implements OnSingleTapListener {
		public void onSingleTap(float x, float y) {
			container=new PopupContainer(mMapView);
			dio.show();
			Layer[] layers=  mMapView.getLayers();
			//遍历出FeatureLayer类型的图层
			for(Layer layer :layers){
				if(!(layer instanceof ArcGISFeatureLayer)){
					continue;
				}
				ArcGISFeatureLayer afl=(ArcGISFeatureLayer) layer;
				//判断ArcGISFeatureLayer是否包含PopopInfo
				if(afl.getPopupInfo()!=null){
					count++;
					new QueryFeatureLayer(FeaturePopupActivity.this,x, y).execute(afl);
				}
			}
			
		}
    }
       
    class QueryFeatureLayer extends AsyncTask<ArcGISFeatureLayer, Void, List<Graphic>>{
    	private float x;
    	private float y;
    	private Context context;
		public QueryFeatureLayer(Context context,float x, float y) {
			this.x = x;
			this.y = y;
			this.context=context;
		}

		@Override
		protected List<Graphic> doInBackground(ArcGISFeatureLayer... params) {
			ArcGISFeatureLayer afl=params[0];
		
		    int[] ids=afl.getGraphicIDs(x, y, 20);
		    if(ids.length==0){
		    	return null;
		    }
		    List<Graphic> gs=new ArrayList<Graphic>();
		    for(int id:ids){
		    	Graphic g= afl.getGraphic(id);
		    	if(g==null){
		    		continue;
		    	}
		    	gs.add(g);
		    }
			return gs;
		}

		@Override
		protected void onPostExecute(List<Graphic> result) {
			count--;
			if(count==0){
				dio.dismiss();
			}
			
			if(result==null || result.size()==0){
				return;
			}
			for(Graphic g:result){
				container.addPopup(new Popup(mMapView, g));
				
			}
			if(count==0){
				popDio=new myPopupViewDialog(context);
				popDio.show();
			}
		}
    }
    
    
    
    
  //点定义PopupContainer显示显示,使其以Dialog的形式显示
  	class myPopupViewDialog extends Dialog{
  		private Context context;
  		public myPopupViewDialog(Context context) {
  			super(context);
  			this.context=context;
  		}
  		@Override
  		protected void onCreate(Bundle savedInstanceState) {
  			super.onCreate(savedInstanceState);
  			LayoutParams params=new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
  			LinearLayout layout=new LinearLayout(context);
  			layout.addView(container.getPopupContainerView(), LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
  			setContentView(layout, params);
  		}
  	}

}


下载代码


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值