Horia,
This is the only way I have found to get the features title based on the PopupTemplate.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>Intro to PopupTemplate - 4.10</title>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>
<link rel="stylesheet" href="https://js.arcgis.com/4.10/esri/css/main.css">
<script src="https://js.arcgis.com/4.10/"></script>
<script>
require([
"esri/Map",
"esri/layers/FeatureLayer",
"esri/views/MapView"
], function(
Map,
FeatureLayer,
MapView
) {
var map = new Map({
basemap: "gray"
});
var view = new MapView({
container: "viewDiv",
map: map,
center: [-73.950, 40.702],
zoom: 11
});
var template = {
title: "Marriage in NY, Zip Code: {ZIP}",
content: [{
type: "fields",
fieldInfos: [{
fieldName: "MARRIEDRATE",
label: "Married %",
visible: true
}, {
fieldName: "MARRIED_CY",
label: "People Married",
visible: true,
format: {
digitSeparator: true,
places: 0
}
}, {
fieldName: "NEVMARR_CY",
label: "People that Never Married",
visible: true,
format: {
digitSeparator: true,
places: 0
}
}, {
fieldName: "DIVORCD_CY",
label: "People Divorced",
visible: true,
format: {
digitSeparator: true,
places: 0
}
}]
}]
};
var featureLayer = new FeatureLayer({
url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/ArcGIS/rest/services/NYCDemographics1/FeatureServer/0",
outFields: ["*"],
popupTemplate: template
});
map.add(featureLayer);
featureLayer.when(function(){
var query = featureLayer.createQuery();
query.where = "OBJECTID_1 = 8";
featureLayer.queryFeatures(query).then(function(results){
var popupTemplate = results.features[0].getEffectivePopupTemplate();
results.features[0].popupTemplate = popupTemplate;
view.popup.features = results.features;
setTimeout(function(){
console.info(view.popup.title);
}, 10);
});
});
});
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>