AnsweredAssumed Answered

ArcGIS Polygon drawing issue with iPhone

Question asked by hassan.malik@eiconix.com on Jan 19, 2015
Latest reply on Jan 21, 2015 by Gagandeep_Singh-esristaff

Hi,  I am new on ArcGIS iPhone platform. I have already developed a iPhone application, app was using MapKit framework for Overlays[Polylines and Polygons] drawing but due to some issues we are replacing Apple Maps SDK with ArcGIS IOS map. But I am getting few issues with ArcGIS IOS Maps.

 

1) I am trying to draw the Polygon Objects on ArcGIS map but its not appearing/drawing in correct shape and on correct location. On Apple map Polygons were drawing in Square shape but on ArcGIS iPhone Map polygons are showing as "Infinite Lines". [ I have attached the Output of ArcGIS Map and Apple Maps ]

 

## My Code

 

- (void)viewDidLoad {

   

    [super viewDidLoad];

   

    NSURL* url = [NSURL URLWithString:@"https://gis.zoetermeer.nl/arcgis/rest/services/Public/GBKZ_Prod/MapServer/"];

    AGSTiledMapServiceLayer *tiledLayer = [AGSTiledMapServiceLayer tiledMapServiceLayerWithURL:url];

   

    tiledLayer.delegate = self;

   

    [self.mapView addMapLayer:tiledLayer withName:@"Basemap Tiled Layer"];

}

 

- (void) layerDidLoad: (AGSLayer*) layer{

   

    NSLog(@"Layer added successfully");

       

        AGSGraphicsLayer* myGraphicsLayer = [AGSGraphicsLayer graphicsLayer];

       

        [self.mapView addMapLayer:myGraphicsLayer withName:@"Graphics Layer"];

       

        NSLog(@"%i",myGraphicsLayer.spatialReferenceStatusValid);

       

        AGSSpatialReference *specailRefference = [AGSSpatialReference spatialReferenceWithWKID: 28992];

       

        NSString *coordinateString = @"4.4998839821275 52.066336122032, 4.499855 52.066286, 4.499792 52.066176, 4.499696 52.066014, 4.499631 52.066002, 4.499611 52.065966, 4.499604 52.065862, 4.499448 52.065609, 4.499412 52.065552, 4.499407 52.065543, 4.499399 52.065536, 4.499389 52.065529, 4.499378 52.065524, 4.4993733686962 52.065522931238, 4.4993733686962 52.066336122032";

       

        NSString *coordinateString2 = @"4.4991002778594 52.065436800426, 4.499085 52.065422, 4.499100 52.065386, 4.499177 52.065316, 4.499370 52.065273, 4.499362 52.065259, 4.499053 52.065327, 4.498905 52.065360, 4.498794 52.065385, 4.498657 52.065415, 4.498647 52.065418, 4.498638 52.065423, 4.498632 52.065429, 4.498629 52.065436, 4.498629 52.065436800426";

       

        NSString *coordinateString3 = @"4.4993733686962 52.075329338091, 4.5008878063918 52.075329338091, 4.5008878063918 52.074430016486, 4.4993733686962 52.074430016486";

       

       

        AGSMutablePolygon *polyGon1 = [self getpolygon:coordinateString];

       

        AGSMutablePolygon *polyGon2 = [self getpolygon:coordinateString2];

       

        AGSMutablePolygon *polyGon3 = [self getpolygon:coordinateString3];

       

        CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(52.066002,4.499631);

       

        AGSPoint* gpsPoint = [[AGSPoint alloc] initWithX:coordinate.longitude

                                                       y:coordinate.latitude

                                        spatialReference:[AGSSpatialReference wgs84SpatialReference]];

       

        AGSGeometryEngine* engine = [AGSGeometryEngine defaultGeometryEngine];

       

        AGSPoint* mapPoint = (AGSPoint*) [engine projectGeometry:gpsPoint

                                              toSpatialReference:specailRefference];

       

        [self.mapView zoomToGeometry:mapPoint withPadding:100 animated:YES];

       

        AGSGraphic *graphic1 = [[AGSGraphic alloc] initWithGeometry:polyGon1 symbol:[self barrierSymbol] attributes:nil];

        [myGraphicsLayer addGraphic:graphic1];

       

        AGSGraphic *graphic2 = [[AGSGraphic alloc] initWithGeometry:polyGon2 symbol:[self barrierSymbol]  attributes:nil];

        [myGraphicsLayer addGraphic:graphic2];

       

        AGSGraphic *graphic3 = [[AGSGraphic alloc] initWithGeometry:polyGon3 symbol:[self barrierSymbol]  attributes:nil];

        [myGraphicsLayer addGraphic:graphic3];

}

 

- (AGSCompositeSymbol*)barrierSymbol {

   

    AGSCompositeSymbol *cs = [AGSCompositeSymbol compositeSymbol];

   

    AGSSimpleLineSymbol *sls = [AGSSimpleLineSymbol simpleLineSymbol];

    sls.color = [UIColor greenColor];

    sls.style = AGSSimpleLineSymbolStyleSolid;

    sls.width = 20;

   

    AGSSimpleFillSymbol *sfs = [AGSSimpleFillSymbol simpleFillSymbol];

    sfs.outline = sls;

    sfs.style = AGSSimpleFillSymbolStyleHorizontal;

    sfs.color = [UIColor darkTextColor];

    [cs addSymbol:sfs];

   

    return cs;

}

 

-(AGSMutablePolygon*)getpolygon:(NSString*)coordinateString{

   

    AGSSpatialReference *specailRefference = [AGSSpatialReference spatialReferenceWithWKID: 28992];

    AGSMutablePolygon *polyGon = [[AGSMutablePolygon alloc] initWithSpatialReference:specailRefference];

    [polyGon addRingToPolygon];

   

    NSArray *tokens = [coordinateString componentsSeparatedByString:@","];

    for (int k=0; k<[tokens count]; k++) {

       

        NSString *latlong = [tokens objectAtIndex:k];

        NSArray *latlongArray = [latlong componentsSeparatedByString:@" "];

       

        NSString *longi = [latlongArray objectAtIndex:0];

        double longVal = [longi doubleValue];

       

        NSString *lati = [latlongArray objectAtIndex:1];

        double latVal = [lati doubleValue];

       

       

        CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latVal, longVal);

       

        AGSPoint* gpsPoint = [[AGSPoint alloc] initWithX:coordinate.longitude

                                                       y:coordinate.latitude

                                        spatialReference:[AGSSpatialReference wgs84SpatialReference]];

       

        AGSGeometryEngine* engine = [AGSGeometryEngine defaultGeometryEngine];

       

        AGSPoint* mapPoint = (AGSPoint*) [engine projectGeometry:gpsPoint

                                              toSpatialReference:specailRefference];

       

        [polyGon addPointToRing:mapPoint];

    }

   

    return polyGon;

}

Attachments

Outcomes