Select to view content in your preferred language

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)

4169
17
10-09-2020 09:45 AM
ChristopheSuter
Regular Contributor

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
ChristopheSuter
Regular Contributor

Hi Heather,

Thanks again for that, but this looks a bit more like a workaround for me, I agree performances improvements at 4.17 are remarkable, but it is a little difficult to link outfields of popup template with geometry. As in query, a Boolean “returnGeometry” property would be easier to use (and to understand) at 4.17+.

But thanks for the time you spent on that

Best,

Kishore
Frequent Contributor

Hi Heather,

We still have the same problem in 4.20 API when we are using hosted feature layer with webmap. I tried updating the code as below:

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 = ["*"];
      returnedLayer.popupTemplate.returnGeometry = true;
    }
    //Now you have to wait for the viewModel to be active
    view.watch("popup.viewModel.active", function(){
      console.log(view.popup.selectedFeature.geometry.type);
    });
  });
});

by setting the popup template return geometry true,  still it is not returning the geometry. I verified in the network logs, the query is overwriting the return geometry to false.

Any suggestions or work around?

Kishore

Regards,
Kishore
0 Kudos
JohnGrayson
Esri Regular Contributor

As you've noted above some layer properties are loaded async, so I like to wait for a layer to be loaded before I try to update the properties.  If this doesn't solve it then maybe you have a different problem from the original issue so starting a new question might help, and having a codepen (or similar) so we can experience the issue would be helpful.

view.when(()=>{
  returnedLayer = view.map.layers.find((layer)=>{
    return layer.id === "SITG_OPENDATA_01_2709";
  });
  returnedLayer.load().then(()=>{
    if (returnedLayer.popupTemplate.outFields == null ) {
      // set the outFields on the template
      returnedLayer.popupTemplate.outFields = ["*"];
      returnedLayer.popupTemplate.returnGeometry = true;
    }
  });
  
  //Now you have to wait for the viewModel to be active
  view.watch("popup.viewModel.active",()=>{
    console.log(view.popup.selectedFeature.geometry.type);
  });
});

 

Kishore
Frequent Contributor

Thank you John,

I found the issue. it is related to my environment and data. your code changes are helpful.

Kishore 

Regards,
Kishore
0 Kudos
HeatherGonzago
Esri Contributor

Hi Christophe,

Thanks for your help and suggestion. We will take a look at this and see if there is any way we could make this easier to implement for our developers.

Thanks,

-Heather

0 Kudos
ZaidOdeh
Emerging Contributor

This is still not working for me on the webmap that has layers saved on it. I get geometry as null, and I really do not wish to query the feature from layer just to get it's geometry.  Any ideas on how to resolve this ? 

  layer.load().then(() => {
        const template = new PopupTemplate({
          returnGeometry: true,
          outFields: ["*"],
          title: setTitleName,
          content: [contentPromise],
          actions: [],
        });

        template.overwriteActions = true;
        template.actions.add(addToSelection);
        template.actions.add(zoomTo);
        template.actions.add(panTo);
        layer.defaultPopupTemplate.returnGeometry = true;
        layer.popupTemplate = template;}

mapView.popup.watch("selectedFeature", (ftr) => {
// ftr geometry is null
});
}
0 Kudos
LaurenBoyd
Esri Contributor

Hi @ZaidOdeh -

I am not seeing the issue you mention above when testing. Could provide a codepen showing the issue?

Thanks!

Lauren
0 Kudos
ZaidOdeh
Emerging Contributor

Hello @LaurenBoyd. I am using the Javascript API 4.23.7. 
I am unable to share a code pen code because the web map and services are private on a local host, so there is no way for me to share them with you.

0 Kudos