[GIS] Hiding popup template in ArcGIS API for JavaScript

arcgis-javascript-apipopup

I am creating a Custom Popup template as follows:

countyPop = new PopupTemplate({
            title: "County: {NAME}",
            fieldInfos: [{ 
                fieldName: "POP2000",
                label: "2000 Pop",
                visible: true
            }, {
                fieldName: "POP2010",
                label: "2010 Pop",
                visible: true
            }]
        });

This popup works fine and is firing when I click the layer. However, I have some javascript to switch out the layers and when I hide this layer and show a different shape layer the popup still hangs around.

How can I stop displaying this popup when I switch to a different layer?

I tried

countyPop.hide(); 

It states there is a hide method in infoWindow but that does nothing. No error is produced and the popup is still there.

Best Answer

Use:

map.infoWindow.hide();

to hide and close the popup. Popup templates do not have a hide method as they specify how content is displayed, not whether the popup itself is visible.

Related Question