I'm trying to open a Popup for a feature returned from a QueryTask. If I just click on the feature in the map, then it works fine, but when the app first opens it zooms to a specific feature and I want to automatically display the popup for it.
var meterNumber_Q = new Query();
meterNumber_Q.returnGeometry = true;
meterNumber_Q.outSpatialReference = sr;
meterNumber_Q.outFields = ['*'];
meterNumber_Q.where = `gs_meter_number = '${meterNumber}'`;
mapImageLayer.findSublayerById(27).queryFeatures(meterNumber_Q).then(zoomToServicePoint);
function zoomToServicePoint(results) {
var feature = results.features[0];
view.popup.open({
features: feature,
title: '<b>Layer: </b>Service Point',
content:
'<ul><li><b>Service Status: </b>{gs_service_status}</li>' +
'<li><b>Meter Number: </b>{gs_meter_number}</li>' +
'<li><b>Access Note: </b>{AccessNotes}</li><ul>'
});
}
This opens the Popup, but it displays the Content exactly as above even though the feature contains the attributes listed inside the {}.
Why aren't the attributes being transferred?
Is there an easier way to do this since I already have the exact same information setup on the sublayer as a popupTemplate?
{
id: 27, //Service Point
visible: true,
legendEnabled: true,
title: 'Service Point',
popupTemplate: servicePopupTemplate,
},
Thanks
Solved! Go to Solution.
function zoomToServicePoint(results) {
var feature = results.features[0];
feature.popupTemplate = {
title: '<b>Layer: </b>Service Point',
content:
'<ul><li><b>Service Status: </b>{gs_service_status}</li>' +
'<li><b>Meter Number: </b>{gs_meter_number}</li>' +
'<li><b>Access Note: </b>{AccessNotes}</li><ul>'
}
view.popup.open({
features: [feature],
fetchFeatures: true
});
}
//
Try this:
function zoomToServicePoint(results) {
var feature = results.features[0];
feature.popupTemplate = {
title: '<b>Layer: </b>Service Point',
content:
'<ul><li><b>Service Status: </b>{gs_service_status}</li>' +
'<li><b>Meter Number: </b>{gs_meter_number}</li>' +
'<li><b>Access Note: </b>{AccessNotes}</li><ul>'
}
view.popup.open({
features: feature,
fetchFeatures: true
});
}
I just tried that and I get the error:
[esri.widgets.Popup.PopupViewModel] e {name: 'fetch-features:invalid-screenpoint-or-view', details: {…}, message: 'Cannot fetch features without a screenPoint and view.'}
function zoomToServicePoint(results) {
var feature = results.features[0];
feature.popupTemplate = {
title: '<b>Layer: </b>Service Point',
content:
'<ul><li><b>Service Status: </b>{gs_service_status}</li>' +
'<li><b>Meter Number: </b>{gs_meter_number}</li>' +
'<li><b>Access Note: </b>{AccessNotes}</li><ul>'
}
view.popup.open({
features: [feature],
fetchFeatures: true
});
}
//
@RobertScheitlin__GISP thanks, missing the array, also I just realized that I only need to do:
view.popup.open({
features: [feature],
});
Because the queried feature is getting it's popupTemplate from the sublayer.