AnsweredAssumed Answered

PopupTemplate with Custom Content. Finding xy of Selected Feature.

Question asked by billm889 on Jan 23, 2020
Latest reply on Jan 24, 2020 by billm889

 This is a javascript api app with custom content for the popupTemplate. A custom function is used to build the content. When the function is called, by default, the selected feature is passed in. In this case, it is a polygon.


Finding normal map service attributes is no problem. For these I'm able to use both of the following calls.

feature.graphic.attributes.GL // works fine
feature.graphic.getAttribute("GL")); // works fine


Problem: I'm trying to get the x,y of the centroid of the selected feature, in map units. It seems that everything having to do with geometry of this feature is undefined.


Using ArcGIS javascript api 4.13


My app is based on this esri sample

Here's my code that doesn't return x,y
      let buildPopupContent; // fn used later to build popup content.
        let popupTemplate = {
          title: "Airport Tier: {Tier}",


        // When the feature is clicked, this function is called. The feature is passed into the function.
        function buildPopupContent (feature) {

          let poly = feature.graphic.geometry;
            alert("x " + poly.centroid.x); // undefined

          var centerPoint = feature.graphic.geometry.getExtent().getCenter(); // Unable to get property 'getExtent' of undefined or null reference
          alert("x " + centerPoint.x);