Search code examples
arcgisarcgis-js-api

Change the way the number of elements are shown on selecting a Point if multiple items exist at that point


Currently in ArcGIS Online if multiple items exist in a single point the template is shown like this

Multiple 1

Will I be able to view the details with the number of elements as a part of the template like this

Multiple 2


Solution

  • You can retrieve the number of selected features using Popup.featureCount.

    The following CodePen uses this property to provide a dynamic PopupTemplate.title: https://codepen.io/arnofiva/pen/5b532f8577d097107cf8040da57e0b97

    var template = layer.popupTemplate;
    var defaultTitle = template.title;
    
    // Compute popup title before it is shown
    template.title = function() {
      var total = view.popup.featureCount;
      if (total > 1) {
        return defaultTitle + " - Count: " + total + "";
      } else {
        return defaultTitle;
      }
    }
    

    Popup with dynamic title

    See the following ArcGIS API for JavaScript resources for more information on popups and widgets: