I have a Dynamic Layer which I want to define a popup for.
DynamicLayer1 = new esri.layers.ArcGISDynamicMapServiceLayer(
"http://testServer/arcgis/rest/services/TestMap/MapServer");
I created a new queryTask object to execute a query on the layer resource identified by the URL:
dojo.connect(map, "onClick", executeQueryTask);
query = new esri.tasks.Query();
query.returnGeometry = true;
query.outFields = layersInfoWindow[layerId]['outFields'];
infoTemplate = new esri.InfoTemplate()
function executeQueryTask(evt) {
query.geometry = evt.mapPoint;
queryTask[activeLayer].execute(query, showResults);
}
Why do I have to click twice to get the popup working? One click highlights the region and then I need another click to get the popup.
The first time you click, the map click event is fired and the executeQueryTask is getting called. Until the queryTask completes, there is no feature downloaded from the server so the popup will not display anything. The second time that you click on the map, the feature is downloaded and you are clicking on an actual graphic and consequently the popup will display the information for this graphic. In order to bypass this you will need to set the queryTask's results to the popup prior to showing the popup. You can do that by calling map.infoWindow.setFeatures inside the showResults function.