Select to view content in your preferred language

features widget not working?

385
4
Jump to solution
10-11-2024 09:27 AM
LefterisKoumis
Frequent Contributor

For some feature layers,  when you click on a feature, you expect the popup to be displayed on the features widget panel, but it just opens and closes the widget immediately! 

https://codepen.io/lkoumis1/pen/poXqjxR 

It's similar to the example posted here. The only difference is that I added a feature Layer instead of using a webmap.

https://developers.arcgis.com/javascript/latest/sample-code/sandbox/?sample=widgets-features 

 

0 Kudos
1 Solution

Accepted Solutions
LefterisKoumis
Frequent Contributor

Thank you Ken. After hours of working on this problem, found out that the issue was of how the REST service for this layer was published. After it was republished, the issue went away. However, you script assisted with faster loading of large datasets. 

View solution in original post

0 Kudos
4 Replies
KenBuja
MVP Esteemed Contributor

The map layer that you're providing doesn't have a popupTemplate defined, whereas the web map does. Once you add a template (like in this sample), the Features widget works as expected.

 

        const template = {
          title: 'This is a test'
        }

        const featureLayer = new FeatureLayer({
          url: "https://gis.cnra.ca.gov/arcgis/rest/services/Boundaries/CCED_AccessType/MapServer/0",
           outFields:['*'],
           popupTemplate: template
        });

 

 

Snag_f88fc6.png

0 Kudos
LefterisKoumis
Frequent Contributor

Thank you for the response @KenBuja . Yes, your solution works for that layer. I used that layer in my example because it is visible on the public. However, my issue is with another layer that I cannot share.

I am sharing the code of how I define the template, and a brief video to show the issue.

 

       const featureLayer = new FeatureLayer({
         url: "https://xyz/MapServer/0",
          outFields:['*'],
         
       });
        map.add(featureLayer);
        view.when(() =>{
          const popupTemplate = featureLayer.createPopupTemplate();
          featureLayer.popupTemplate = popupTemplate;
        })

 

 

0 Kudos
KenBuja
MVP Esteemed Contributor

I substituted another layer and the code would work sometimes, returning content in the Features widget, but it wasn't consistent. Sometimes it would throw the error "popupTemplate is null". Are you getting that in your console?

I changed the view.when to featureLayer.when and that seemed be more consistent with a layer that takes a while to load.

Snag_486a93.png

I also tried using an await function with the FeatureLayerView and that seemed pretty consistent also.

view.when(() =>{
  (async () => { 
    const layerView = await view.whenLayerView(featureLayer);
    await reactiveUtils.whenOnce(() => !layerView.updating);
    const popupTemplate = featureLayer.createPopupTemplate();
    popupTemplate.title = 'This is a test'; 
    featureLayer.popupTemplate = popupTemplate;
  })()
})

 

0 Kudos
LefterisKoumis
Frequent Contributor

Thank you Ken. After hours of working on this problem, found out that the issue was of how the REST service for this layer was published. After it was republished, the issue went away. However, you script assisted with faster loading of large datasets. 

0 Kudos