How to get a listener for many Feature Layers in ArcGIS Android? -
i have 2 feature layers added map can see when display mapview. however, it's last added feature layer can processed touch listener. cannot figure out how make features layers taken account touch listener.
my goal differentiate click on carto_etare's feature click on carto_pt_eau's one.
any appreciated.
mgeodatabase = new geodatabase(mgeodb); // load geodatabase mgeodatabase.loadasync(); // add feature layer geodatabase arcgismap mgeodatabase.adddoneloadinglistener(new runnable() { @override public void run() { (geodatabasefeaturetable geodbtable : mgeodatabase.getgeodatabasefeaturetables()){ arraylist<string> list_of_tables = new arraylist<string>(); list_of_tables.add("carto_etare"); list_of_tables.add("carto_pt_eau"); set<string> set = new hashset<string>(list_of_tables); if (set.contains(geodbtable.gettablename())) { mfeaturelayer = new featurelayer(geodbtable); mfeaturelayer.setlabelsenabled(true); mfeaturelayer.setselectionwidth(10); //featurelayer.selectfeatures(); mmap.getoperationallayers().add(mfeaturelayer); mmapview.setmap(mmap); // set on touch listener listen click events mmapview.setontouchlistener(new defaultmapviewontouchlistener(mainactivity.this, mmapview) { @override public boolean onsingletapconfirmed(motionevent e) { // point clicked , convert point in map coordinates point clickpoint = mmapview.screentolocation(new android.graphics.point(math.round(e.getx()), math.round(e.gety()))); int tolerance = 10; double maptolerance = tolerance * mmapview.getunitsperdensityindependentpixel(); // create objects required selection query envelope envelope = new envelope(clickpoint.getx() - maptolerance, clickpoint.gety() - maptolerance, clickpoint.getx() + maptolerance, clickpoint.gety() + maptolerance, mmap.getspatialreference()); queryparameters query = new queryparameters(); query.setgeometry(envelope); // call select features mfuture = mfeaturelayer.selectfeaturesasync(query, featurelayer.selectionmode.add); // add done loading listener fire when selection returns mfuture.adddonelistener(new runnable() { @override public void run() { try { //call on future result featurequeryresult result = mfuture.get(); // create iterator iterator<feature> iterator = result.iterator(); feature feature; while (iterator.hasnext()) { feature = iterator.next(); map<string, object> attributes = feature.getattributes(); if(feature.getfeaturetable().gettablename().equals("carto_pt_eau")) { toast.maketext(getapplicationcontext(), long.tostring((long)attributes.get("id_pt_eau")), toast.length_short).show(); } else if(feature.getfeaturetable().gettablename().equals("carto_etare")) { mpdffilename = (string) attributes.get("cod"); } } } catch (exception e) { log.e(getresources().getstring(r.string.app_name), "select feature failed: " + e.getmessage()); } } }); return super.onsingletapconfirmed(e); } }); } } } });
your current code select whatever features within mfeaturelayer per line here
mfuture = mfeaturelayer.selectfeaturesasync(query, featurelayer.selectionmode.add); which getting overwritten each time within loop on geodatabase tables it's holding whatever layer added last.
i think identify or 1 of overloads might more suited purposes.
some quick example usage code is:
@override public boolean onsingletapconfirmed(motionevent e) { android.graphics.point screenpoint = new android.graphics.point((int) e.getx(), (int) e.gety()); final listenablefuture<list<identifylayerresult>> identifyfuture = mmapview .identifylayersasync(screenpoint, 10, false, 10); identifyfuture.adddonelistener(new runnable() { @override public void run() { try { list<identifylayerresult> identifylayerresultlist = identifyfuture.get(); //if point identify occurs @ contains points both layers, should return 2 results, 1 each layer log.d("identifysize", string.valueof(identifylayerresultlist.size())); (identifylayerresult result : identifylayerresultlist) { layercontent layer = result.getlayercontent(); //do whatever want layer //the features retrieved through result.getelements() } } catch (interruptedexception | executionexception e1) { e1.printstacktrace(); } } }); return super.onsingletapconfirmed(e); }
Comments
Post a Comment