Select to view content in your preferred language

quick q: how to display ALL fields in esri.dijit.Popup

5285
17
04-22-2013 12:07 PM
KevinMacLeod1
Frequent Contributor
Hi all,

I want to display all attributes for all fields in an esri.dijit.Popup window.

I remember seeing this somewhere but can not find it again. I want to accomplish the same thing the following code would do in a regular infoWindow:

var infoTemplate = new esri.InfoTemplate("${name}", "${*}");

But with a Popup Dijit. Anyone know the syntax? Thanks!





Below is the entire code / details for why/what I am trying to accomplish. I want to convert the code below to a Popup dijit and put a 'title' in as a Description since it overwrites the title because it shows multiple coincident features.

       var infoTemplate = new esri.dijit.PopupTemplate({
                            title: "",
                            description: feature.attributes.layerName,
                            fieldInfos: [
                            { fieldName: "${*}", visible: true, label: "{*}" }
                            ]
                        });




I want to make that work in the identify widget:
//// Identify Widget ////
        var identifyParams;
        var tasks;
        var clickPoint;

            //var popup = new esri.dijit.Popup({ fillSymbol: new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25]))}, dojo.create("div"));


        dojo.connect(map, 'onLoad', function () {
            //setup generic identify parameters 
            identifyParams = new esri.tasks.IdentifyParameters();
            identifyParams.tolerance = 5;
            identifyParams.returnGeometry = true;
            identifyParams.layerIds = MYDYNAMICLAYER.visibleLayers;
            identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;

            dojo.connect(map, 'onClick', doIdentify);
        });





        dojo.connect(map, 'onLayersAddResult', setupIdentify);


        function setupIdentify(results) {
            //loop through operational layers and add identify task for each. 
            tasks = dojo.map(results, function (result) {
                return new esri.tasks.IdentifyTask(result.layer.url);
            });


        }
        function doIdentify(evt) {

            map.infoWindow.hide();
            clickPoint = evt.mapPoint;

            identifyParams.geometry = evt.mapPoint;
            identifyParams.mapExtent = map.extent;
            identifyParams.width = map.width;
            identifyParams.height = map.height;
            identifyParams.layerIds = MYDYNAMICLAYER.visibleLayers;
            identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_VISIBLE;

            var deferreds = dojo.map(tasks, function (task) {
                return task.execute(identifyParams);
            });
            var dlist = new dojo.DeferredList(deferreds);
            dlist.then(handleQueryResults);

        }
        function handleQueryResults(results) {

            var features = [];
            dojo.forEach(results, function (result) {
                // for a simplified test let's just display all the attributes in the popup 
                if (result[1].length > 0) {
                    dojo.forEach(result[1], function (r) {
                        var feature = r.feature;
                        console.log(feature);
                        feature.attributes.layerName = r.layerName;


                        var infoTemplate = new esri.InfoTemplate("${name}", "${*}");
                        

                        feature.setInfoTemplate(infoTemplate);
                        features.push(feature);

                    });
                }

            });
            map.infoWindow.setFeatures(features);
            map.infoWindow.show(clickPoint);

        }


        //// ^^^  Identify Widget ////
0 Kudos
17 Replies
AdrianMarsden
Honored Contributor
OK - I've don a hack and slash on my code, to only do the "every result, every field in one floating pane"

It is here - using esri data and a VERY big click tolerance to ensure lots of results.

The attached CSS is my ENTIRE project CSS, so lots of stuff not required.

Many, many thanks to Ben Fousek who posted the way of getting floating panes looking like dialogs.

Obviously as I am using the Esri samples there are many more fields than you'd want to expose, but it shows what can be done.

I also use the layer description field to embed feature level hyper links, but that's another story.....

Cheers

ACM
KevinMacLeod1
Frequent Contributor
Adrian thanks, this is awesome! I'll play around with it..
0 Kudos
NilsBabel
Frequent Contributor
Yep, that's right, only fields in the MXD will get exposed - plus they will have any aliases you set in ArcMap as well.  ArcServer gets a bit stressed if you don't expose the shape filed and always leave OBJECTID 9or whatever your unique key is) but otherwise hide anything that you don't think will be used.


So you have to display the OBJECTID?  I have it checked off in my MXD but it still displays in the Identify results window.  Do you know how I can turn it off so it doesn't display in the identify results?  Other than specifying only the fields I don want in the IdentifyParameters (I'm using "${*}" to return all the fields).

Thanks
0 Kudos
KevinMacLeod1
Frequent Contributor
So you have to display the OBJECTID?  I have it checked off in my MXD but it still displays in the Identify results window.  Do you know how I can turn it off so it doesn't display in the identify results?  Other than specifying only the fields I don want in the IdentifyParameters (I'm using "${*}" to return all the fields).

Thanks


Yes, it would be nice to have a programmatic way of doing what you and I want to do, from the API: display all fields except for one, or a few, particular fields. So far, it seems the only way is to check them off in MXD. I will test this on our site later. For now we wanted ObjectID left there. But turning other fields off in MXD worked fine, they did not display in the infoWindows once they were turned off in MXD. But it would be nice to be able to do this from Javascript. For example, perhaps the programmer does (readily) not have access to the server and MXD/.msd. Perhaps there is a way to do this, I do not know.
0 Kudos
NilsBabel
Frequent Contributor
Thanks,  I've always found it easier to set the field display and aliases within the MXD.  But it seems at version 10.1 and jsapi 3.4 OBJECTID displays in the infowindow even if it is checked off in the MXD.  I don't think this was always the case.
0 Kudos
AdrianMarsden
Honored Contributor
Hi

If you look at the example I linked to above, you'll notice some cunning code (got from somewhere else here,  - this excludes various fields.

if (j.toUpperCase() != "OBJECTID" && j.toUpperCase() != "SHAPE.FID" && j.toUpperCase() !=                                            "SHAPE" && j.toUpperCase() != "SHAPE_AREA" && j.toUpperCase() != "SHAPE.AREA" && j.toUpperCase() !=
                                            "SHAPE.LEN" && j.toUpperCase() != "SHAPE_LENGTH") {
                                            infotext += "<th class='idheader'>" + j.toUpperCase() + "</th>";
                                        }


I'm sure that could be modified for other types of display

ACM
0 Kudos
NilsBabel
Frequent Contributor
Thanks, that's probably what I need.  I'll have to take a closer look at the code.
0 Kudos