Select to view content in your preferred language

Loading ajax content into infoWindow

1575
4
Jump to solution
05-27-2013 08:22 PM
JimWharton
Occasional Contributor
I'm loading a bunch of points from JSON when my map loads. I create a graphic for each from a lat/lon pair. When a user clicks a point, I'd like to fire off a query based on a custom ID attribute I store with the graphic. I'd like to make a JSON request to the same server and pull back another JSON object to populate the infoWindow.

My problem comes in because due to the async nature of Javascript, my "details" JSON object isn't ready while creating the initial info Template. I can't find an event to latch onto to fire off the query. If I attach to the onShow event, I have no knowledge of what graphic I clicked, and that event only fires as long as there are no open info windows (users do click on other map graphics while info windows are open... there's no event for that use case)

I've hunted around for other examples of this, it seems like it would be a common thing.
0 Kudos
1 Solution

Accepted Solutions
StephenLead
Honored Contributor
I'm loading a bunch of points from JSON when my map loads. I create a graphic for each from a lat/lon pair. When a user clicks a point, I'd like to fire off a query based on a custom ID attribute I store with the graphic. I'd like to make a JSON request to the same server and pull back another JSON object to populate the infoWindow.

My problem comes in because due to the async nature of Javascript, my "details" JSON object isn't ready while creating the initial info Template. I can't find an event to latch onto to fire off the query.


An option could be to reorganise your points into a featureLayer based on a featureCollection, as explained at http://help.arcgis.com/en/webapi/javascript/arcgis/jsapi/featurelayer.html#featurelayer2

If you were able to load the "details" object from the original JSON at the same time, there'd be no need to make a second request for this information.

Alternatively, you'd at least have a better mechanism for tying the original point to the second JSON request, based on a common ID.

View solution in original post

0 Kudos
4 Replies
StephenLead
Honored Contributor
I'm loading a bunch of points from JSON when my map loads. I create a graphic for each from a lat/lon pair. When a user clicks a point, I'd like to fire off a query based on a custom ID attribute I store with the graphic. I'd like to make a JSON request to the same server and pull back another JSON object to populate the infoWindow.

My problem comes in because due to the async nature of Javascript, my "details" JSON object isn't ready while creating the initial info Template. I can't find an event to latch onto to fire off the query.


An option could be to reorganise your points into a featureLayer based on a featureCollection, as explained at http://help.arcgis.com/en/webapi/javascript/arcgis/jsapi/featurelayer.html#featurelayer2

If you were able to load the "details" object from the original JSON at the same time, there'd be no need to make a second request for this information.

Alternatively, you'd at least have a better mechanism for tying the original point to the second JSON request, based on a common ID.
0 Kudos
JimWharton
Occasional Contributor
An option could be to reorganise your points into a featureLayer based on a featureCollection, as explained at http://help.arcgis.com/en/webapi/javascript/arcgis/jsapi/featurelayer.html#featurelayer2

If you were able to load the "details" object from the original JSON at the same time, there'd be no need to make a second request for this information.

Alternatively, you'd at least have a better mechanism for tying the original point to the second JSON request, based on a common ID.


Cool, I'll check it out. Currently I've added a click handler on the graphics layer which returns the graphic object that was clicked. I can use that and set the innerHTML property of one of my DIVs inside my infoWindow. Your solutions sounds more elegant.

Thanks,
-Jim
0 Kudos
KellyHutchins
Esri Notable Contributor
Jim,

Here's a link to a sample that illustrates the feature collection approach Steve suggested:

http://help.arcgis.com/en/webapi/javascript/arcgis/jssamples/fl_featureCollection.html

The sample shows how to load photo information from Flickr and display it on the map. When the location is clicked the photo information is displayed in a popup window.
0 Kudos
JimWharton
Occasional Contributor
That's great! Thank you so much!

-Jim
0 Kudos