How do you programmatically retrieve public maps from a group in AGOL?

510
3
12-23-2019 12:43 PM
SkylerKroll
New Contributor II

Hello. I had asked a question a couple of weeks ago about retrieving map items from a group in AGOL. The example I was given worked, but I need to get public times within a group. How would I go about doing this? I know the group Id, but I'm not sure how to query said group to get the items. Thanks. 

3 Replies
KellyHutchins
Esri Frequent Contributor

You can use the queryItems method on PortalGroup to query for items in the group: PortalGroup | ArcGIS API for JavaScript 4.14 

SkylerKroll
New Contributor II

Okay. Thank you. I will give the documentation a look. 

SkylerKroll
New Contributor II

Hi, Kelly. I'm having trouble with how to structure the syntax to query the items and populate the carousel with the map thumbnails. Can you help me along? Am I missing something? 

 <script type = "text/javascript">
  require([
    "esri/core/urlUtils",
    "esri/portal/Portal",
    "esri/portal/PortalGroup",
    "esri/identity/OAuthInfo",
    "esri/identity/IdentityManager",
    "esri/portal/PortalQueryParams"
  ], function (urlUtilsPortalPortalGroupOAuthInfoesriIdPortalQueryParams) {

    urlUtils.addProxyRule({
              urlPrefix: "https://www.arcgis.com",
              proxyUrl: "https://localhost/dotnet/proxy.ashx"
          });

  
    displayItems();
   
    function displayItems() {

      var portalGroup = new PortalGroup({
        
        id: "3Ab1689d3d9dab474caa8a9cb4785a244f",
        owner: "Rocket350",
        portalUrl: "https://rocket350.maps.arcgis.com"
      });

        // Query the group items from portalGroup above
        portalGroup.queryItems().then(populateCarousel);
      
    }

    function populateCarousel(items) {
      //var htmlFragment = "";
      index = 0;
      items.results.forEach(function (item) {
        index += 1;
        if (item.type == "Web Map") {
          console.log(item.type);
          console.log(item.thumbnailUrl);
          //Sconsole.log(item.thumbnailUrl);
          // htmlFragment +=
          //   '<div class="esri-item-container">' +
          //   (item.thumbnailUrl
          //     ? '<div class="esri-image" style="background-image:url(' +
          //     item.thumbnailUrl +
          //     ');"></div>'
          //     : '<div class="esri-image esri-null-image">Thumbnail not available</div>') +
          //   (item.title
          //     ? '<div class="esri-title">' + (item.title || "") + "</div>"
          //     : '<div class="esri-title esri-null-title">Title not available</div>') +
          //   "</div>";
          $('<div class="carousel-item"><img src="'item.thumbnailUrl+'" width="50%"></div>').appendTo('.carousel-inner')
          console.log(index);
          
        }
        else {
          console.log(item.type);
        }
      });
      $('.carousel-item').first().addClass('active');
      $('.carousel-indicators > li').first().addClass('active');
      $('#mapCarousel').carousel();
    }
  });
</script>
0 Kudos