Launch webmap popup programmatically

5513
12
Jump to solution
05-14-2013 08:17 AM
by Anonymous User
Not applicable
Original User: zconlen

Hi,
My application consumes a webmap, which is where the popups are designed and configured. A feature of the app is for a user to select an asset from a combo box and the map will zoom to that feature on the map, highlight it and open the popup for that feature. I have the zoom to working, but struggling to get the popup to behave as desired.

I'm calling the show method of infoWindow, like
map.infoWindow.show(screenPoint);  


The results vary. If no feature has been identified previously, I get an empty unformated popup.
[ATTACH=CONFIG]24297[/ATTACH]

If a feature has previously been selected, I get the formatted popup, at the correct location, but showing the information for the previous manual identify.
[ATTACH=CONFIG]24299[/ATTACH]

As you can see, in the second scenario, the wrong feature is highlighted, and the information in the popup corresponds to that wrong feature (the pipe to the west), not the manhole which the popup is supposed to be showing. It is positioned correctly though.

It seems that the popup displays information for the "selected" feature. So, perhaps I need to first select the desired feature, but not sure how.

Obviously, I want to avoid trying to programmatically re-create the popup and the highlighting that is used by default in the webmap. Must be an easier way.

Here is the function which is supposed to handle this. Results are from a query task, which will return one feature only:
//Zoom to user selected feature, highlight it and display popup function zoomExtent(results) {   var featureSet = results;   var features = featureSet.features;   var extent = esri.graphicsExtent(features);    //result may be either a line or a point feature. If line feature, the above extent variable is fine. If a point   //feature, that extent is undefined, so we need to create a valid extent   if (!extent) {      var point = features[0];     extent = new esri.geometry.Extent(point.geometry.x - 100, point.geometry.y - 100, point.geometry.x + 100, point.geometry.y + 100, new esri.SpatialReference({ wkid:3857}));     }    //zoom to extent   map.setExtent(extent);   //get location to use for positioning popup   var screenPoint = map.toScreen(extent.getCenter());   map.infoWindow.show(screenPoint);   }


Thanks
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable
Original User: Kelly

So the issue is that you are performing a query and the graphics that are returned don't have an info template defined. You could define an info template and assign it to the resulting features. Alternatively you may be able to query the layer in your web map instead. Is your web map publicly available? If so can you post the web map id?

View solution in original post

0 Kudos
12 Replies
by Anonymous User
Not applicable
Original User: Kelly

Before showing the info window try adding the following:


map.infoWindow.setFeatures(features);

0 Kudos
ZorbaConlen
Occasional Contributor
Kelly, thanks for reply. That's better, but not quite right. I'm now getting the highlighting behavior as desired, and the popup is no longer displaying info from the previous click, but there is no content. Here is screenshot:

[ATTACH=CONFIG]24310[/ATTACH]

I know there is a setContent method, but assuming I should not need to use this as the title and content should be read from the feature. Any thoughts?
0 Kudos
by Anonymous User
Not applicable
Original User: Kelly

How are you figuring out which features to zoom to? Are you using a query task? Or using the feature layer query method?
0 Kudos
ZorbaConlen
Occasional Contributor
I'm using a query task. The query task parameters are like:

var query = new esri.tasks.Query();
query.outFields = ["ASSETNUMBER","Description","DateDiscovered","Severity","incidentID"];
query.returnGeometry = true;
query.where  = "ASSETNUMBER = '" + selItem + "'"
queryTask.execute(query,zoomExtent);
0 Kudos
by Anonymous User
Not applicable
Original User: Kelly

So the issue is that you are performing a query and the graphics that are returned don't have an info template defined. You could define an info template and assign it to the resulting features. Alternatively you may be able to query the layer in your web map instead. Is your web map publicly available? If so can you post the web map id?
0 Kudos
ZorbaConlen
Occasional Contributor
No, the webmap is internal only, so I can't share the id with you. I checked out the api reference for infoTemplate. This looks fairly straight forward. Looks like I would define the template and then use infoWindow.setContent(template)....

Is there a sample for querying the layer in the webmap?

There is one potential hitch in the giddyup. I'm customizing the infoWindow to show an image gallery of attachments. It works by connecting to the onSelectionChanged event of the infoWindow -

dojo.connect(map.infoWindow, "onSelectionChange", displayAttachments);


displayAttachments is the function which modifieds the info window interface....

That's not working either, for the programmatically launched popup.
0 Kudos
by Anonymous User
Not applicable
Original User: Kelly



That's not working either, for the programmatically launched popup.


This is to be expected because the programmatically launched popup is not the popup for the feature in the web map. It is a popup for the feature returned by the query so it has the same geometry but not the popup information.
You may want to try getting the layer you want to search from the map the using the FeatureLayer select method to find the feature of interest and display the popup. Here's a link to a sample that shows how to select features using a feature layer.

http://help.arcgis.com/en/webapi/javascript/arcgis/jssamples/fl_selection.html
ZorbaConlen
Occasional Contributor
Ok, looks like I have a couple options. I'll investigate these. Thanks for your help.
0 Kudos
by Anonymous User
Not applicable
Original User: WestonSF

Did you find a solution to this? I'm facing the same issue. Is there a way of getting the infoTemplate from the ArcGIS Online map?
0 Kudos