Opening Popup for feature returned from QueryTask?

496
6
Jump to solution
10-28-2021 09:48 AM
_____
by
New Member

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

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Esteemed Contributor

 

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
    });
}

 

View solution in original post

6 Replies
_____
by
New Member

//

0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

@_____ 

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
    });
}
0 Kudos
_____
by
New Member

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.'}
0 Kudos
RobertScheitlin__GISP
MVP Esteemed Contributor

 

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
    });
}

 

_____
by
New Member

//

0 Kudos
_____
by
New Member

@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.