basemap gallery

3939
11
Jump to solution
05-07-2012 02:49 PM
LukePhilips
New Contributor III
Is there equivalent functionality in the iOS api to get the standard ESRI base map gallery like you see in ArcGIS Online and the other web API's?
0 Kudos
1 Solution

Accepted Solutions
NimeshJarecha
Esri Regular Contributor
You do not need to contract a URL. If AGSPortalItem::thumbnailFileName property is not NIL then you should execute AGSPortalItem's fetchThumbnail method. Once, that successfully execute, you will get thumbnail image in portalItem:operation:didFetchThumbnail: delegate method of AGSPortalItemDelegate.

Also, once that method execute successfully, you will get portal item thumbnail in AGSPortalItem's thumbnail property.

Hope this helps!

Regards,
Nimesh

View solution in original post

0 Kudos
11 Replies
NimeshJarecha
Esri Regular Contributor
Yes, it's available. You should use the Portal API.

The AGSPortalInfo::basemapGalleryGroupQuery property provides a query string. Here are the steps you need to follow to get all the base maps..

1. Create AGSPortalQueryParams object with method queryParamsWithQuery by passing the basemapGalleryGroupQuery.
2. Use AGSPortal's findGroupsWithQueryParams to find the group.
3. Create another AGSPortalQueryParams object with result group id.
    AGSPortalQueryParams *queryParams = [AGSPortalQueryParams queryParamsForItemsInGroup:@"<group_id>"];
4. Use AGSPortal's findItemsWithQueryParams method to find item's of the group. The returned results will be all base maps as AGSPortalItem array.

Hope this helps!

Regards,
Nimesh
0 Kudos
LukePhilips
New Contributor III
I'm sure I'm close... but seems like the queryParams isn't being populated and the findGroupsWithQueryParams isn't firing...
I've got in the .h:
@interface MainViewController : UIViewController <AGSMapViewLayerDelegate, AGSPortalDelegate> {
...
}


and in the .m
- (void)viewDidLoad {
....

    NSURL *url = [NSURL URLWithString:@"http://www.arcgis.com"];
    AGSPortal *portal = [[[AGSPortal alloc] initWithURL:url credential:nil] autorelease];
    portal.delegate = self;
    AGSPortalQueryParams *queryParam = [AGSPortalQueryParams queryParamsWithQuery:portal.portalInfo.basemapGalleryGroupQuery];   
    [portal findGroupsWithQueryParams:queryParam];
}

I also have logging in the portalDidLoadand the portal: didFindGroups: and nothing seems to be happening...
0 Kudos
NimeshJarecha
Esri Regular Contributor
Okay..there are two issues here..

1. You are autoreleasing the AGSPortal object.
What does that mean? - By the time portal loads it is released and delegate won't fire.
What to do? - Create a retain property of AGSPortal.

2. You are trying to get the portalInfo from portal before it's finish loading. You won't get anything.
What to do? - You should move following code in the portalDidLoad.

AGSPortalQueryParams *queryParam = [AGSPortalQueryParams queryParamsWithQuery:portal.portalInfo.basemapGalleryGroupQuery];  
[portal findGroupsWithQueryParams:queryParam];

Hope this helps!

Regards,
Nimesh
0 Kudos
LukePhilips
New Contributor III
Thanks, that got it all. I'm sure once I'm done with my questions you'll have all the documentation you need to update the API reference.. 🙂
How is the Portal Sample coming along? looks like it will cover most of my questions.
Once I have the portalItems, how do I add them as 'base maps' / layers to my map? If I take one portalItem as an example, like the Imagery service, is there the URI information to create a AGSTiledMapSericeLayer or do we use a web map and add that into the mapView?
0 Kudos
NimeshJarecha
Esri Regular Contributor
Yes, portal sample will answer all your questions.

It depends what you want to do...

1. If you want just tiled layer out of it then you can initiate AGSWebMap with webMapWithPortalItem: method and openInToMapView.
2. If you want to replace base map in your existing web map then you can initiate AGSWebMap with webMapWithPortalItem: method and use openIntoMapView:withAlternateBaseMap: method on existing web map.

Regards,
Nimesh
0 Kudos
LukePhilips
New Contributor III
Using the resetMapView:NO it still resets the map view extent, as well the map item isn't inserted as a base map, but instead as an operational layer on top of all the other operational layers.
-(IBAction)baseMapToggle:(id)sender
{
    
    AGSPortalItem *item = [self.baseMapItems objectAtIndex:6];
    AGSWebMap* webMap = [[AGSWebMap alloc] initWithPortalItem:item];
    webMap.delegate = self;
}

- (void) webMapDidLoad:(AGSWebMap*) webMap {
    //webmap data was retrieved successfully
    [webMap openIntoMapView:self.mapView withAlternateBaseMap:[webMap baseMap] resetMapView:NO];
    
}


my previous means of cycling the base map is similar to other forum posts
[self.mapView removeMapLayerWithName:@"Base Map"];
[self.mapView insertMapLayer:self.baseMapLayer withName:@"Base Map" atIndex:0];
0 Kudos
NimeshJarecha
Esri Regular Contributor
Are you working with other web map? Not the one which you are creating from portal item? If no, you can not use openIntoMapView:withAlternateBaseMap. You should rather create a AGSTiledMapServiceLayer from base map url and insert it at index 0.

- (void) webMapDidLoad:(AGSWebMap*) webMap {
    //webmap data was retrieved successfully
   
    [self.mapView removeMapLayerWithName:@"Base Map"];
    AGSWebMapLayerInfo *baseMapLayer = [webMap.baseMap.baseMapLayers objectAtIndex:0];
    self.baseMapLayer = [AGSTiledMapServiceLayer tiledMapServiceLayerWithURL:baseMapLayer.URL];
    [self.mapView insertMapLayer:self.baseMapLayer withName:@"Base Map" atIndex:0];
}

Hope this make things clear to you!

Regards,
Nimesh
0 Kudos
LukePhilips
New Contributor III
Nimesh,
Thanks again, everything has been clear and helpful. I was almost expecting an answer like you had since my map was not originally a web map. I assume with this process I have to inspect each baseMap returned from ArcGIS Online and handle them appropriately as the Bing maps and the OpenStreetMap won't have URL's like the TiledMapServices.
0 Kudos
NimeshJarecha
Esri Regular Contributor
To handle the bing and open street maps you should check the layerType property of AGSWebMapLayerInfo.

Regards,
Nimesh
0 Kudos