Select to view content in your preferred language

Query MapService for Fields and dominions to turn into controls

503
1
02-05-2013 06:23 AM
PhilipKnight1
Regular Contributor
I am dynamically creating controls based on the Field type and dominion of a MapService. Currently I am getting this information by referencing features that were created already

I inserted this into the xaml, causing them to appear:
[HTML]            <esri:FeatureLayer ID="MyFeatureLayer"
                Url="http://107.20.209.214/ArcGIS/rest/services/AquarionNotifications/MapServer/0">
            </esri:FeatureLayer>[/HTML]

I then call a method (here in part):
        private void LoadFeatureData()
        {
            FeatureLayer _featureLayer = MyMap.Layers["MyFeatureLayer"] as FeatureLayer;

            Graphic _graphicSource = _featureLayer.Graphics[0];

            ESRI.ArcGIS.Client.FeatureService.FeatureLayerInfo _layerInfo = _featureLayer.LayerInfo;

            FeatureType _ftype = null;
            if ( false == string.IsNullOrEmpty(_featureLayer.LayerInfo.TypeIdField) )
            {
                _ftype = _featureLayer.LayerInfo.FeatureTypes[_graphicSource.Attributes[_featureLayer.LayerInfo.TypeIdField]];
            }

            foreach (Field fld in _featureLayer.LayerInfo.Fields)
            {
                //ObjectID Field
                if (fld.Name == _layerInfo.ObjectIdField)
                {
                    TextBlock fieldoid = new TextBlock();
                    fieldoid.Text = fld.Alias;
                    EditForm.Children.Add(fieldoid);

                    TextBlock oid = new TextBlock();
                    oid.Text = _graphicSource.Attributes[_layerInfo.ObjectIdField] != null ? _graphicSource.Attributes[_layerInfo.ObjectIdField].ToString() : "";
                    EditForm.Children.Add(oid);
                }
                else
                {
                    TextBlock field = new TextBlock();
                    field.Text = fld.Alias;
                    field.Foreground = forgroundBrush;
                    field.FontWeight = FontWeights.Bold;
                    EditForm.Children.Add(field);

                    //Type Field
                    if (fld.Name == _featureLayer.LayerInfo.TypeIdField)//This is the type field
                    {


This is working just fine. But the problem is that individual graphics are appearing on the map, which are not being used and are just getting in the way.

One solution would be to just hide these graphics, the other would be to query the mapservice somehow or create what I need on the fly but never display on the map. The second option would be preferable, as the first one seems like it would just waste resources. How do i do either?
0 Kudos
1 Reply
DominiqueBroux
Esri Frequent Contributor
From my understanding, instead of creating a feature layer you should use a QueryTask to get the info you need from the server.
There is a sample here: http://resources.arcgis.com/en/help/silverlight-api/samples/start.htm#QueryWithoutMap
0 Kudos