How to use AGSPolygon

3285
9
05-18-2011 02:23 AM
Mdhanu
by
New Contributor
Hi All,

Can anybody please tell me how to use AGSPolygon class. If any sample please provide.......

Thanks & Regards
Dhanu
0 Kudos
9 Replies
NimeshJarecha
Esri Regular Contributor
If you want to create a new polygon then you should use AGSMutablePolygon.

AGSMutablePolygon *polygon = [[[AGSMutablePolygon alloc] initWithSpatialReference:[AGSSpatialReference spatialReferenceWithWKID:4326]]autorelease];
[polygon addRingToPolygon];
[polygon addPointToRing:[AGSPoint pointWithX:-143.963 y:-41.866 spatialReference:nil]];
[polygon addPointToRing:[AGSPoint pointWithX:-157.947 y:-21.940 spatialReference:nil]];
[polygon addPointToRing:[AGSPoint pointWithX:-165.336 y:11.767 spatialReference:nil]];

Regards,
Nimesh
0 Kudos
Mdhanu
by
New Contributor
If you want to create a new polygon then you should use AGSMutablePolygon.

AGSMutablePolygon *polygon = [[[AGSMutablePolygon alloc] initWithSpatialReference:[AGSSpatialReference spatialReferenceWithWKID:4326]]autorelease];
[polygon addRingToPolygon];
[polygon addPointToRing:[AGSPoint pointWithX:-143.963 y:-41.866 spatialReference:nil]];
[polygon addPointToRing:[AGSPoint pointWithX:-157.947 y:-21.940 spatialReference:nil]];
[polygon addPointToRing:[AGSPoint pointWithX:-165.336 y:11.767 spatialReference:nil]];

Regards,
Nimesh


Thanks Nimesh. But how to add this polygon to our mapview. Can you please help me on this.

Thanks & Regards
Dhanu
0 Kudos
NimeshJarecha
Esri Regular Contributor
You should check the Sketch Graphic Layer sample here..

All samples available here...

Also, go through reference and conceptual docs.

Regards,
Nimesh
0 Kudos
Mdhanu
by
New Contributor
You should check the Sketch Graphic Layer sample here..

All samples available here...

Also, go through reference and conceptual docs.

Regards,
Nimesh


Hi,

Thanks for your help.Actually the values like xMin,xMax,yMin,yMax are coming from server.Then how to use those values and display the pin on the mapview.Can anybody please help.And the data looking like following...

geometry: AGSPolygon: [envelope: AGSEnvelope: xmin = 6697891.653882, ymin = 1858772.386138, xmax = 6700179.767164, ymax = 1860410.398556, spatial reference: [AGSSpatialReference: wkid = 2229, wkt = null]], symbol: (null).

Thanks & Regards
Dhanu
0 Kudos
NimeshJarecha
Esri Regular Contributor
You should do the following...

1. Create a graphics layer and add it to map.
2. Create a graphic with the geometry (polygon) and add to graphics layer.
3. Refresh graphics layer with [graphicsLayer dataChanged].

The sample I pointed out does the same.

Regards,
Nimesh
0 Kudos
TomHicks
New Contributor II
I am new to ArcGIS for iOS, and I am struggling with displaying a polygon. I applied the above instructions to 'CustomCalloutSample' but nothing was drawn.

The sample draws three graphicPoints with callouts. I tried to make a polygon with the same points (and same spatialReference) as follows:


    AGSMutablePolygon* poly = [[AGSMutablePolygon alloc] initWithSpatialReference:self.mapView.spatialReference];
    [poly addRingToPolygon];
    [poly addPointToRing:[AGSPoint pointWithX:-9546541.78950715 y:4615710.12174574 spatialReference:nil]];
    [poly addPointToRing:[AGSPoint pointWithX:-9552294.6205 y:4618447.7069 spatialReference:nil]];
    [poly addPointToRing:[AGSPoint pointWithX:-9550988.22392791 y:4614761.34217867 spatialReference:nil]];
    [poly addPointToRing:[AGSPoint pointWithX:-9546541.78950715 y:4615710.12174574 spatialReference:nil]];
    graphic = [AGSGraphic graphicWithGeometry:poly symbol:nil attributes:nil infoTemplateDelegate:nil];
    [self.graphicsLayer addGraphic:graphic];
    [self.graphicsLayer dataChanged];

Only the three points were drawn...there was no polygon. Can someone please help? I am completely stuck...
0 Kudos
NimeshJarecha
Esri Regular Contributor
You are not seeing polygon on map because you have not set symbol. Either you have symbol set on graphic layer's renderer or set symbol to each graphic.

Just change code line as following...

graphic = [AGSGraphic graphicWithGeometryoly symbol:[AGSSimpleFillSymbol simpleFillSymbol] attributes:nil infoTemplateDelegate:nil];
[self.graphicsLayer addGraphic:graphic];

Hope this helps!

Regards,
Nimesh
0 Kudos
TomHicks
New Contributor II
Problem solved!  I added an instance of AGSSimpleFillSymbol as follows:

    //Create the AGSSimpleFillSymbol and set it�??s color
    AGSSimpleFillSymbol* myFillSymbol = [AGSSimpleFillSymbol simpleFillSymbol];
    myFillSymbol.color = [UIColor colorWithRed:0.7 green:0.1 blue:0.1 alpha:0.5];
   
    //Create the AGSSimpleLineSymbol used for the outline
    AGSSimpleLineSymbol* myOutlineSymbol = [AGSSimpleLineSymbol simpleLineSymbol];
    myOutlineSymbol.color = [UIColor redColor];
    myOutlineSymbol.width = 2;
   
    //set the outline property to myOutlineSymbol
    myFillSymbol.outline = myOutlineSymbol;

Then I used myFillSymbol when creating graphic:

    graphic = [AGSGraphic graphicWithGeometry:poly symbol:myFillSymbol attributes:nil infoTemplateDelegate:nil];
0 Kudos
NimeshJarecha
Esri Regular Contributor
Perfect! :)
0 Kudos