Select to view content in your preferred language

Manually open Feature popup when recieve a message (from postmessage)

1192
3
Jump to solution
02-19-2021 12:58 AM
Gheeks
by
Emerging Contributor

Hello,

I'm trying to open the feature popup when my map is recieving a message:

 

window.addEventListener("message", function (event) {
   if (event?.data?.type === "external") {
      console.log(_getAllFeaturesRecursive(featureLayer,[]));
   }
});

 

 

By doing this, I know that I need to open my popup...

I was using a function "getAllFeaturesRecursives" that get all the features:

 

          const _getAllFeaturesRecursive = (layer, featuresSoFar) => {
          return layer
            .queryFeatures({
              start: featuresSoFar.length,
              num: layer.capabilities.query.maxRecordCount,
              outFields: ['*']
            })
            .then((results) => {
              if (
                results.exceededTransferLimit &&
                results.exceededTransferLimit === true
              ) {
                return _getAllFeaturesRecursive(layer, [
                  ...featuresSoFar,
                  ...results.features
                ]);
              } else {
                var p = Promise.resolve([...featuresSoFar, ...results.features]).then((feat) => {
                  console.log(feat[0]);
                  feat[0].layer.popupEnabled = false;
                  feat[0].layer.popupEnabled = true;
                });
              }
            });
          };

 

Gheeks_0-1613724993733.png

So I tried to put popupenable to true, but it seems to be true foreach layers...

Do you have any ideas to open the feature popup (with focus) manually (without direct events on the map?)

 

Thanks 🙂

 

0 Kudos
2 Solutions

Accepted Solutions
TommyBramble
Regular Contributor

You can call the .open() method of the mapView's popup and pass in the feature or content you want to display. Might be something like this...

mapView.popup.open({ location: feat[0].geometry, features: [feat[0]] });

https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#popup

https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Popup.html#open

 

View solution in original post

Gheeks
by
Emerging Contributor

Hm...It seems there was a problem with my method to get features, and also it seems to be useless:

Solution:

                var query = {
                  objectIds: [event.data.objectid],
                  outFields: ["*"],
                  returnGeometry: true
                };

                featureLayer.queryFeatures(query)
                  .then(function(response){
                    // close view popup if it is open
                    view.popup.close();
                    // Open the new popup
                    var feat = response.features[0];
                    view.popup.open({ location: feat.geometry, features: [feat] });
                  });
                // console

Special thanks to @TommyBramble  🙂

View solution in original post

0 Kudos
3 Replies
TommyBramble
Regular Contributor

You can call the .open() method of the mapView's popup and pass in the feature or content you want to display. Might be something like this...

mapView.popup.open({ location: feat[0].geometry, features: [feat[0]] });

https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#popup

https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Popup.html#open

 

Gheeks
by
Emerging Contributor

Hey, sorry for the late feedback, i was absent for a week.

I've tried your solution and it seems to works but not really, in fact, my feat[0}.geometry seems to be null...

That's weird.

0 Kudos
Gheeks
by
Emerging Contributor

Hm...It seems there was a problem with my method to get features, and also it seems to be useless:

Solution:

                var query = {
                  objectIds: [event.data.objectid],
                  outFields: ["*"],
                  returnGeometry: true
                };

                featureLayer.queryFeatures(query)
                  .then(function(response){
                    // close view popup if it is open
                    view.popup.close();
                    // Open the new popup
                    var feat = response.features[0];
                    view.popup.open({ location: feat.geometry, features: [feat] });
                  });
                // console

Special thanks to @TommyBramble  🙂

0 Kudos