Pass custom field variable into pop-up

797
2
07-07-2020 01:05 PM
CamCode
New Contributor III

I am trying to add one new pop-up field, that comes from a separate rest call, but I am unsure how to incorporate.

All my other fields come from this service:

https://services9.arcgis.com/RHVPKKiFTONKtxq3/ArcGIS/rest/services/USGS_Seismic_Data_v1/FeatureServe... 

But I need one piece of data from this service, the 'name' as place (which I am getting and using fine, I just can't get it into the pop-up):

https://services9.arcgis.com/RHVPKKiFTONKtxq3/ArcGIS/rest/services/USGS_Seismic_Data_v1/FeatureServe... 

With my original query, I add this to get the name (or place) from second service:

                let plc;
                 ............
                QTt.execute(query2).then(function(results) {
                    results.features.map(function(feat) {
                        let magD = feat.attributes["id"];
                        if (id === magD) {
                            plc = feat.attributes["place"];
                             .......................

And below is my attempt to call it into the pop-up:

          function popupContent (feature) {
                const div = document.createElement('div');
                div.innerHTML =
                "<span class='name_plc'>Name: "+ plc + "</span>"; <------------ attempt
                return div;
            }
            let popuptemp = {
                title: "Shake Intensity",
                content: [{
                    type: "fields",
                    fieldInfos: [{
                            fieldName: "grid_value",
                            label: "Grid Value"
                        },
                        {
                            fieldName: "id",
                            label: "id"
                        },
                        {
                            fieldName: "place",
                            label: "place"
                        },
                        {
                            fieldName: "ObjectID",
                            label: "ObjectID"
                        },
                        {
                            fieldName: "url",
                            label: "Url"
                        }
                    ]
                }]
            }
            fl = new FeatureLayer({
                source: gras,
                objectIdField: "ObjectID",
                geometryType: "polygon",
                fields: [{
                        name: "ObjectID",
                        alias: "ObjectID",
                        type: "oid"
                    }, {
                        name: "id",
                        alias: "id",
                        type: "string"
                    },
                    {
                        name: "place",
                        alias: "place",
                        type: "string"
                    },
                    {
                        name: "url",
                        alias: "url",
                        type: "string"
                    }, {
                        name: "grid_value",
                        alias: "grid_value",
                        type: "double"
                    }
                ],
                renderer: renderer,
                popupEnabled: true,
                popupTemplate: popuptemp,
                content: popupContent, <--- attempt
            });

            app.mapview.map.add(fl);
Tags (1)
0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor
0 Kudos
CamCode
New Contributor III

I was able to achieve this by running another query within 'content' as a function. Not the most elegant, but works.

0 Kudos