protected override void OnClick()
        {
             IMxDocument pmxdoc = (IMxDocument)ArcMap.Application.Document;
             IMap pmap = pmxdoc.FocusMap;
             IGxDialog pGxDialog = new GxDialog();
             pGxDialog.Title = "Browse Data";
             //pGxDialog.set_StartingLocation("C:\\Temp");
             pGxDialog.set_StartingLocation("GIS Servers");
             IEnumGxObject pEnumGx;
             if (!pGxDialog.DoModalOpen(0, out pEnumGx))
                 return; // Exit if user press Cancel
             IGxObject pgxobject = pEnumGx.Next();
             IGxAGSObject gxAGSObject = pgxobject as IGxAGSObject;
             IAGSServerObjectName agsServerObjectName = gxAGSObject.AGSServerObjectName;
             IAGSServerConnectionName agsServerConnectionName = agsServerObjectName.AGSServerConnectionName;
             IPropertySet propertySet = agsServerConnectionName.ConnectionProperties;
             //create a new ArcGIS Server connection factory
             IAGSServerConnectionFactory2 agsServerConnectionFactory2 = (IAGSServerConnectionFactory2)new AGSServerConnectionFactory();
             IAGSServerConnection agsServerConnection = agsServerConnectionFactory2.Open(propertySet, 0);
             //get an enum of all server object names from the server (GIS services, i.e.)
             IAGSEnumServerObjectName soNames = agsServerConnection.ServerObjectNames;
             IAGSServerObjectName3 soName = (IAGSServerObjectName3)soNames.Next();
             ILayerFactory msLayerFactory = new MapServerLayerFactory();
             IEnumLayer enumLyrs = msLayerFactory.Create(soName);
             IMapServerLayer mapServerLayer = (IMapServerLayer)enumLyrs.Next();
             pmap.AddLayer((ILayer)mapServerLayer);

             ArcMap.Application.CurrentTool = null;
        }
Ejemplo n.º 2
0
        protected override void OnClick()
        {
            IMxDocument pmxdoc    = (IMxDocument)ArcMap.Application.Document;
            IMap        pmap      = pmxdoc.FocusMap;
            IGxDialog   pGxDialog = new GxDialog();

            pGxDialog.Title = "Browse Data";
            //pGxDialog.set_StartingLocation("C:\\Temp");
            pGxDialog.set_StartingLocation("GIS Servers");
            IEnumGxObject pEnumGx;

            if (!pGxDialog.DoModalOpen(0, out pEnumGx))
            {
                return;  // Exit if user press Cancel
            }
            IGxObject                pgxobject               = pEnumGx.Next();
            IGxAGSObject             gxAGSObject             = pgxobject as IGxAGSObject;
            IAGSServerObjectName     agsServerObjectName     = gxAGSObject.AGSServerObjectName;
            IAGSServerConnectionName agsServerConnectionName = agsServerObjectName.AGSServerConnectionName;
            IPropertySet             propertySet             = agsServerConnectionName.ConnectionProperties;
            //create a new ArcGIS Server connection factory
            IAGSServerConnectionFactory2 agsServerConnectionFactory2 = (IAGSServerConnectionFactory2) new AGSServerConnectionFactory();
            IAGSServerConnection         agsServerConnection         = agsServerConnectionFactory2.Open(propertySet, 0);
            //get an enum of all server object names from the server (GIS services, i.e.)
            IAGSEnumServerObjectName soNames        = agsServerConnection.ServerObjectNames;
            IAGSServerObjectName3    soName         = (IAGSServerObjectName3)soNames.Next();
            ILayerFactory            msLayerFactory = new MapServerLayerFactory();
            IEnumLayer      enumLyrs       = msLayerFactory.Create(soName);
            IMapServerLayer mapServerLayer = (IMapServerLayer)enumLyrs.Next();

            pmap.AddLayer((ILayer)mapServerLayer);

            ArcMap.Application.CurrentTool = null;
        }
Ejemplo n.º 3
0
        private static IMapServerLayer GetArcGisServerGroupLayer(IAGSServerObjectName3 soName)
        {
            IMapServerLayer outLayer = null;
            var             factory  = new MapServerLayerFactory() as ILayerFactory;

            try
            {
                //create an enum of layers using the name object (will contain only a single layer)
                outLayer = factory.Create(soName).Next() as IMapServerLayer;
            }
            catch
            {
                throw;
            }
            finally
            {
                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(factory);
            }
            return(outLayer);
        }
Ejemplo n.º 4
0
 private static ILayer GetLayer(IAGSServerObjectName3 objectName)
 {
     ILayerFactory msLayerFactory = new MapServerLayerFactory();
     IEnumLayer enumLyrs = msLayerFactory.Create(objectName);
     var mapServerLayer = (IMapServerLayer)enumLyrs.Next();
     if (mapServerLayer != null)
     {
         return (ILayer)mapServerLayer;
     }
     return null;
 }