Select to view content in your preferred language

Possible to show more than on feature layer?

859
4
Jump to solution
09-27-2012 01:17 PM
BrendanMcKenney
Deactivated User
Typo in the Post Title. Sorry. Meant to say more than ONE feature layer.

I'm trying to add more than one feature layer to the mapView at a time. Is this possible? There are a total of 9 feature layers that could be shown at once if possible. Here is what I have tried already. It seems only the first layer is shown, and not subsequent layers. Any suggestions would be appreciated.



    self.incidentsLayer = [AGSFeatureLayer featureServiceLayerWithURL:[NSURL URLWithString:@"http://egisws02.nos.noaa.gov/ArcGIS/rest/services/MP/MPA_Inventory_Fishing/MapServer/1"] mode:AGSFeatureLayerModeOnDemand];     self.incidentsLayer.outFields = [NSArray arrayWithObject:@"*"];     self.incidentsLayer.infoTemplateDelegate = self.incidentsLayer;          self.restrictedLayer = [AGSFeatureLayer featureServiceLayerWithURL:[NSURL URLWithString:@"http://egisws02.nos.noaa.gov/ArcGIS/rest/services/MP/MPA_Inventory_Fishing/MapServer/2"] mode:AGSFeatureLayerModeOnDemand];     self.restrictedLayer.outFields = [NSArray arrayWithObject:@"*"];     self.restrictedLayer.infoTemplateDelegate = self.restrictedLayer;               [self.mapView addMapLayer:self.incidentsLayer withName:@"Incidents"];      [self.mapView addMapLayer:self.incidentsLayer withName:@"Restricted"];
0 Kudos
1 Solution

Accepted Solutions
NimeshJarecha
Esri Regular Contributor
Yes, your URL is incorrect. You should implement the AGSMapViewLayerDelegate's method to know why your layer fails to load.

Change,
http://egisws02.nos.noaa.gov/ArcGIS/rest/services/MP/MPA_Inventory_Fishing/MapServer/7
To,
http://egisws02.nos.noaa.gov/ArcGIS/rest/services/MPA/MPA_Inventory_Fishing/MapServer/7

Regards,
Nimesh

View solution in original post

0 Kudos
4 Replies
NimeshJarecha
Esri Regular Contributor
Yes, it is possible to add multiple feature layers to map. You are seeing only one layer because you are adding one layer twice. 😞 Just change it as following...

[self.mapView addMapLayer:self.incidentsLayer withName:@"Incidents"];
[self.mapView addMapLayer:self.restrictedLayer withName:@"Restricted"];

Regards,
Nimesh
0 Kudos
BrendanMcKenney
Deactivated User
Hi Nimesh,

Thanks for the reply. I did have a simple mistake there, yes. I tried again tonight, and am still only getting one feature layer to show. I even tried adding a second feature layer to the RelatedRecordEditingSample and can still only get the first feature layer to show. Can you see anything that is wrong with this:

#import "RelatedRecordEditingSampleViewController.h"

#import <ArcGIS/ArcGIS.h>
#import "NotesViewController.h"
#import "LoadingView.h"

//this is the url for the basemap. 
#define kBaseMapServiceURL @"http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"

//url for the incidents layer
#define kIncidentsLayerURL @"http://egisws02.nos.noaa.gov/ArcGIS/rest/services/MPA/MPA_Inventory_Fishing/MapServer/1"



#pragma mark - Class Extension

@interface RelatedRecordEditingSampleViewController() 

@property (nonatomic, retain) IBOutlet AGSMapView *mapView;
@property (nonatomic, retain) AGSFeatureLayer *incidentsLayer;
@property (nonatomic, retain) AGSFeatureLayer *restrictedLayer;
@property (nonatomic, retain) AGSPopupsContainerViewController* popupVC;
@property (nonatomic, retain) UIBarButtonItem* customActionButton;
@property (nonatomic, retain) LoadingView* loadingView;

@end

#pragma mark - Implementation

@implementation RelatedRecordEditingSampleViewController


@synthesize mapView = _mapView;
@synthesize incidentsLayer = _incidentsLayer;
@synthesize popupVC = _popupVC;
@synthesize loadingView = _loadingView;
@synthesize customActionButton = _customActionButton;
@synthesize restrictedLayer = _restrictedLayer;


#pragma mark -  UIView methods

- (void)viewDidLoad {
    
    //creating a tiled service with the base map url
    NSURL *mapUrl = [NSURL URLWithString:kBaseMapServiceURL];
 AGSTiledMapServiceLayer *tiledLyr = [AGSTiledMapServiceLayer tiledMapServiceLayerWithURL:mapUrl];
    
    //add the tiled layer to the map view
 [self.mapView addMapLayer:tiledLyr withName:@"Tiled Layer"];
    
    //Zooming to an initial envelope with the specified spatial reference of the map.
    //this is the San Francisco extent. 
 AGSSpatialReference *sr = [AGSSpatialReference spatialReferenceWithWKID:102100];
 AGSEnvelope *env = [AGSEnvelope envelopeWithXmin:-13639984
                                                ymin:4537387
                                                xmax:-13606734
                                                ymax:4558866 
         spatialReference:sr];
 [self.mapView zoomToEnvelope:env animated:YES];
    
    //Set up the map view
 self.mapView.calloutDelegate = self;
 
    //setup the incidents layer as a feature layer and add it to the map
    self.incidentsLayer = [AGSFeatureLayer featureServiceLayerWithURL:[NSURL URLWithString:kIncidentsLayerURL] mode:AGSFeatureLayerModeOnDemand]; 
    self.incidentsLayer.outFields = [NSArray arrayWithObject:@"*"];
    self.incidentsLayer.infoTemplateDelegate = self.incidentsLayer;
    
    self.restrictedLayer = [AGSFeatureLayer featureServiceLayerWithURL:[NSURL URLWithString:@"http://egisws02.nos.noaa.gov/ArcGIS/rest/services/MP/MPA_Inventory_Fishing/MapServer/7"] mode:AGSFeatureLayerModeOnDemand];
    self.restrictedLayer.outFields = [NSArray arrayWithObject:@"*"];
    self.restrictedLayer.infoTemplateDelegate = self.restrictedLayer;
    
    [self.mapView addMapLayer:self.incidentsLayer withName:@"Incidents"];
     [self.mapView addMapLayer:self.restrictedLayer withName:@"Restrictions"];
    
    //setting the custom action button which will be later used to display related notes of an incident
//    self.customActionButton  = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"pencil.png"] style:UIBarButtonItemStyleBordered target:self action:@selector(displayIncidentNotes)] autorelease];
 
    [super viewDidLoad];
}
0 Kudos
NimeshJarecha
Esri Regular Contributor
Yes, your URL is incorrect. You should implement the AGSMapViewLayerDelegate's method to know why your layer fails to load.

Change,
http://egisws02.nos.noaa.gov/ArcGIS/rest/services/MP/MPA_Inventory_Fishing/MapServer/7
To,
http://egisws02.nos.noaa.gov/ArcGIS/rest/services/MPA/MPA_Inventory_Fishing/MapServer/7

Regards,
Nimesh
0 Kudos
BrendanMcKenney
Deactivated User
Hi Nimesh,

Once again, a typo bites me in the butt. Thanks for pointing that out. I'll read up on AGSMapViewLayerDelegate method this weekend. Thanks again.

Brendan
0 Kudos