Select to view content in your preferred language

BaseMap tool & ArcGIS.com resources

1137
7
Jump to solution
08-17-2012 02:00 PM
TerryGiles
Frequent Contributor
I'm thinking about making a tool for my Silverlight app similar to the functionality of the 'Add BaseMap' button in ArcMap.  Watching the http requests in Fiddler while clicking that button in ArcMap you can see it makes calls to arcgis.com, similar to how ArcGIS Explorer Desktop does (specifically this - http://www.arcgis.com/sharing/search?f=json&sortField=name&sortOrder=asc&num=50&q=group:34ca4e3505f2...

This request returns a nice bit of JSON of the basemaps available, including a link to the thumbnail image which would be perferct for my idea.

Anyone know if there are any restrictions against using this kind of info from ArcGIS.com?

Thanks, Terry
0 Kudos
1 Solution

Accepted Solutions
DominiqueBroux
Esri Frequent Contributor
BasemapGalleryGroupQuery is just returning the groups that drive the gallery of basemaps, it's not directly returning the basemaps.
After getting the groups, you have to chain to another query looking for the items shared with the group.

Alternatively you can directly use SearchBasemapGalleryAsync which is doing that job for you.

View solution in original post

0 Kudos
7 Replies
DominiqueBroux
Esri Frequent Contributor
The Portal API, new at 3.0, is what you need to access web maps stored in arcgis.com (documentation)

There is a sample here : http://resources.arcgis.com/en/help/silverlight-api/samples/start.htm#PortalMetadata
0 Kudos
TerryGiles
Frequent Contributor
Thank you Dominique.  I'm just starting to migrate to 10.1 and v3.0 of the API so this is perfect.
0 Kudos
TerryGiles
Frequent Contributor
Hello again Dominique,

I upgraded to v3 of the API and am trying to use the ArcGISPortal class to accomplish what I described above.  I'm close but am missing something here.  I trying to use the PortalInfo's BaseMapGalleryGroupQuery to get an Enumeration of the basemaps, but my results are empty.  Can you take a quick look at the code below and let me know if this should work or am I going in the wrong direction?


            _Portal = new ArcGISPortal();
            _Portal.InitializeAsync("http://www.arcgis.com/sharing", (p, ex) =>
            {
                if (ex != null)
                {
                    txtMaps.Text = "Basemaps currently unavailable";
                    lbxBaseMaps.Visibility = Visibility.Collapsed;
                }
                else
                {
                    ArcGISPortalInfo pInfo = p.ArcGISPortalInfo;
                    SpatialSearchParameters param = new SpatialSearchParameters
                    {
                        QueryString = pInfo.BasemapGalleryGroupQuery  //QueryString is "title:\"ArcGIS Online Basemaps\" AND owner:esri_en"
                    };

                    p.SearchItemsAsync(param, (result, err) =>
                    {
                        if (err == null)
                        {
                            System.Diagnostics.Debug.WriteLine(result.Results.Count());   //Results is empty
                        }
                    });
                    

                    txtMaps.Text = "Select a Basemap";
                    lbxBaseMaps.Visibility = Visibility.Visible;
                }       
            });


Thank you,
Terry
0 Kudos
DominiqueBroux
Esri Frequent Contributor
BasemapGalleryGroupQuery is just returning the groups that drive the gallery of basemaps, it's not directly returning the basemaps.
After getting the groups, you have to chain to another query looking for the items shared with the group.

Alternatively you can directly use SearchBasemapGalleryAsync which is doing that job for you.
0 Kudos
TerryGiles
Frequent Contributor
Once again, thank you very much Dominique!

ArcGISPortalInfo::SearchBaseMapGalleryAsync is exactly what I was after.  Code below for those interested.


            _Portal = new ArcGISPortal();
            _Portal.InitializeAsync("http://www.arcgis.com/sharing", (p, ex) =>
            {
                if (ex != null)
                {
                    txtMaps.Text = "Basemaps currently unavailable";
                    lbxBaseMaps.Visibility = Visibility.Collapsed;
                }
                else
                {
                    ArcGISPortalInfo pInfo = p.ArcGISPortalInfo;
                    pInfo.SearchBasemapGalleryAsync(null,(items,err) =>
                    {
                        if (err != null)
                        {
                            txtMaps.Text = "Basemaps currently unavailable";
                            lbxBaseMaps.Visibility = Visibility.Collapsed;
                        }
                        else
                        {
                            txtMaps.Text = "Select a Basemap";
                            lbxBaseMaps.ItemsSource = items.Results;
                            lbxBaseMaps.Visibility = Visibility.Visible;
                        }
                    });
                }       
            });

0 Kudos
DominiqueBroux
Esri Frequent Contributor
Once again, thank you very much Dominique!


You are welcome.

I didn't notice early but you are using the REST end point http://www.arcgis.com/sharing while the recommended is http://www.arcgis.com/sharing/rest (see Remarks section in doc).

Probably not a problem for what you are doing today but may be a problem for future.

Sidenote : As arcgis.com is the default URL, you could as well pass a null Url:
_Portal.InitializeAsync(null, (p, ex) => .......
0 Kudos
TerryGiles
Frequent Contributor
Revised code below, which incorporates

  1. Dominique's comment re: passing in null in the Portal's InitializeAsync method

  2. using a SearchParameters object in the SearchBasemapGalleryAsync call.  Otherwise only 10 results are returned (currently should be 12)



            _Portal = new ArcGISPortal();
            _Portal.InitializeAsync(null, (p, ex) =>
            {
                if (ex != null)
                {
                    txtMaps.Text = "Basemaps currently unavailable";
                    lbxBaseMaps.Visibility = Visibility.Collapsed;
                }
                else
                {
                    SearchParameters param = new SearchParameters();
                    param.Limit = 20;
                    ArcGISPortalInfo pInfo = p.ArcGISPortalInfo;
                    pInfo.SearchBasemapGalleryAsync(param,(items,err) =>
                    {
                        if (err == null)
                        {
                            txtMaps.Text = "Basemap Options:";
                            lbxBaseMaps.ItemsSource = items.Results;
                            lbxBaseMaps.Visibility = Visibility.Visible;
                        }
                        else
                        {
                            txtMaps.Text = "Basemaps currently unavailable";
                            lbxBaseMaps.Visibility = Visibility.Collapsed;
                        }
                    });
                }       
            });

0 Kudos