How to hide empty popup window?

4387
5
04-15-2015 07:01 AM
TobiasBrühlmeier1
New Contributor III

Hi,

This is what I've coded to create a popup:

map = new Map("map", {

        basemap : "streets",

        slider : true,

        infoWindow : popup

      });

...

popup = new Popup({

  titleInBody : false,

  visibleWhenEmpty : false,

  hideDelay : 0

  }, domConstruct.create("div"));

...

var popupTemplate = new PopupTemplate({

  title : "STAT_NAME: {STAT_NAME}",

  description : "<b>STAT_CODE: </b>{STAT_CODE}<br>",

  });

...

The popup works as expected: When I click an object of my feature layer, I get a popup showing the description of this object.

But when I click the basemap, I would expect the popup to disappear, because I've set "visibleWhenEmpty: false" and "hideDelay : 0". But this part doesn't work: I just get a popup telling me "no information available".

What's the trick?

Regards, Tobias

0 Kudos
5 Replies
KellyHutchins
Esri Frequent Contributor

When you click the basemap the popup shouldn't appear. Here's a sample showing a popup associated with a feature layer. Clicking on features shows the popup.

Popup | ArcGIS API for JavaScript

In your code how are you displaying the popup? Do you associate it with a feature layer or are you using the map's click event?

TobiasBrühlmeier1
New Contributor III

Thanks for the hint! The problem was actually caused by a wrong association within the map's click event. Solved for now.

Regards, Tobias

0 Kudos
PeggyCorey
New Contributor

I'm having the exact same problem!

Mine is using the map's click event to trigger the popup.  I'm not using FeatureLayers.

Tobias, can you please elaborate on how you fixed yours?

Thanks!

0 Kudos
MatthewLofgren
Occasional Contributor

Hi Peggy

I've done it like this before.

function executeIdentifyTask(evt) {
  var attr, template, route;
  identifyParams.geometry = evt.mapPoint;
  identifyParams.mapExtent = map.extent;

  var deferred = identifyTask.execute(identifyParams);

  deferred.then(function (response) {
       // If no results, prevent info window from showing
       if(response.length > 0)
       {
            map.infoWindow.show(evt.mapPoint);
       }
       else
       {
            map.infoWindow.hide();
       }

       return array.map(response, function (result) {
            var feature = result.feature;
            feature.attributes.layerName = result.layerName;
            template = new InfoTemplate();
            template.setTitle("${SomeTitle}");
            template.setContent("some content");
            feature.setInfoTemplate(template);
            return feature;
       });
  }).then(function(features){
       map.infoWindow.setFeatures(features);
  });
}
0 Kudos
PeggyCorey
New Contributor

This worked like a charm... thanks so much!

0 Kudos