Hi, I'm using ArcGIS Javascript API 4.17 and it seems view.popup.selectedFeature does not return geometry where 4.16 did (looked at the request and it seems queryGeometries parameter is now set to false)

3424
17
10-09-2020 09:45 AM
ChristopheSuter
New Contributor III

Hi, I'm using ArcGIS Javascript API 4.17 and it seems view.popup.selectedFeature does not return geometry where 4.16 did. I looked at the request and it seems queryGeometries parameter is now set to false, but not for all layers.

This is quite a big problem since measuring from popup actions is not possible anymore.

Did anyone see the same behavior ?

0 Kudos
17 Replies
AnneFitz
Esri Regular Contributor

Hi Christophe, can you please provide a test-app that reproduces the issue you are seeing?

0 Kudos
HeatherGonzago
Esri Contributor

Hi, we did do some work with help with querying and performance issues but this should not pertain to this issue at all.  The geometry should be there already unless it's not querying for geometries on the layer. Could you please provide a test app showing the issue you are experiencing?

Thanks.

0 Kudos
HeatherGonzago
Esri Contributor

I played around with some of our samples and cannot see this issue, for example, Popup actions | ArcGIS API for JavaScript 4.17  is able to successfully access the selected feature's geometry and performs a measurement without an issues. We'll definitely need to see your app to figure out the issue at hand.

0 Kudos
ChristopheSuter
New Contributor III

Hi Heather,

I found where the problem is, if you do not specify outFields=['*'] when creating the featureLayer, then no geometry is returned on popup selected Feature.

Here are 2 samples:

https://www.topomat.ch/demo/popupFeature/working.html

https://www.topomat.ch/demo/popupFeature/not_working.html

This is still a problem when layers are not created in the code, but published in a webMap ...

Best,

Christophe

0 Kudos
ChristopheSuter
New Contributor III

Hi Heather,

I found where the problem is, if you do not specify outFields=['*'] when creating the featureLayer, then no geometry is returned on popup selected Feature.

Here are 2 samples:

Popup feature returns geometry 

Popup feature does not return geometry 

https://www.topomat.ch/demo/popupFeature/working.html

This is still a problem when layers are not created in the code, but published in a webMap ...

Best,

Christophe

0 Kudos
HeatherGonzago
Esri Contributor

Thank you Christophe, this should definitely not be happening. Let me look at this and see what may be going on. I appreciate your quick response with info.

-heather

0 Kudos
HeatherGonzago
Esri Contributor

Ok, this isn't a bug. The problem is because you need to make sure you specify the PopupTemplate's outfields as well.

I updated the non-working sample to include this and the geometry returns correctly now, see https://codepen.io/hgonzago/pen/ExyKZqB?editors=1000 .

There were some updates made at 4.17 to help with performance issues so this is probably why you see this problem. Prior to this though, we always recommend setting the outFields in the PopupTemplate. Going forward, if you wish to access the returned geometry like this, you must make sure that this is included.

We do discuss this in documentation, but I think we can probably make this easier to find and understand. I will make sure to include some additional information in our next doc update.

I hope this helps,

Heather

0 Kudos
ChristopheSuter
New Contributor III

Ok thanks Heather, but what is the solution if that same layer is defined in a webmap:

… new sample

https://www.topomat.ch/demo/popupFeature/webmap_not_working.html

0 Kudos
HeatherGonzago
Esri Contributor

Hi Christophe,

The performance work that was done removed some unnecessary geometry queries on the popup. Unfortunately, what worked in the past now needs to be slightly updated to get the geometries like before. In the prior samples, the geometry was included in either the layer or the popup's template. In your specific case, the layer isn't queried for geometries in order to draw features and the popup does not need to query for geometries because it does not need the geometry for anything within the popup, i.e. Arcade expressions. We won't query for the geometries unless they are needed such as in your application.

Here is a snippet showing how to do this in your example, https://codepen.io/hgonzago/pen/bGepYKW?editors=1000 

view.when(function () {
  webmap.when(function(response){
    returnedLayer = response.layers.find(function(layer){
     return layer.id === "SITG_OPENDATA_01_2709";
    });

    if (returnedLayer.popupTemplate.outFields == null ) {
      // set the outFields on the template
      returnedLayer.popupTemplate.outFields = ["*"];
    }

    //Now you have to wait for the viewModel to be active
    view.watch("popup.viewModel.active", function(){
      console.log(view.popup.selectedFeature.geometry.type);
    });

  });
});

 

I am definitely going to include this in our documentation to help avoid this confusion for any others later down the line. Thank you for questions and samples. //

0 Kudos