Select to view content in your preferred language

display popup upon adding graphic on map

1137
4
04-13-2022 04:11 PM
LefterisKoumis
Frequent Contributor

how to display the popup for a graphic when is added to the map, eliminating the need to click on it.

Tried but didn't display.

 

view.graphics.add(thegraphic);
            view.popup.open({
              features: [thegraphic],  // array of graphics
              fetchFeatures: true  //fetch the content of this feature and display it
            });

 

 

0 Kudos
4 Replies
YObaidat
Occasional Contributor

I think you're missing here the location property which tells the popup where to show

 

view.graphics.add(thegraphic);
            view.popup.open({
              features: [thegraphic],
              fetchFeatures: true,
              location:thegraphic
            });

 

if your geometry is polygon you need to pass centroid to the location

view.graphics.add(thegraphic);
            view.popup.open({
              features: [thegraphic],
              fetchFeatures: true,
              location:thegraphic.centroid
            });

 

0 Kudos
LefterisKoumis
Frequent Contributor

THank you. Still didn't open.

As an alternate, I am thinking to disable popups and just display the calcite card with popup content.

0 Kudos
LaurenBoyd
Esri Contributor

Hi @LefterisKoumis ,

This codepen shows the popup being manually opened after the graphic is added to the View: https://codepen.io/laurenb14/pen/dyJgeoL?editors=1000 The location needs to be the geometry of the graphic, not the graphic itself.

If you're still not able to get it to work, could you share a codepen showing the issue? Thanks!

Lauren
0 Kudos
LefterisKoumis
Frequent Contributor

Thank you for your response. However, my workflow is a bit more complex than your example.

I am trying to re-write and duplicate the functionality of another app that I scripted in dojo and ArcGIS API 3.x. You can see the app at: https://svctenvims.dot.ca.gov/pm_tools/

To follow the workflow  there is no need to click the other tabs. 

So, zoom in the map until to be at the 600 feet scale and click on any of the highways in California. If you don't zoom close enough, you will get an error. When you click, you will see a red mark and a green flag. The red flag shows the exact the location of the clicked location and the green flag shows the nearest postmile location from the highway. As you can see, the side bar shows up upon clicking and it displays the template content of the green flag point. The script workflow is: When you click, it creates the red mark point and it displays it. Also, it continues to call REST services to obtain the coordinates for the nearest postmile location. Once it gets the response of the request, it creates the new graphics with the popup template and the green flag symbol. I tried to use the view.popup.open with the graphic associated with the postmile once it is rendered but it doesn't display. 

0 Kudos