Selection Box

1580
13
Jump to solution
04-18-2012 11:02 AM
AshrafMemon
New Contributor
Hi there,

Has anyone implemented a selection box to define selection envelop for query on the map? The scenario is:
- User clicks on a query button
- users draws a selection box on the map to define query extent
- user clicks search to search the database.

I have implemented step 1 and 3, need some help (examples or pointers) on step 2.

Thank you,
Ashraf
0 Kudos
1 Solution

Accepted Solutions
NimeshJarecha
Esri Regular Contributor
Sorry, i just forgot to mention that you were creating graphic with self.mappoint. Change it to use sketchPolygon. See attached project.

[ATTACH=CONFIG]13653[/ATTACH]

Regards,
Nimesh

View solution in original post

0 Kudos
13 Replies
NimeshJarecha
Esri Regular Contributor
Ashraf,

You can use Sketch Graphics Layer for step 2 and pass sketch layer's geometry as query geometry parameter. Look at Sketch Layer Sample.

Hope this helps!

Regards,
Nimesh
0 Kudos
AshrafMemon
New Contributor
Hi Nimesh,

How do you create a rectangular box using 2 clicks (or dragging) on the map view? I have been playing with the example you pointed out for the last couple of days to figure out the solution and also playing with the identify example, no luck yet. Can you please send me a some clues of a snippet to resolve the issue?

Thanks,
Ashraf
0 Kudos
NimeshJarecha
Esri Regular Contributor
Ashraf,

You want to create a rectangular box using 2 clicks, that's an envelope. You can't sketch an envelope with sketch graphics layer. You should sketch the polygon and use it in the query geometry parameter.

Regards,
Nimesh
0 Kudos
AshrafMemon
New Contributor
Hi Nimesh,

Thank you for your responses.

How about using graphics layer with logic to detect 2nd click below, please assume that the below code is written in the successful if condition to detect second click:

        AGSMutablePolygon* sketchPolygon = [[AGSMutablePolygon alloc] initWithSpatialReference:self.mapView.spatialReference];
        self.mappoint2=mappoint;
        NSLog(@"minx,miny,maxx,maxy:%f,%f,%f,%f",self.mappoint1.x,self.mappoint1.y, self.mappoint2.x,self.mappoint2.y);
       
        [sketchPolygon addRingToPolygon];
        [sketchPolygon addPointToRing:[AGSPoint pointWithX:self.mappoint1.x y:self.mappoint1.y spatialReference:self.mapView.spatialReference]];
        [sketchPolygon addPointToRing:[AGSPoint pointWithX:self.mappoint2.x y:self.mappoint1.y spatialReference:self.mapView.spatialReference]];
        [sketchPolygon addPointToRing:[AGSPoint pointWithX:self.mappoint2.x y:self.mappoint2.y spatialReference:self.mapView.spatialReference]];
        [sketchPolygon addPointToRing:[AGSPoint pointWithX:self.mappoint1.x y:self.mappoint2.y spatialReference:self.mapView.spatialReference]];
        [sketchPolygon addPointToRing:[AGSPoint pointWithX:self.mappoint1.x y:self.mappoint1.y spatialReference:self.mapView.spatialReference]];
       AGSGraphic *graphic;   
        AGSSimpleFillSymbol* myFillSymbol = [AGSSimpleFillSymbol simpleFillSymbol];
        myFillSymbol.color = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];

        graphic = [AGSGraphic graphicWithGeometry:sketchPolygon symbol:myFillSymbol attributes:nil infoTemplateDelegate:nil];  
       [self.graphicsLayer addGraphic:graphic];

but nothing shows up on the screen, any suggestions on what I am doing wrong?

Thanks,
Ashraf
0 Kudos
NimeshJarecha
Esri Regular Contributor
Nothing shows up because you are making it invisible.

Change,
myFillSymbol.color = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];

To,
myFillSymbol.color = [UIColor colorWithRed:255 green:0 blue:0 alpha:0.5];

Regards,
Nimesh
0 Kudos
AshrafMemon
New Contributor
Hi Nimesh,

Sorry that was a mistake, but that didn't solve the problem either. I am attaching the identify demo sample code with the above modification to the code. Can you please check whats wrong?

Thank you,
Ashraf
0 Kudos
NimeshJarecha
Esri Regular Contributor
Just refresh graphics layer after adding the graphic.

[self.graphicsLayer addGraphic:graphic];
[self.graphicsLayer dataChanged]; //add

Regards,
Nimesh
0 Kudos
AshrafMemon
New Contributor
just tried that. It didn't work.

Sincerely,
Ashraf Memon
C: 858 405 1484
0 Kudos
AshrafMemon
New Contributor
Hi Nimesh,

Is it working on your machine?

Thanks,
Ashraf
0 Kudos