DominikW

Querying MapServerLayer programmatically

Discussion created by DominikW on Jul 21, 2011
Hi there,

Currently I'm working on an addin which should be used to query a certain attribute within a MapServerLayer which is loaded in ArcMap. My present approach is to use IIdentify, but no matter what the result returned is null.

In the SDK reference there is the hint, that MapServerIdentifySublayer or -QuerySublayer should be used, but I honestly have no clue how to obtain a reference for this.

I also checked if the Object in question implements the appropriate interfaces, that is the case.

protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
        {
            IPoint point = new PointClass();
            point = mxApplication.Display.DisplayTransformation.ToMapPoint(arg.X, arg.Y);

            IMapServerSublayer msl = null; //new MapServerLayerClass();
            MapServerIdentifySublayer misl;
            IIdentify layerIdent = null;

            for (int i = 0; i < layerArray.Count; i++)
            {
                if (layerArray[i] is IMapServerSublayer)
                {
                    msl = layerArray[i] as IMapServerSublayer; //Here something is returned, what seems to be right.
                    misl = layerArray[i] as MapServerIdentifySublayer; // This cast result in "null"
                    layerIdent = msl as IIdentify;
                }
            }

            if (layerIdent is IIdentify)
            {
                
                IArray array = layerIdent.Identify(point);
                for (int j = 0; j < array.Count; j++)
                {
                    System.Object arrayObject = array.get_Element(j);

                    IRowIdentifyObject rowIdentifyObject = array.get_Element(j) as IRowIdentifyObject;
                    IFeature featureIdent = rowIdentifyObject.Row as IFeature;
                    for (int k = 0; k < featureIdent.Fields.FieldCount; k++)
                    {
                        if (featureIdent.Fields.Field[k].Name == "dbo_extViewActive_IncidentID")
                        {
                            MessageBox.Show("Die IncidentID lautet: " + featureIdent.Fields.Field[k].DefaultValue);
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Identify kann nicht ausgeführt werden");
            }
        }

        protected override void OnUpdate()
        {
            Enabled = ArcMap.Application != null;
        }
    }


Regards,
Dominik

Outcomes