Select to view content in your preferred language

executeWithQuery for AGSMutablePoint returns near by feature of Layers from didClickAtPoint.

4760
7
04-07-2016 12:57 PM
PritiBose
Deactivated User

hello,

for two days i trying to fixed issue.

i am using AGSMutablePoint to get Asset present on visible Layers at Click point....

m_mapView.touchDelegate = self;

m_sketchLayer.geometry = [[[AGSMultipoint alloc] initWithSpatialReference:m_mapView.spatialReference] autorelease];

- (void) mapView:(AGSMapView*)m_mapView

didClickAtPoint:(CGPoint)screen

        mapPoint:(AGSPoint*)mappoint

        graphics:(NSDictionary*)graphics {

self.m_queryTask = [AGSQueryTask queryTaskWithURL:[NSURL URLWithString:CurrentLayerURL]];

self.m_queryTask.delegate = self;

             

AGSQuery *currentQuery = [AGSQuery query];

currentQuery.spatialRelationship = AGSSpatialRelationIntersect;   // i tried all spatialrelation option

currentQuery.outFields = [NSArray arrayWithObjects:@"*", nil];

currentQuery.returnGeometry=YES;

AGSEnvelope *env = [AGSEnvelope envelopeWithXmin:mappoint.x  -10.0 ymin:mappoint.y -10.0 xmax:mappoint.x +10.0 ymax:mappoint.y +10.0 spatialReference:[AGSSpatialReference spatialReferenceWithWKID:dSpatialReference WKT:self.m_mapView.spatialReference.wkt]];

currentQuery.outSpatialReference = self.m_mapView.spatialReference;             

currentQuery.geometry=env;

[self.m_queryTask executeWithQuery:currentQuery];

}

i wanted to get only features where i clicked....and not featured all around... as can be seen from image....

images show two graphics ... it had return me two result at different point but i had click on single point.....

Screen Shot 2016-04-08 at 1.21.55 AM.png

is there any way to reduce search criteria....

if no then when i display result with showCalloutAtPoint for both graphics it display only one last result (BL-0073)as seen from image....how to display all graphics result (for 2nd line)....so that user can click on individual graphics result....

0 Kudos
7 Replies
ShiminCai
Frequent Contributor

Hi,

Try:

     currentQuery.spatialRelationship = AGSSpatialRelationTouch;

     currentQuery.geometry=[mappoint geometry];

Regards,

Shimin

0 Kudos
PritiBose
Deactivated User

Hello,

  currentQuery.geometry=[mappoint geometry]; gives error ..... there is no [mappoint geometry].

i tried with AGSSpatialRelationTouch , but it did not return me any result....

is there any way i can make all result display like one Screen Shot 2016-04-08 at 11.51.07 AM.png

at present showcalloutatpoint display only last result.... at least if query returning 2-3 result as seen from above image .... i need to show all display result not only one BL-0073.....

0 Kudos
ShiminCai
Frequent Contributor

1. Sorry and try this line: currentQuery.geometry=mappoint;

2. Actually the features you click should be stored in the third argument: graphics of the mapview touch delegate method. I think you just need to loop through the graphics and locate the one you want to display... 

0 Kudos
PritiBose
Deactivated User

hello,

i already tried, mapping geometry..... it does not return me any result..... above code of mine works perfect only thing instead of getting only result at Click point...it gives me near by features too...as can be seen from two parallel line from 1st image.

2. i am looping through graphics i have stored all the graphics of result....then i filter out result and accordingly i loop through individual result and graphics...but still it display only last graphics.....

for (NSArray *arr1 in arrStoredGraphics) {

                            if ([[arr objectAtIndex:2] isEqualToString:[arr1 objectAtIndex:0]]) {

                               

                                AGSCalloutTemplate *m_AssetDetailCallout = [[AGSCalloutTemplate alloc]init];

                               

                                m_AssetDetailCallout.titleTemplate = [arr1 objectAtIndex:0];

                                m_AssetDetailCallout.detailTemplate = @"Click for more detail..";

                                self.m_mapView.calloutDelegate=self;

                                self.m_mapView.callout.delegate =self;

                                AGSGraphic *querygraphic =[[AGSGraphic alloc] init];

                                querygraphic.geometry=[arr1 objectAtIndex:1];

                                querygraphic.symbol=[arr1 objectAtIndex:2];

                                querygraphic.infoTemplateDelegate=m_AssetDetailCallout;

                                NSMutableDictionary *dFeatures=[[NSMutableDictionary alloc] init];

                                dFeatures=[arr1 objectAtIndex:4];

                                [dFeatures setObject:[arr objectAtIndex:1] forKey:@"FieldValue"];

                                [querygraphic setAllAttributes:dFeatures];

                                [m_graphicsLayer addGraphic:querygraphic];

                        

                                [self.m_mapView.callout showCalloutAtPointAGSPoint *)querygraphic.geometry.envelope.center forGraphic:querygraphic animated:YES];

                                break;

}

plz help either to reduce search query result only on click point or show all graphics display result.... so the user know which graphic is belongs to which result....

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Ok. Here's what I would do. AGSGeometryEngine will be your friend here.

Just go through the graphics parameter (although that delegate method was deprecated and you should use the features equivalent if you're using the 10.2.x SDK) to find the entry for the layer you're interested in, then go over the features returned for that layer and use AGSGeometryEngine.distanceFromGeometry:toGeometry​​​ to pick the closest geometry to the map point where the user tapped.

Note that since your layer is on the map, the results will come back in the didClickAtPoint​ delegate call in the features parameter, as mentioned by Shimin Cai​​ above. You do not need to query the remote layer again since your data is already on the map on the device. Querying again might be doing what you want but it's an extra network request.

0 Kudos
PritiBose
Deactivated User

hello,

i tried AGSGeometryEngine.distanceFromGeometry:toGeometry it is giving me 0, also i tried rest intersect n all but no used..... even thought it picks up feature from near by area from click point geometry shows intersect....

also i tried AGSSpatialRelationshipRelation with relationParam but no success....

is there any way to use AGSSpatialRelationshipTouches.... as i feel this spatial-relation should work .....but when i tried with my above code it is not returning me any geometry.....

0 Kudos
Nicholas-Furness
Esri Regular Contributor

After some direct messaging back and forth we found a few issues:

  • The MapView was using Map Services rather than Feature Services for the layers in question. mapView:didClick will not return features for a Map Service, so the query is indeed required.
  • Rather than using a query, an AGSIdentifyTask was more appropriate.
  • The code had some strange leftover SpatialReference stuff in there. Tidying that up helped.
  • There was no need for the Sketch Layer.

Making those changes and tightening up the search envelope resolved the issues.

0 Kudos