Accessing title of default popup created for a SceneView

191
1
Jump to solution
01-06-2022 06:45 AM
AnnaPearson
New Contributor II

Is there a good way to access the properties of the default popup object created for a SceneView? (as in https://developers.arcgis.com/javascript/latest/api-reference/esri-views-SceneView.html#popup)

view.on("click", function (event) {
console
.log(view.popup); console.log(view.popup.id); console.log(view.popup.title);
}

By logging view.popup to the console (using the lines of code shown above) I can see that the properties exist because the below lines are logged to the console (part of the output from Line 2).

id: "17e2bf83e50-widget-1"

title: "k0"

I then log just the id property (Line 3) and it prints just the id property. However, if I try to log view.popup.title (Line 4), it logs 'null' to the console. Anything else I try to print out using console.log prints the same value found within view.popup. I originally thought I was missing something about how things work in JavaScript but after a query on stackoverflow it seems like maybe it has to do with how view.popup is constructed? Maybe that view.popup.title is made later in the code and doesn't technically exist at that moment when I'm trying to log it?

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ArnoFiva
Esri Contributor

Sounds like good old Heisenberg 🙂  But I think the log values you are witnessing are because they are evaluated during the click event. Without having the full source code, I assume when the click event fires, the view is still determining what feature to show in the popup or maybe still fetching title and other attributes from the server.

What works better is watching a specific property for changes:

view.popup.watch("title", () => {
  console.log(view.popup.title);
});

Or using the developer console to inspect the values directly when you see the popup is fully loaded. If "view" is not a global variable, this is one way to access it through the developer console (assuming you consume the API as an AMD module):

view = require("esri/views/View").views.getItemAt(0);
console.log(view.popup.title);

 

 

View solution in original post

1 Reply
ArnoFiva
Esri Contributor

Sounds like good old Heisenberg 🙂  But I think the log values you are witnessing are because they are evaluated during the click event. Without having the full source code, I assume when the click event fires, the view is still determining what feature to show in the popup or maybe still fetching title and other attributes from the server.

What works better is watching a specific property for changes:

view.popup.watch("title", () => {
  console.log(view.popup.title);
});

Or using the developer console to inspect the values directly when you see the popup is fully loaded. If "view" is not a global variable, this is one way to access it through the developer console (assuming you consume the API as an AMD module):

view = require("esri/views/View").views.getItemAt(0);
console.log(view.popup.title);