Select to view content in your preferred language

make esri.dijit.Popup only return popup when feature is clicked

889
3
09-20-2012 04:29 AM
CraigMcDade
Deactivated User
I have a popup/infowindow that returns info for 2 of the layers in my map. However, when I click anywhere in the map the popup also comes up that says "no information available". Is there a way to disable this so that the popup only appears when a feature is clicked?
0 Kudos
3 Replies
__Rich_
Deactivated User
How are you showing the popup?

I'm guessing it's designed to inform the user that there's nothing of interest at the location that they clicked.
0 Kudos
StephenLead
Honored Contributor
I have a popup/infowindow that returns info for 2 of the layers in my map


How are you calling the popup - what is causing the query to run? Are you running an IdentifyTask, for example?

Is there a way to disable this so that the popup only appears when a feature is clicked?


You could associate an infoWindow with a feature layer. In that case, the infoWindow will show when clicking on the feature. When you click away from a feature, nothing happens.

Another option is to run a queryTask on click. If there are features found, display them in the infoWindow. If not, don't display the infoWindow.
0 Kudos
SteveCole
Honored Contributor
I would second Steve's suggestion about tying the popup to a feature layer. For example, in one of my maps, I define the popup content at the beginning of my initMap() function like this:

 var removalTemplate = new esri.InfoTemplate();
 removalTemplate.setContent('<table cellspacing=\"5\" style=\"font-size:90%\"><tr><td style=\"vertical-align:top\"><b>Road Name:</b></td><td style=\"vertical-align:top\">${Name}</td></tr><tr><td style=\"vertical-align:top\"><b>Snow Removal Priority:</b></td><td style=\"vertical-align:top\">${Priority:formatPriorityLabel}</td></tr></table>');
 removalTemplate.setTitle('${Name}');


Next, you specify the template when you create the feature layer:

 // Define the Snow Removal Route layer
 theSnowRemovalLayer = new esri.layers.FeatureLayer("URL to feature layer", {
  mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
  infoTemplate:removalTemplate,
  outFields: ["*"],
  opacity:0.80,
  visible: false
 });


Towards the end, but still within the initMap() function, I associate the popup with the specific feature layer:

 dojo.connect(theSnowRemovalLayer,"onClick",function(evt){
  //Listener event for feature selection and the popup info widow
  var query = new esri.tasks.Query();
  query.geometry = pointToExtent(map,evt.mapPoint,15);

  var deferred = theSnowRemovalLayer.selectFeatures(query,esri.layers.FeatureLayer.SELECTION_NEW);
  map.infoWindow.resize(map.width * 0.55,map.height * 0.25);  
  map.infoWindow.setFeatures([deferred]);
  map.infoWindow.show(evt.mapPoint);
 });


Hopefully that makes sense. Good luck!

Steve
0 Kudos