Select to view content in your preferred language

Query Result Field Alias

4262
7
12-10-2012 08:01 AM
BrianLeroux
Frequent Contributor
Hi All. I am using field aliases on a layer i am hosting and the pop up for that windows displays those alias' how I expect. I have an add-in i created that performs a spatial query on that layer and returns the results back as a new layer in the map. The pop-ups and the attribute table on this new layer do not have the correct alias values. Looking at Fiddler i see the correct alias values are being sent back but for whatever reason they are not being acknowledged in my application when creating the new layer from the query results.

I attached a screenshot of the configure screen for the new layer. [ATTACH=CONFIG]19825[/ATTACH]
Here is a snippet of the query response from Fiddler:
{"displayFieldName":"NAME","fieldAliases":{"ACCOUNT_NO":"Account #","POLICY_NO":"Policy #","NAME":"Name","RES_PREM_ADDRESS":"Address",
0 Kudos
7 Replies
PietaSwanepoel2
Frequent Contributor
Brian, did you ever solve this issue?
0 Kudos
BrianLeroux
Frequent Contributor
Unfortunately I was not able to resolve.
0 Kudos
AlexeyTereshenkov
Deactivated User
Hi,

Do not want to sound too dumb, but have you tried deleting the browsing history in your web browser? I remember spending some time figuring out why the aliases are not shown correctly after applying the changes in the Application Builder and restarting the application in the same web browser session.
0 Kudos
BrianLeroux
Frequent Contributor
That is far from dumb. When troubleshooting I frequently clear cahc and close browser sessions. In my case this does not help at all. I am able to manually change the aliases but the correct alias values should be populated from the results of the query. I verify that the query returns the alias' correctly but the viewer app does not use them. I am starting to think ther builder was not designed to do that. When I find time I will probably just code my query tool to get the aliases and and update the new layer with them.

Thanks.
0 Kudos
PietaSwanepoel2
Frequent Contributor
If your query results are added to a new graphics layer the default settings for layer will apply. Meaning all fields as defined by your service will be added, be visible and have alias names as defined by the service. In order to have the same settings apply to your new layer, you will have to code it to inherit the settings from the parent layer. And how to do it is not obvious.

I hacked the configuration file (map.xml) to get hold of the values. Have added code for an attribute query add-in on the forum ( http://forums.arcgis.com/threads/75698-Attribute-query-add-in-free-solution-provided ). Have a look at the code that populate the combobox
0 Kudos
BrianLeroux
Frequent Contributor
If your query results are added to a new graphics layer the default settings for layer will apply. Meaning all fields as defined by your service will be added, be visible and have alias names as defined by the service. 


What you are saying here is what I excpect to happen but unfortunatley is not the case (for me anyway). I have 2 seperate tools in which one performs a spatial query and the other a attribute query. Both add a new graphics layer if the layer does not exist and then adds the features from the query results to the graphics layer. I based my code off of the ESRI samples. Here is the relevant portion of the code. Maybe I am creating the layer incorrectly.

// Retrieve or create a graphics layer to use for displaying results
            GraphicsLayer graphicsLayer = null;
            if (featureSet.Features[0].Geometry is ESRI.ArcGIS.Client.Geometry.MapPoint)
                graphicsLayer = GetOrCreateLayer("Policy Spatial Query Results", "CustomStrobeMarkerSymbol");
            else if (featureSet.Features[0].Geometry is ESRI.ArcGIS.Client.Geometry.Polyline)
                graphicsLayer = GetOrCreateLayer("Polyline Spatial Query Results", "RedLineSymbol");
            else if (featureSet.Features[0].Geometry is ESRI.ArcGIS.Client.Geometry.Polygon)
                graphicsLayer = GetOrCreateLayer("Polygon Spatial Query Results", "RedFillSymbol");

            string RecCount = featureSet.Features.Count.ToString();
            string strRecordLimit = null;

               // Add results to the graphics layer
                graphicsLayer.ClearGraphics(); //clear out any old features

                foreach (Graphic feature in featureSet.Features)
                    graphicsLayer.Graphics.Add(feature);

                // Add the results graphics layer to the map if it has not already been added and the results to map checkbox is checked
                if (chkResults2Map.IsChecked == true)
                {
                    if (MapApplication.Current.Map.Layers[graphicsLayer.ID] == null)
                        MapApplication.Current.Map.Layers.Add(graphicsLayer);
                }
            }

private GraphicsLayer GetOrCreateLayer(string layerId, string renderer)
       
        {
            Layer layer = MapApplication.Current.Map.Layers[layerId];
            if (layer != null && layer is GraphicsLayer)
            {
                return layer as GraphicsLayer;
            }
                          
            else
            {
                GraphicsLayer gLayer = new GraphicsLayer() 
                { 
                    ID = layerId, 
                    Renderer = new SimpleRenderer()
                    {
                        Symbol = Resources[renderer] as Symbol
                    }
                };
                gLayer.SetValue(MapApplication.LayerNameProperty, layerId);
                return gLayer;
            }
        }

0 Kudos
PietaSwanepoel2
Frequent Contributor
Are you sure that the the fidder results you see (correct aliases) are indeed for the graphics layer you added and not maybe for the layer the results are based on? It might also be that the Silverlight viewer code ignores the alias settings (meaning the ones from service and not those set in viewer)

An option would be to add the fields manually to graphics layer instead of inheriting it from the source layer
0 Kudos