AnsweredAssumed Answered

Popup, PopupTemplate, and InfoTemplate clear as mud

Question asked by MollyKFoley on Mar 21, 2019
Latest reply on Mar 23, 2019 by rscheitlin

What is the difference between these three? Do you have to define a popup object before you define a popup template? My understanding is that the popup template is the same as an info template, the only difference is that the popupTemplate lets you use graphs/pictures and do extra formatting. I think when I define a feature layer and it's properties, I can use a popupTemplate for the infoTemplate property, correct? Is myPopupTemplate.setContent() the same method as myInfoTemplate.setContent()? I create all the content for the popup dynamically, so I can't use fieldInfos or anything like that in the PopupTemplate. This is also why I can't use a "click" function on a feature that brings up the InfoTemplate, because if there are overlapping features (on the same feature layer) and a user uses the arrows on the popup, the click function won't fire again, thus the InfoTemplate does not update.

 

This leaves me with a select-change event on a Popup object (if the select-change event does not fire when the arrows are used, then this whole question is moot and there is no solution to using arrows which would be dumb)...but I don't understand how that correlates with PopupTemplate/InfoTemplate/InfoWindow. Popup objects have their own setContent method. Do I not need a PopupTemplate or an InfoTemplate and instead just set the content and title using the Popup object's own methods? 

 

This is my current code using an InfoTemplate. Note that the content for the InfoTemplate is fired on click of a feature and arrows on the popup do not act as a click. It would be great if there was a solution to the arrow problem while still using InfoTemplates so then I wouldn't have to mess with popup/popupTemplate.

 

var mgmtTractPopupBox = new InfoTemplate();

//Add the habitat management tract feature layer
var hbMgmtTractFL = new FeatureLayer("https://xxx/rest/services/HabitatMonitoring/HabitatData/MapServer/3", {
    refreshInterval: 10,
    mode: FeatureLayer.MODE_ONDEMAND,
    visible: false,
    outFields: ["*"],
    infoTemplate: mgmtTractPopupBox
});
hbMgmtTractFL.setMinScale(500000);
hbMgmtTractFL.setSelectionSymbol(selectionSym);

//Format mgmtTract popup content on click of a feature
hbMgmtTractFL.on("click", function (feature) {
    var OID = feature.graphic.attributes.OBJECTID;
    relatedTractAttrb(OID);
});
       
function relatedTractAttrb(oids) {
    var relate = new RelationshipQuery();
    relate.objectIds = [oids];
    relate.relationshipId = 0;
    relate.outFields = ['*'];
    hbMgmtTractFL.queryRelatedFeatures(relate, function (fset) {
        var features = fset[oids].features;
            var rows = ['<table id="mgmtPopupTable1"><tr><th>Veg Practice</th><th>Herbicide</th><th>Month Treated</th>\
                    <th>Year Treated</th><th>Implemented By</th><th>Funded By</th><th>Farm Bill Code</th></tr>'
];
            for (i = 0; i < features.length; i++) {
                var feature = features[i]
                var vegPractice = vegPName(feature.attributes.VegMgmtPractice);
                var herbicide = herbName(feature.attributes.Herbicide);
                var monthTreated = monthName(feature.attributes.MonthTreated);
                var yearTreated = feature.attributes.YearTreated;
                var impBy = impName(feature.attributes.ImplementedBy);
                var fundBy = fundName(feature.attributes.FundedBy);
                var fbc = feature.attributes.FarmBillCode;
                if (fundBy == "CRP" || fundBy == "CRP - CREP") {
                    fbc = crpName(fbc);
                }
                else if (fundBy == "EQIP" || fundBy == "EQIP - RCPP") {
                    fbc = eqipName(fbc);
                }
                else {
                    fbc = "Not applicable";
                }
                var contentRow = '<tr><td>' + vegPractice + '</td><td>' + herbicide + '</td><td>' + monthTreated + '</td><td>' + yearTreated +
                    '</td><td>' + impBy + '</td><td>' + fundBy + '</td><td>' + fbc + '</td></tr>';
                rows.push(contentRow);
            }
        content = rows.join("");
        content = content + '</table>';
        mgmtTractPopupBox.setTitle("Habitat Management Tract ${OBJECTID}");
        mgmtTractPopupBox.setContent(content);
    });
}

 

The documentation on all three of these things is incredibly confusing and I wish ESRI would clean it up

Outcomes