My console log for a selected feature popup.watch is only showing one attribute when there should be all of them returned. Is it something simple I am overlooking?
var stuffLayer = new MapImageLayer({
url: "https://",
sublayers: [{
id: 2,
title: "Stuff",
visible: true,
outFields: ["*"],
popupTemplate: {
title: "Stuff",
content: createClickContentType
}
//minScale: 100000
},
{
id: 4,
title: "Stuff 2",
visible: false,
//minScale: 100000,
//legendEnabled: false
},
{
id: 3,
title: "Stuff 3",
visible: false,
outFields: ["*"],
popupTemplate: {
title: "Stuff 3",
content: createClickContentType
},
//maxScale: 100000
},
{
id: 1,
title: "Metadata",
visible: false,
popupTemplate: {
title: "Metadata",
content: createClickContentPro
},
}
]
});
mapView.map.add(stuffLayer);
mapView.popup.watch(["selectedFeature"], function(g){
console.log(g);
});
Solved! Go to Solution.
Is there special notation for the related table fields? Similar to the 3.x api ?
Jay,
From what I understand you use something like this for the field name
relationships/0/Point_Count_COMMON
Ok, I can get the values I need returned to the console but nothing in the popup. Is it a timing issue to return them back to the popupTemplate function?
contentSpecies = function(value, key, data) {
var contentSpecies = "";
objectID = data.OBJECTID;
var queryTask = new QueryTask({
url: "https://blah.com/MapServer/1"
});
var relationQuery = new RelationshipQuery({
objectIds: [objectID],
outFields: ["Species", "Notes", "Status"],
returnGeometry: true,
relationshipId: 0
});
queryTask.executeRelationshipQuery(relationQuery)
.then(function(rslts) {
var features = rslts[objectID].features;
features.forEach(function(ftr) {
var t = ftr.attributes;
var species = t.Species;
contentSpecies += "<span class='bold' title='Species'><b>Species: </b></span>" + species + "<br/>";
var notes = t.Notes;
contentSpecies += "<span class='bold' title='Notese'><b>Notes: </b></span>" + notes + "<br/>";
var status = t.Status;
contentSpecies += "<span class='bold' title='Status'><b>Status: </b></span>" + status + "<br/>";
});
console.log(contentSpecies);
//return contentSpecies;
})
return contentSpecies;
};
Jay,
You are returning contentSpecies before the relationship query is done.
I tried with the async await feature but it is not even firing the function now when called.
contentSpecies = async function(value, key, data) {
console.log("functioning");
try {
var contentSpecies = "";
objectID = data.OBJECTID;
var queryTask = new QueryTask({
url: "https://webmaps.com/MapServer/1"
});
var relationQuery = new RelationshipQuery({
objectIds: [objectID],
outFields: ["Species", "Notes", "Status"],
returnGeometry: true,
relationshipId: 0
});
let rslts = await queryTask.executeRelationshipQuery(relationQuery);
var features = rslts[objectID].features;
console.log(features);
features.forEach(function(ftr) {
var t = ftr.attributes;
var species = t.Species;
contentSpecies += "<span class='bold' title='Species'><b>Species: </b></span>" + species + "<br/>";
var notes = t.Notes;
contentSpecies += "<span class='bold' title='Notese'><b>Notes: </b></span>" + notes + "<br/>";
var status = t.Status;
contentSpecies += "<span class='bold' title='Status'><b>Status: </b></span>" + status + "<br/>";
});
} catch (e) {
console.error(e);
} finally {
console.log(contentSpecies);
return contentSpecies;
}
}